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(); } private void OnViewChange(string peerid, bool 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); } 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); } } } public void OnBigBtn(string peerid) { for (int i = 0; i < PeerList.Count; i++) { if (PeerList[i].PeerId == peerid) { ItemUserlist[i].gameObject.SetActive(false); } } } public void OnCloseBtn(string peerid) { for (int i = 0; i < PeerList.Count; i++) { if (PeerList[i].PeerId == peerid) { ItemUserlist[i].gameObject.SetActive(true); } } } } }