using System; using System.Collections.Generic; using System.Linq; using Cute; using UnityEngine; namespace Wizard; public class ChatReplayListDialog : MonoBehaviour { [SerializeField] private SimpleScrollViewUI _replayListScrollView; [SerializeField] private UILabel _labelNoReplay; private List _listReplayInfoItem; private Action _onClickReplaySendBtn; private List _loadedResourceList = new List(); public void Init(List listReplayInfoItem, Action onClickReplaySendBtn) { _listReplayInfoItem = listReplayInfoItem; _onClickReplaySendBtn = onClickReplaySendBtn; CreateReplayList(); } private void CreateReplayList() { bool flag = _listReplayInfoItem.Count <= 0; _replayListScrollView.SetVisiable(!flag); _labelNoReplay.gameObject.SetActive(flag); if (!flag) { LoadResources(delegate { _replayListScrollView.CreateScrollView(_listReplayInfoItem.Count, OnInitializeContent); }); } } private void OnInitializeContent(int index, GameObject plate) { ReplayInfoItem replayInfo = _listReplayInfoItem[index]; plate.GetComponent().SetData(replayInfo, delegate { _onClickReplaySendBtn.Call(replayInfo); }); } private void LoadResources(Action callBack = null) { UIManager.GetInstance().createInSceneCenterLoading(); List list = new List(); foreach (ReplayInfoItem item in _listReplayInfoItem) { list.Add(Toolbox.ResourcesManager.GetAssetTypePath(item.OpponentEmblemId, ResourcesManager.AssetLoadPathType.Emblem_S)); if (!string.IsNullOrEmpty(item.OpponentCountryCode)) { list.Add(Toolbox.ResourcesManager.GetAssetTypePath(item.OpponentCountryCode, ResourcesManager.AssetLoadPathType.Country_S)); } } List loadPathList = list.Distinct().Except(_loadedResourceList).ToList(); if (loadPathList.Count > 0) { StartCoroutine(Toolbox.ResourcesManager.LoadAssetGroupAsync(loadPathList, delegate { _loadedResourceList.AddRange(loadPathList); UIManager.GetInstance().closeInSceneCenterLoading(); callBack.Call(); })); } } private void UnloadResources() { if (_loadedResourceList.Count > 0) { Toolbox.ResourcesManager.RemoveAssetGroup(_loadedResourceList); _loadedResourceList.Clear(); } } private void OnDestroy() { UnloadResources(); } }