123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- 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>();
- }
- private void OnViewChange(string peerid, bool 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);
- }
- 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);
- }
- }
- }
- 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);
- }
- }
- }
- }
- }
|