|
|
@@ -14,6 +14,10 @@ public class RoleMgr
|
|
|
}
|
|
|
//获取角色信息(适用于本地PK获取对手或者我的信息)
|
|
|
public static string GetRoleInfo(int id, Image image)
|
|
|
+ {
|
|
|
+ return GetRoleInfo(id, image, image);
|
|
|
+ }
|
|
|
+ public static string GetRoleInfo(int id, Image image, MonoBehaviour coroutineStarter)
|
|
|
{
|
|
|
string nickname = null;
|
|
|
if (IsRoleAvatar(id)) {
|
|
|
@@ -21,7 +25,7 @@ public class RoleMgr
|
|
|
} else {
|
|
|
nickname = LoginMgr.myUserInfo.nickname;
|
|
|
}
|
|
|
- SetAvatarToImage(image, id, LoginMgr.myUserInfo.avatarUrl);
|
|
|
+ SetAvatarToImage(image, coroutineStarter, id, LoginMgr.myUserInfo.avatarUrl);
|
|
|
return nickname;
|
|
|
}
|
|
|
|
|
|
@@ -34,14 +38,20 @@ public class RoleMgr
|
|
|
|
|
|
public const int NullAvatarID = int.MinValue;
|
|
|
public static void SetAvatarToImage(Image image, int avatarID, string avatarUrl) {
|
|
|
- if (avatarID == NullAvatarID) image.sprite = null;
|
|
|
- else if (avatarID < 0) image.StartCoroutine(LoadAvatar(avatarUrl, image));
|
|
|
+ SetAvatarToImage(image, image, avatarID, avatarUrl);
|
|
|
+ }
|
|
|
+ public static void SetAvatarToImage(Image image, MonoBehaviour coroutineStarter, int avatarID, string avatarUrl) {
|
|
|
+ if (avatarID == NullAvatarID)
|
|
|
+ {
|
|
|
+ if (image) image.sprite = null;
|
|
|
+ }
|
|
|
+ else if (avatarID < 0) coroutineStarter.StartCoroutine(LoadAvatar(avatarUrl, image));
|
|
|
else
|
|
|
{
|
|
|
string path = "Textures/Avatar/";
|
|
|
if (avatarID < 7) path += "Player" + avatarID;
|
|
|
else path += avatarID - 7;
|
|
|
- image.sprite = Resources.Load<Sprite>(path);
|
|
|
+ if (image) image.sprite = Resources.Load<Sprite>(path);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -51,15 +61,16 @@ public class RoleMgr
|
|
|
{
|
|
|
if (string.IsNullOrWhiteSpace(url))
|
|
|
{
|
|
|
- image.sprite = null;
|
|
|
+ if (image) image.sprite = null;
|
|
|
yield break;
|
|
|
}
|
|
|
if (remoteAvatarMap.ContainsKey(url))
|
|
|
{
|
|
|
- image.sprite = remoteAvatarMap[url];
|
|
|
+ if (image) image.sprite = remoteAvatarMap[url];
|
|
|
yield break;
|
|
|
}
|
|
|
- image.sprite = null;
|
|
|
+ if (image) image.sprite = null;
|
|
|
+ else yield break;
|
|
|
using (UnityWebRequest uwr = new UnityWebRequest(url, UnityWebRequest.kHttpVerbGET)) {
|
|
|
uwr.downloadHandler = new DownloadHandlerTexture();
|
|
|
yield return uwr.SendWebRequest();
|
|
|
@@ -67,7 +78,7 @@ public class RoleMgr
|
|
|
Texture2D texture = DownloadHandlerTexture.GetContent(uwr);
|
|
|
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
|
|
|
remoteAvatarMap[url] = sprite;
|
|
|
- image.sprite = sprite;
|
|
|
+ if (image) image.sprite = sprite;
|
|
|
}
|
|
|
}
|
|
|
}
|