123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- 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<UserItemList>
- {
- public GameObject UserItem;
- private List<GameObject> ItemUserlist;
- public List<Peer> PeerList;
- // Start is called before the first frame update
- void Start()
- {
- ItemUserlist = new List<GameObject>();
- PeerList = new List<Peer>();
- 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<Peer> 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<ItemUserView>().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<ItemUserView>();
- 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 { }
-
- }
- }
- }
- }
- }
|