using ShadowStudio.Model; using ShadowStudio.Tool; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using XRTool.Util; namespace ShadowStudio.Mgr { public class UserItemList : UnitySingleton { public GameObject UserItem; private List ItemUserlist; public List PeerList; // Start is called before the first frame update void Start() { ItemUserlist = new List(); PeerList = new List(); PlayerViewComponent.ViewChange += OnViewChange; } private void OnViewChange(string peerid, bool isOut) { Debug.Log("peerid====>" + peerid); Debug.Log("isOut====>" + isOut); if (isOut) { OnBigBtn(peerid); } else { OnCloseBtn(peerid); } } public void Init(List PeerList) { for (int i = 0; i < PeerList.Count; i++) { AddUserItem(PeerList[i]); } } public Peer GetPeer(string peerid) { for (int i = 0; i < PeerList.Count; i++) { if (PeerList[i].PeerId == peerid) { return PeerList[i]; } } return null; } public void AddUserItem(Peer peer, Texture2D texture2 = null) { this.PeerList.Add(peer); GameObject obj = Instantiate(UserItem, transform) as GameObject; ItemUserlist.Add(obj); obj.transform.GetComponent().Init(peer); if (PlayerViewComponent.viewDic.ContainsKey(peer.PeerId)) { obj.SetActive(false); } if (BoardDlg.Instance != null) { BoardDlg.Instance.roomNum.text = ItemUserlist.Count + "/" + CommonMethod.roomConfig.Max_member; } } public void DeleteUserItem(string peerId, Texture2D texture2 = null) { for (int i = 0; i < ItemUserlist.Count; i++) { ItemUserView userView = ItemUserlist[i].transform.GetComponent(); if (userView._peer.PeerId == peerId) { DestroyImmediate(ItemUserlist[i]); ItemUserlist.RemoveAt(i); } } for (int i = 0; i < PeerList.Count; i++) { if (PeerList[i].PeerId == peerId) { PeerList.RemoveAt(i); } } if (BoardDlg.Instance != null) { BoardDlg.Instance.roomNum.text = ItemUserlist.Count + "/" + CommonMethod.roomConfig.Max_member; } } public void OnBigBtn(string peerid) { for (int i = 0; i < PeerList.Count; i++) { if (PeerList[i].PeerId == peerid) { try { ItemUserlist[i].SetActive(false); } catch { } } } } public void OnCloseBtn(string peerid) { for (int i = 0; i < PeerList.Count; i++) { if (PeerList[i].PeerId == peerid&& ItemUserlist[i]!=null) { try { ItemUserlist[i].SetActive(true); } catch { } } } } } }