UserItemList.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. }
  21. private void OnViewChange(string peerid, bool isOut)
  22. {
  23. if (isOut)
  24. {
  25. OnBigBtn(peerid);
  26. }
  27. else
  28. {
  29. OnCloseBtn(peerid);
  30. }
  31. }
  32. public void Init(List<Peer> PeerList)
  33. {
  34. for (int i = 0; i < PeerList.Count; i++)
  35. {
  36. AddUserItem(PeerList[i]);
  37. }
  38. }
  39. public Peer GetPeer(string peerid)
  40. {
  41. for (int i = 0; i < PeerList.Count; i++)
  42. {
  43. if (PeerList[i].PeerId == peerid)
  44. {
  45. return PeerList[i];
  46. }
  47. }
  48. return null;
  49. }
  50. public void AddUserItem(Peer peer, Texture2D texture2 = null)
  51. {
  52. this.PeerList.Add(peer);
  53. GameObject obj = Instantiate(UserItem, transform) as GameObject;
  54. ItemUserlist.Add(obj);
  55. obj.transform.GetComponent<ItemUserView>().Init(peer);
  56. }
  57. public void DeleteUserItem(string peerId, Texture2D texture2 = null)
  58. {
  59. for (int i = 0; i < ItemUserlist.Count; i++)
  60. {
  61. ItemUserView userView = ItemUserlist[i].transform.GetComponent<ItemUserView>();
  62. if (userView._peer.PeerId == peerId)
  63. {
  64. DestroyImmediate(ItemUserlist[i]);
  65. ItemUserlist.RemoveAt(i);
  66. }
  67. }
  68. for (int i = 0; i < PeerList.Count; i++)
  69. {
  70. if (PeerList[i].PeerId == peerId)
  71. {
  72. PeerList.RemoveAt(i);
  73. }
  74. }
  75. }
  76. public void OnBigBtn(string peerid)
  77. {
  78. for (int i = 0; i < PeerList.Count; i++)
  79. {
  80. if (PeerList[i].PeerId == peerid)
  81. {
  82. ItemUserlist[i].gameObject.SetActive(false);
  83. }
  84. }
  85. }
  86. public void OnCloseBtn(string peerid)
  87. {
  88. for (int i = 0; i < PeerList.Count; i++)
  89. {
  90. if (PeerList[i].PeerId == peerid)
  91. {
  92. ItemUserlist[i].gameObject.SetActive(true);
  93. }
  94. }
  95. }
  96. }
  97. }