2026-04-03 18:32:19 +08:00
|
|
|
|
using System;
|
2026-06-11 19:37:56 +08:00
|
|
|
|
using System.Collections;
|
2026-04-13 18:30:55 +08:00
|
|
|
|
using UnityEngine;
|
2026-06-11 19:37:56 +08:00
|
|
|
|
using UnityEngine.Networking;
|
|
|
|
|
|
using UnityEngine.Rendering;
|
2026-04-03 18:32:19 +08:00
|
|
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
|
|
public class UserBaseInfo
|
2026-03-09 09:25:01 +08:00
|
|
|
|
{
|
2026-04-13 18:30:55 +08:00
|
|
|
|
public Sprite avatarSprite;
|
2026-06-11 19:37:56 +08:00
|
|
|
|
public IEnumerator DownSprite(System.Action<Sprite> action)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (avatarSprite != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
action?.Invoke(avatarSprite);
|
|
|
|
|
|
yield break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-21 18:20:55 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(avatarUrl))
|
|
|
|
|
|
{
|
|
|
|
|
|
// 优先从 GameManager 头像缓存读取(兼容图集切片命名)
|
|
|
|
|
|
avatarSprite = GameManager.Instance.GetAvatarSprite(avatarUrl);
|
|
|
|
|
|
if (avatarSprite != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
action?.Invoke(avatarSprite);
|
|
|
|
|
|
yield break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 回退:数字ID用 Resources.Load(单图PNG)
|
|
|
|
|
|
if (int.TryParse(avatarUrl, out int id) && id > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
avatarSprite = Resources.Load<Sprite>($"Avatar/{id}");
|
|
|
|
|
|
if (avatarSprite != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
action?.Invoke(avatarSprite);
|
|
|
|
|
|
yield break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 网络URL下载
|
|
|
|
|
|
string url = avatarUrl;
|
|
|
|
|
|
int downCount = 5;
|
2026-06-11 19:37:56 +08:00
|
|
|
|
Texture2D avatarTexture2D = new Texture2D(100, 100);
|
|
|
|
|
|
for (int i = 0; i < downCount; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (UnityWebRequest www = UnityWebRequestTexture.GetTexture(url))
|
|
|
|
|
|
{
|
|
|
|
|
|
yield return www.SendWebRequest();
|
|
|
|
|
|
if (www.result == UnityWebRequest.Result.ConnectionError ||
|
|
|
|
|
|
www.result == UnityWebRequest.Result.ProtocolError)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError("下载失败: " + www.error);
|
|
|
|
|
|
downCount--;
|
2026-06-21 18:20:55 +08:00
|
|
|
|
if (downCount == 0) yield break;
|
2026-06-11 19:37:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
avatarTexture2D = DownloadHandlerTexture.GetContent(www);
|
|
|
|
|
|
avatarSprite = Sprite.Create(avatarTexture2D, new Rect(0, 0, avatarTexture2D.width, avatarTexture2D.height), new Vector2(0.5f, 0.5f));
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
action?.Invoke(avatarSprite);
|
2026-06-21 22:38:18 +08:00
|
|
|
|
|
|
|
|
|
|
// 兜底:下载或加载失败 → 用默认头像
|
|
|
|
|
|
if (avatarSprite == null)
|
|
|
|
|
|
action?.Invoke(GameManager.Instance.GetAvatarSprite(null));
|
2026-06-11 19:37:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
public void UpdateAvatar(System.Action<Sprite> action)
|
|
|
|
|
|
{
|
|
|
|
|
|
GameManager.Instance.StartCoroutine(DownSprite(action));
|
|
|
|
|
|
}
|
2026-03-09 09:25:01 +08:00
|
|
|
|
public string userName { get; set; }
|
|
|
|
|
|
public string password { get; set; }
|
|
|
|
|
|
public string number { get; set; }
|
|
|
|
|
|
public string avatarUrl { get; set; }
|
|
|
|
|
|
public string mobile { get; set; }
|
|
|
|
|
|
public string wxOpenId { get; set; }
|
|
|
|
|
|
public string channel { get; set; }
|
|
|
|
|
|
public bool isRedName { get; set; }
|
|
|
|
|
|
}
|