UI换了很多,spine主视觉停用

This commit is contained in:
2026-06-15 20:17:25 +08:00
parent 5eec879582
commit 216ab08e8d
3634 changed files with 814422 additions and 382766 deletions
+47 -13
View File
@@ -30,6 +30,10 @@ public class friendCardPrefab : MonoBehaviour
private Material _profileBorderMaterial;
private Material _friendProfileMaterial;
private Coroutine _avatarLoadRoutine;
private Sprite _runtimeAvatarSprite;
private Texture2D _runtimeAvatarTexture;
private Texture2D _runtimeSteamAvatarTexture;
private Texture2D _runtimeSteamAvatarFlippedTexture;
private string _steamId;
private Action<string, bool> _starChanged;
private Action<string> _openDetails;
@@ -49,6 +53,8 @@ public class friendCardPrefab : MonoBehaviour
StopCoroutine(_avatarLoadRoutine);
_avatarLoadRoutine = null;
}
ReleaseRuntimeAvatarResources();
}
public void Bind(FriendCardViewData data, Action<string, bool> onStarChanged, Action<string> onOpenDetails, Action<string> onOpenPrivateConversation)
@@ -146,6 +152,8 @@ public class friendCardPrefab : MonoBehaviour
yield break;
}
ReleaseRuntimeAvatarResources();
string resolvedAvatarUrl = NetworkManager.ResolveAvatarUrl(data.AvatarUrl, data.SteamId);
bool loaded = false;
@@ -160,7 +168,9 @@ public class friendCardPrefab : MonoBehaviour
Texture2D texture = DownloadHandlerTexture.GetContent(request);
if (texture != null)
{
friendProfile.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
_runtimeAvatarTexture = texture;
_runtimeAvatarSprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
friendProfile.sprite = _runtimeAvatarSprite;
loaded = true;
}
}
@@ -203,7 +213,20 @@ public class friendCardPrefab : MonoBehaviour
byte[] buffer = new byte[width * height * 4];
if (SteamUtils.GetImageRGBA(imageId, buffer, buffer.Length))
{
friendProfile.sprite = CreateFlippedSteamAvatarSprite(buffer, (int)width, (int)height);
_runtimeSteamAvatarTexture = new Texture2D((int)width, (int)height, TextureFormat.RGBA32, false);
_runtimeSteamAvatarTexture.LoadRawTextureData(buffer);
_runtimeSteamAvatarTexture.Apply();
_runtimeSteamAvatarFlippedTexture = new Texture2D((int)width, (int)height, TextureFormat.RGBA32, false);
for (int y = 0; y < height; y++)
{
Color[] pixels = _runtimeSteamAvatarTexture.GetPixels(0, (int)y, (int)width, 1);
_runtimeSteamAvatarFlippedTexture.SetPixels(0, (int)height - 1 - (int)y, (int)width, 1, pixels);
}
_runtimeSteamAvatarFlippedTexture.Apply();
_runtimeAvatarSprite = Sprite.Create(_runtimeSteamAvatarFlippedTexture, new Rect(0, 0, width, height), new Vector2(0.5f, 0.5f));
friendProfile.sprite = _runtimeAvatarSprite;
yield break;
}
}
@@ -213,19 +236,30 @@ public class friendCardPrefab : MonoBehaviour
#endif
}
private static Sprite CreateFlippedSteamAvatarSprite(byte[] rgbaBuffer, int width, int height)
private void ReleaseRuntimeAvatarResources()
{
Texture2D texture = new Texture2D(width, height, TextureFormat.RGBA32, false);
texture.LoadRawTextureData(rgbaBuffer);
texture.Apply();
Texture2D flipped = new Texture2D(width, height, TextureFormat.RGBA32, false);
for (int y = 0; y < height; y++)
if (_runtimeAvatarSprite != null)
{
Color[] pixels = texture.GetPixels(0, y, width, 1);
flipped.SetPixels(0, height - 1 - y, width, 1, pixels);
Destroy(_runtimeAvatarSprite);
_runtimeAvatarSprite = null;
}
if (_runtimeAvatarTexture != null)
{
Destroy(_runtimeAvatarTexture);
_runtimeAvatarTexture = null;
}
if (_runtimeSteamAvatarFlippedTexture != null)
{
Destroy(_runtimeSteamAvatarFlippedTexture);
_runtimeSteamAvatarFlippedTexture = null;
}
if (_runtimeSteamAvatarTexture != null)
{
Destroy(_runtimeSteamAvatarTexture);
_runtimeSteamAvatarTexture = null;
}
flipped.Apply();
return Sprite.Create(flipped, new Rect(0, 0, width, height), new Vector2(0.5f, 0.5f));
}
}