using System; using System.Collections; using System.Collections.Generic; using System.Linq; using Cute; using UnityEngine; namespace Wizard; public class UserListView : MonoBehaviour { [SerializeField] private SimpleScrollViewUI _scrollView; [SerializeField] private UIPanel _panel; private List _userList; private string _actionButtonLabel; private Dictionary> _loadQueueDict = new Dictionary>(); private LoadQueue _loadQueue = new LoadQueue(); private List _loadedResourceList = new List(); public Action PlateCustomize { get; set; } public int PanelDepth { set { _panel.depth = value; } } public Action OnSelect { get; set; } public DialogBase Dialog { get; private set; } public static UserListView CreateDialog(GameObject prefab, List userList, Action actionButtonEvent, string actionButtonLabel) { DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose(); UserListView component = UnityEngine.Object.Instantiate(prefab).GetComponent(); dialogBase.SetObj(component.gameObject); dialogBase.SetSize(DialogBase.Size.M); dialogBase.SetButtonLayout(DialogBase.ButtonLayout.CloseBtn); component.Initialize(dialogBase, userList, actionButtonEvent, actionButtonLabel); return component; } public static UserListView CreateView(GameObject prefab, GameObject parent, List userList, Action actionButtonEvent, string actionButtonLabel) { UserListView component = NGUITools.AddChild(parent, prefab).GetComponent(); component.Initialize(null, userList, actionButtonEvent, actionButtonLabel); return component; } private void Initialize(DialogBase dialog, List userList, Action actionButton, string actionButtonLabel) { _actionButtonLabel = actionButtonLabel; _userList = userList; OnSelect = actionButton; Dialog = dialog; UIManager.GetInstance().createInSceneCenterLoading(); StartCoroutine(LoadFriendUserImages(userList, delegate { _scrollView.CreateScrollView(userList.Count, InitializeInviteFriendPlate); UIManager.GetInstance().closeInSceneCenterLoading(); })); } private void OnDestroy() { UnloadImages(); } private void UnloadImages() { if (_loadedResourceList.Count > 0) { Toolbox.ResourcesManager.RemoveAssetGroup(_loadedResourceList); _loadedResourceList.Clear(); } } private void InitializeInviteFriendPlate(int index, GameObject plateObject) { UserListViewPlate component = plateObject.GetComponent(); component.Initialize(_userList[index], _actionButtonLabel); component.SetUnderLine(index < _userList.Count - 1); component.OnAction = delegate(UserInfoBase userInfo) { OnSelect.Call(userInfo); }; PlateCustomize.Call(component, _userList[index]); } private IEnumerator LoadFriendUserImages(List userList, Action callBack = null) { List loadPathList = new List(); List list = new List(); _loadQueueDict.Clear(); for (int i = 0; i < userList.Count; i++) { List list2 = new List(userList[i].GetUserAssetPathList().Except(list).Except(_loadedResourceList)); if (i < _scrollView.ScrollObjectNum) { loadPathList.AddRange(list2); } else { string text = i.ToString(); _loadQueueDict.Add(text, list2); LoadQueue.Callback onEnd = delegate(string id) { _loadedResourceList.AddRange(_loadQueueDict[id]); }; _loadQueue.AddToLast(text, list2, null, onEnd); } list.AddRange(list2); } if (loadPathList.Count > 0) { yield return StartCoroutine(Toolbox.ResourcesManager.LoadAssetGroupAsync(loadPathList, null)); _loadedResourceList.AddRange(loadPathList); } _loadQueue.StartLoad(); callBack.Call(); } }