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

This commit is contained in:
FloatGaming
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));
}
}
+85 -31
View File
@@ -40,21 +40,21 @@ public sealed class FriendCardViewData
public class friendSystem : MonoBehaviour
{
private const string LabelAllFriends = "全部好友";
private const string LabelOnlineFriends = "在线好友";
private const string LabelStarredFriends = "星标好友";
private const string LabelOfflineFriends = "离线好友";
private const string LabelGameFriends = "游戏好友";
private const string LabelSteamFriends = "Steam好友";
private const string StatusOnline = "在线";
private const string StatusOffline = "离线";
private const string StatusPlaying = "游戏中";
private const string StatusInRoom = "房间中";
private const string NoticeFriendDetailsNotReady = "好友详情面板尚未接入";
private const string NoticePrivateChatNotReady = "私聊面板尚未接入";
private const string DefaultStatusLoading = "正在拉取好友信息...";
private const string DefaultStatusEmpty = "你当前没有好友";
private const string DefaultStatusServiceUnavailable = "无法访问服务";
private static string LabelAllFriends => LocalizationService.Get("friends.filter.all", "全部好友");
private static string LabelOnlineFriends => LocalizationService.Get("friends.filter.online", "在线好友");
private static string LabelStarredFriends => LocalizationService.Get("friends.filter.starred", "星标好友");
private static string LabelOfflineFriends => LocalizationService.Get("friends.filter.offline", "离线好友");
private static string LabelGameFriends => LocalizationService.Get("friends.filter.game", "游戏好友");
private static string LabelSteamFriends => LocalizationService.Get("friends.filter.steam", "Steam好友");
private static string StatusOnline => LocalizationService.Get("friends.status.online", "在线");
private static string StatusOffline => LocalizationService.Get("friends.status.offline", "离线");
private static string StatusPlaying => LocalizationService.Get("friends.status.playing", "游戏中");
private static string StatusInRoom => LocalizationService.Get("friends.status.in_room", "房间中");
private static string NoticeFriendDetailsNotReady => LocalizationService.Get("friends.notice.details_not_ready", "好友详情面板尚未接入");
private static string NoticePrivateChatNotReady => LocalizationService.Get("friends.notice.private_chat_not_ready", "私聊面板尚未接入");
private static string DefaultStatusLoading => LocalizationService.Get("friends.default.loading", "正在拉取好友信息...");
private static string DefaultStatusEmpty => LocalizationService.Get("friends.default.empty", "你当前没有好友");
private static string DefaultStatusServiceUnavailable => LocalizationService.Get("friends.default.service_unavailable", "无法访问服务");
public GameObject friendCardPrefab;
public Transform friendsDisplayContent;
@@ -74,21 +74,22 @@ public class friendSystem : MonoBehaviour
new Dictionary<string, FriendCardViewData>(StringComparer.Ordinal);
private readonly Dictionary<string, GameObject> _spawnedCards =
new Dictionary<string, GameObject>(StringComparer.Ordinal);
private readonly List<(FriendFilterType filter, string label)> _filters =
new List<(FriendFilterType filter, string label)>
private readonly List<FriendFilterType> _filters =
new List<FriendFilterType>
{
(FriendFilterType.All, LabelAllFriends),
(FriendFilterType.Online, LabelOnlineFriends),
(FriendFilterType.Starred, LabelStarredFriends),
(FriendFilterType.Offline, LabelOfflineFriends),
(FriendFilterType.GameFriends, LabelGameFriends),
(FriendFilterType.SteamFriends, LabelSteamFriends)
FriendFilterType.All,
FriendFilterType.Online,
FriendFilterType.Starred,
FriendFilterType.Offline,
FriendFilterType.GameFriends,
FriendFilterType.SteamFriends
};
private bool _dropdownInitialized;
private bool _isRefreshing;
private bool _lastRefreshFailed;
private Coroutine _resyncCoroutine;
private bool _languageSubscribed;
private static List<string> _startupSteamFriendIds = new List<string>();
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
@@ -99,9 +100,11 @@ public class friendSystem : MonoBehaviour
private void OnEnable()
{
LocalizationService.EnsureInitialized();
ClearDisplayedFriends();
SetDefaultText(DefaultStatusLoading);
InitializeDropdown();
SubscribeLanguageChanged();
if (ArenaRoomService.Instance != null)
{
@@ -118,6 +121,7 @@ public class friendSystem : MonoBehaviour
private void OnDisable()
{
UnsubscribeLanguageChanged();
if (ArenaRoomService.Instance != null)
{
ArenaRoomService.Instance.OnFriendsListChanged -= HandleFriendsListChanged;
@@ -244,13 +248,11 @@ public class friendSystem : MonoBehaviour
}
friendsDisplayDropdown.onValueChanged.RemoveListener(HandleFilterChanged);
if (!_dropdownInitialized)
{
friendsDisplayDropdown.ClearOptions();
friendsDisplayDropdown.AddOptions(_filters.Select(item => item.label).ToList());
friendsDisplayDropdown.value = 0;
_dropdownInitialized = true;
}
int selectedValue = Mathf.Clamp(friendsDisplayDropdown.value, 0, Mathf.Max(0, _filters.Count - 1));
friendsDisplayDropdown.ClearOptions();
friendsDisplayDropdown.AddOptions(_filters.Select(GetFilterLabel).ToList());
friendsDisplayDropdown.value = selectedValue;
_dropdownInitialized = true;
friendsDisplayDropdown.onValueChanged.AddListener(HandleFilterChanged);
friendsDisplayDropdown.RefreshShownValue();
@@ -523,7 +525,7 @@ public class friendSystem : MonoBehaviour
return FriendFilterType.All;
}
return _filters[friendsDisplayDropdown.value].filter;
return _filters[friendsDisplayDropdown.value];
}
private void HandleStarChanged(string steamId, bool isOn)
@@ -569,6 +571,58 @@ public class friendSystem : MonoBehaviour
globalChatSystem.OpenPrivateConversation(steamId);
}
private void SubscribeLanguageChanged()
{
if (_languageSubscribed)
{
return;
}
LocalizationService.LanguageChanged += HandleLanguageChanged;
_languageSubscribed = true;
}
private void UnsubscribeLanguageChanged()
{
if (!_languageSubscribed)
{
return;
}
LocalizationService.LanguageChanged -= HandleLanguageChanged;
_languageSubscribed = false;
}
private void HandleLanguageChanged(string _)
{
if (!isActiveAndEnabled)
{
return;
}
InitializeDropdown();
Render();
}
private static string GetFilterLabel(FriendFilterType filter)
{
switch (filter)
{
case FriendFilterType.Online:
return LabelOnlineFriends;
case FriendFilterType.Starred:
return LabelStarredFriends;
case FriendFilterType.Offline:
return LabelOfflineFriends;
case FriendFilterType.GameFriends:
return LabelGameFriends;
case FriendFilterType.SteamFriends:
return LabelSteamFriends;
default:
return LabelAllFriends;
}
}
private static int GetSortBucket(FriendCardViewData friend)
{
if (friend == null)
@@ -11,6 +11,9 @@ using UnityEngine.UI;
public class friendsManager : MonoBehaviour
{
private const float RequestCooldownSeconds = 3f;
private static string FriendServiceUnavailable => LocalizationService.Get("friends.notice.service_uninitialized", "好友服务未初始化");
private static string AlreadyFriendNotice => LocalizationService.Get("friends.search.already_friend", "你们已经是好友");
private static string NetworkNotInitialized => LocalizationService.Get("friends.search.network_not_initialized", "网络服务尚未初始化");
public InputField searchFriend_iptfd;
public Button searchButton;
@@ -208,7 +211,7 @@ public class friendsManager : MonoBehaviour
prefab.Bind(
profile,
canSendRequest,
alreadyFriend ? "你们已经是好友" : string.Empty,
alreadyFriend ? AlreadyFriendNotice : string.Empty,
() => SendFriendRequestAsync(profile.steam_id),
RequestCooldownSeconds);
}
@@ -235,7 +238,7 @@ public class friendsManager : MonoBehaviour
NetworkManager network = NetworkManager.Instance;
if (network == null)
{
throw new Exception("NetworkManager is not initialized");
throw new Exception(NetworkNotInitialized);
}
string trimmed = query.Trim();
@@ -323,7 +326,7 @@ public class friendsManager : MonoBehaviour
ArenaRoomService arena = ArenaRoomService.Instance;
if (arena == null)
{
gNotice.error.display("好友服务未初始化");
gNotice.error.display(FriendServiceUnavailable);
EndAction(actionSignature);
return;
}
@@ -392,7 +395,7 @@ public class friendsManager : MonoBehaviour
ArenaRoomService arena = ArenaRoomService.Instance;
if (arena == null)
{
gNotice.error.display("好友服务未初始化");
gNotice.error.display(FriendServiceUnavailable);
EndAction(actionSignature);
return;
}
@@ -422,7 +425,7 @@ public class friendsManager : MonoBehaviour
ArenaRoomService arena = ArenaRoomService.Instance;
if (arena == null)
{
gNotice.error.display("好友服务未初始化");
gNotice.error.display(FriendServiceUnavailable);
EndAction(actionSignature);
return;
}
@@ -470,7 +473,7 @@ public class friendsManager : MonoBehaviour
ArenaRoomService arena = ArenaRoomService.Instance;
if (arena == null)
{
gNotice.error.display("好友服务未初始化");
gNotice.error.display(FriendServiceUnavailable);
EndAction(actionSignature);
return;
}