UserItemList.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using ShadowStudio.Model;
  2. using ShadowStudio.Tool;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using XRTool.Util;
  8. namespace ShadowStudio.Mgr
  9. {
  10. public class UserItemList : UnitySingleton<UserItemList>
  11. {
  12. public GameObject UserItem;
  13. private List<GameObject> ItemUserlist;
  14. public List<Peer> PeerList;
  15. // Start is called before the first frame update
  16. void Start()
  17. {
  18. ItemUserlist = new List<GameObject>();
  19. PeerList = new List<Peer>();
  20. PlayerViewComponent.ViewChange += OnViewChange;
  21. }
  22. private void OnViewChange(string peerid, bool isOut)
  23. {
  24. Debug.Log("peerid====>" + peerid);
  25. Debug.Log("isOut====>" + isOut);
  26. if (isOut)
  27. {
  28. OnBigBtn(peerid);
  29. }
  30. else
  31. {
  32. OnCloseBtn(peerid);
  33. }
  34. }
  35. public void Init(List<Peer> PeerList)
  36. {
  37. for (int i = 0; i < PeerList.Count; i++)
  38. {
  39. AddUserItem(PeerList[i]);
  40. }
  41. }
  42. public Peer GetPeer(string peerid)
  43. {
  44. for (int i = 0; i < PeerList.Count; i++)
  45. {
  46. if (PeerList[i].PeerId == peerid)
  47. {
  48. return PeerList[i];
  49. }
  50. }
  51. return null;
  52. }
  53. public void AddUserItem(Peer peer, Texture2D texture2 = null)
  54. {
  55. this.PeerList.Add(peer);
  56. GameObject obj = Instantiate(UserItem, transform) as GameObject;
  57. ItemUserlist.Add(obj);
  58. obj.transform.GetComponent<ItemUserView>().Init(peer);
  59. if (PlayerViewComponent.viewDic.ContainsKey(peer.PeerId))
  60. {
  61. obj.SetActive(false);
  62. }
  63. if (BoardDlg.Instance != null)
  64. {
  65. BoardDlg.Instance.roomNum.text = ItemUserlist.Count + "/" + CommonMethod.roomConfig.Max_member;
  66. }
  67. }
  68. public void DeleteUserItem(string peerId, Texture2D texture2 = null)
  69. {
  70. for (int i = 0; i < ItemUserlist.Count; i++)
  71. {
  72. ItemUserView userView = ItemUserlist[i].transform.GetComponent<ItemUserView>();
  73. if (userView._peer.PeerId == peerId)
  74. {
  75. DestroyImmediate(ItemUserlist[i]);
  76. ItemUserlist.RemoveAt(i);
  77. }
  78. }
  79. for (int i = 0; i < PeerList.Count; i++)
  80. {
  81. if (PeerList[i].PeerId == peerId)
  82. {
  83. PeerList.RemoveAt(i);
  84. }
  85. }
  86. if (BoardDlg.Instance != null)
  87. {
  88. BoardDlg.Instance.roomNum.text = ItemUserlist.Count + "/" + CommonMethod.roomConfig.Max_member;
  89. }
  90. }
  91. public void OnBigBtn(string peerid)
  92. {
  93. for (int i = 0; i < PeerList.Count; i++)
  94. {
  95. if (PeerList[i].PeerId == peerid)
  96. {
  97. try { ItemUserlist[i].SetActive(false); } catch { }
  98. }
  99. }
  100. }
  101. public void OnCloseBtn(string peerid)
  102. {
  103. for (int i = 0; i < PeerList.Count; i++)
  104. {
  105. if (PeerList[i].PeerId == peerid&& ItemUserlist[i]!=null)
  106. {
  107. try { ItemUserlist[i].SetActive(true); } catch { }
  108. }
  109. }
  110. }
  111. }
  112. }