改动与优化
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)
|
||||
|
||||
@@ -458,10 +458,12 @@ public class friendSystem : MonoBehaviour
|
||||
for (int index = 0; index < target.Count; index++)
|
||||
{
|
||||
FriendCardViewData friend = target[index];
|
||||
bool created = false;
|
||||
if (!_spawnedCards.TryGetValue(friend.SteamId, out GameObject cardObject) || cardObject == null)
|
||||
{
|
||||
cardObject = Instantiate(friendCardPrefab, friendsDisplayContent);
|
||||
_spawnedCards[friend.SteamId] = cardObject;
|
||||
created = true;
|
||||
}
|
||||
|
||||
cardObject.transform.SetSiblingIndex(index);
|
||||
@@ -470,6 +472,11 @@ public class friendSystem : MonoBehaviour
|
||||
{
|
||||
card.Bind(friend, HandleStarChanged, HandleOpenDetails, HandleOpenPrivateConversation);
|
||||
}
|
||||
|
||||
if (created)
|
||||
{
|
||||
UI_OrderedEntryAnimator.PlayFadeOnly(cardObject, index, 0.16f, 0.012f, true);
|
||||
}
|
||||
}
|
||||
|
||||
UpdateDefaultTextState(target.Count);
|
||||
|
||||
@@ -203,6 +203,7 @@ public class friendsManager : MonoBehaviour
|
||||
}
|
||||
|
||||
_spawnedSearchCard = Instantiate(friendSearchPrefab, friendSearchParent, false);
|
||||
UI_OrderedEntryAnimator.PlayFadeOnly(_spawnedSearchCard, 0, 0.16f, 0f, true);
|
||||
friendSearchPrefab prefab = _spawnedSearchCard.GetComponent<friendSearchPrefab>();
|
||||
if (prefab != null)
|
||||
{
|
||||
@@ -370,6 +371,7 @@ public class friendsManager : MonoBehaviour
|
||||
GameObject cardObject = Instantiate(friendRequestPrefab, parent, false);
|
||||
_spawnedRequestCards[request.id] = cardObject;
|
||||
cardObject.transform.SetSiblingIndex(index);
|
||||
UI_OrderedEntryAnimator.PlayFadeOnly(cardObject, index, 0.16f, 0.012f, true);
|
||||
friendRequestPrefab prefab = cardObject.GetComponent<friendRequestPrefab>();
|
||||
if (prefab != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user