BaseList.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class BaseList : MonoBehaviour
  5. {
  6. [HideInInspector]
  7. public int rCount = 0;
  8. [HideInInspector]
  9. public List<BaseConfig> configs = new List<BaseConfig>();
  10. [HideInInspector]
  11. public List<BaseView> Views = new List<BaseView>();
  12. [HideInInspector]
  13. private int maxCount;
  14. [HideInInspector]
  15. public int maxRowItemCount = 0;
  16. [HideInInspector]
  17. public int maxColumItemCount = 0;
  18. public int Row;
  19. public int Column;
  20. // Start is called before the first frame update
  21. void Start()
  22. {
  23. }
  24. public virtual void initList(List<BaseConfig> c)
  25. {
  26. if (Views.Count<=0)
  27. {
  28. maxCount = Row * Column;
  29. Views = new List<BaseView>();
  30. BaseView view = this.GetComponentInChildren<BaseView>();
  31. // Debug.Log("viewviewviewview");
  32. view.gameObject.SetActive(false);
  33. Views.Add(view);
  34. BaseView cloneView;
  35. for (int i = 0; i < maxCount - 1; i++)
  36. {
  37. cloneView = Instantiate(view);
  38. cloneView.transform.parent = this.transform;
  39. cloneView.name = view.name + "_" + (i + 1);
  40. cloneView.transform.localScale = view.transform.localScale;
  41. cloneView.transform.localRotation = view.transform.localRotation;
  42. Views.Add(cloneView);
  43. }
  44. }
  45. configs = new List<BaseConfig>();
  46. c.ForEach(i => configs.Add(i));
  47. int vindex=0;
  48. for (int i = 0; i < Views.Count; i++)
  49. {
  50. if(i< configs.Count)
  51. {
  52. Views[i].init(i, configs[i], vindex);
  53. Views[i].baselist = this;
  54. Views[i].gameObject.SetActive(true);
  55. vindex++;
  56. Debug.Log(i);
  57. if(i==1)
  58. {
  59. // 进入房间默认打开第一个人的视频画面
  60. //AgoraVideoAudioManager.Instance.ShowOneView(RoomMain.Instance.agoraRawImage);
  61. }
  62. }
  63. else
  64. {
  65. Views[i].gameObject.SetActive(false);
  66. }
  67. }
  68. maxRowItemCount = (this.configs.Count - 1) / Row + 1;
  69. maxColumItemCount = (this.configs.Count - 1) / Column + 1;
  70. // rCount = maxItemCount;
  71. }
  72. public void showItems(int start,int end,bool isShow=false)
  73. {
  74. int vindex = 0;
  75. for (int i = 0; i < Views.Count; i++)
  76. {
  77. Views[i].sx = i;
  78. if ((i + start) < configs.Count&&i<= (end - start)&& (i + start)>=0)
  79. {
  80. if (Views[i].Index!= (i + start))
  81. {
  82. Views[i].init((i + start),configs[(i + start)], vindex);
  83. Views[i].baselist = this;
  84. }
  85. if (Views[i].isShow|| isShow)
  86. {
  87. Views[i].gameObject.SetActive(true);
  88. vindex++;
  89. }
  90. }
  91. else
  92. {
  93. Views[i].gameObject.SetActive(false);
  94. }
  95. }
  96. }
  97. public void showItems(List<int> items)
  98. {
  99. int vindex = 0;
  100. for (int i = 0; i < items.Count; i++)
  101. {
  102. if(items[i]>=0)
  103. {
  104. if(configs.Count>items[i])
  105. {
  106. if (Views[i].Index != items[i])
  107. {
  108. Views[i].init(items[i], configs[items[i]], vindex);
  109. Views[i].baselist = this;
  110. }
  111. Views[i].gameObject.SetActive(true);
  112. vindex++;
  113. }
  114. else
  115. {
  116. Views[i].gameObject.SetActive(false);
  117. }
  118. }
  119. else
  120. {
  121. Views[i].gameObject.SetActive(false);
  122. }
  123. }
  124. }
  125. public virtual void updateConfig(List<BaseConfig> configs)
  126. {
  127. // this.configs = configs;
  128. initList(configs);
  129. }
  130. }