改动与优化
This commit is contained in:
@@ -41,6 +41,7 @@ public class friendCardPrefab : MonoBehaviour
|
||||
private bool _bindingToggle;
|
||||
private Sprite _defaultProfileBorderSprite;
|
||||
private bool _subscribedToChatState;
|
||||
private FriendCardViewData _boundData;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -53,6 +54,7 @@ public class friendCardPrefab : MonoBehaviour
|
||||
{
|
||||
SubscribeChatState();
|
||||
RefreshChattingVisual();
|
||||
EnsureAvatarLoadStarted();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
@@ -69,11 +71,18 @@ public class friendCardPrefab : MonoBehaviour
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (_avatarLoadRoutine != null)
|
||||
{
|
||||
StopCoroutine(_avatarLoadRoutine);
|
||||
_avatarLoadRoutine = null;
|
||||
}
|
||||
|
||||
UnsubscribeChatState();
|
||||
}
|
||||
|
||||
public void Bind(FriendCardViewData data, Action<string, bool> onStarChanged, Action<string> onOpenDetails, Action<string> onOpenPrivateConversation)
|
||||
{
|
||||
_boundData = data;
|
||||
_steamId = data != null ? data.SteamId : string.Empty;
|
||||
_starChanged = onStarChanged;
|
||||
_openDetails = onOpenDetails;
|
||||
@@ -115,12 +124,36 @@ public class friendCardPrefab : MonoBehaviour
|
||||
if (_avatarLoadRoutine != null)
|
||||
{
|
||||
StopCoroutine(_avatarLoadRoutine);
|
||||
_avatarLoadRoutine = null;
|
||||
}
|
||||
_avatarLoadRoutine = StartCoroutine(LoadAvatarRoutine(data));
|
||||
|
||||
EnsureAvatarLoadStarted();
|
||||
|
||||
RefreshChattingVisual();
|
||||
}
|
||||
|
||||
private void EnsureAvatarLoadStarted()
|
||||
{
|
||||
if (friendProfile == null || _boundData == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_avatarLoadRoutine != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (isActiveAndEnabled)
|
||||
{
|
||||
_avatarLoadRoutine = StartCoroutine(LoadAvatarRoutine(_boundData));
|
||||
}
|
||||
else
|
||||
{
|
||||
ApplyCachedAvatarIfAvailable(_boundData);
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleStarToggleChanged(bool isOn)
|
||||
{
|
||||
if (_bindingToggle)
|
||||
@@ -256,6 +289,20 @@ public class friendCardPrefab : MonoBehaviour
|
||||
_avatarLoadRoutine = null;
|
||||
}
|
||||
|
||||
private void ApplyCachedAvatarIfAvailable(FriendCardViewData data)
|
||||
{
|
||||
if (friendProfile == null || data == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string resolvedAvatarUrl = NetworkManager.ResolveAvatarUrl(data.AvatarUrl, data.SteamId);
|
||||
if (playerMessagePrefab.TryGetCachedAvatarSprite(data.SteamId, resolvedAvatarUrl, out Sprite cachedSprite) && cachedSprite != null)
|
||||
{
|
||||
friendProfile.sprite = cachedSprite;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator LoadSteamAvatarRoutine(string steamId)
|
||||
{
|
||||
#if !(UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX || UNITY_STANDALONE_OSX || STEAMWORKS_WIN || STEAMWORKS_LIN_OSX)
|
||||
|
||||
Reference in New Issue
Block a user