BaseList.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. // AgoraVideoAudioManager.Instance.ShowOneView(RoomMain.Instance.agoraRawImage);
  60. //}
  61. }
  62. else
  63. {
  64. Views[i].gameObject.SetActive(false);
  65. }
  66. }
  67. maxRowItemCount = (this.configs.Count - 1) / Row + 1;
  68. maxColumItemCount = (this.configs.Count - 1) / Column + 1;
  69. // rCount = maxItemCount;
  70. }
  71. public void showItems(int start,int end,bool isShow=false)
  72. {
  73. int vindex = 0;
  74. for (int i = 0; i < Views.Count; i++)
  75. {
  76. Views[i].sx = i;
  77. if ((i + start) < configs.Count&&i<= (end - start)&& (i + start)>=0)
  78. {
  79. if (Views[i].Index!= (i + start))
  80. {
  81. Views[i].init((i + start),configs[(i + start)], vindex);
  82. Views[i].baselist = this;
  83. }
  84. if (Views[i].isShow|| isShow)
  85. {
  86. Views[i].gameObject.SetActive(true);
  87. vindex++;
  88. }
  89. }
  90. else
  91. {
  92. Views[i].gameObject.SetActive(false);
  93. }
  94. }
  95. }
  96. public void showItems(List<int> items)
  97. {
  98. int vindex = 0;
  99. for (int i = 0; i < items.Count; i++)
  100. {
  101. if(items[i]>=0)
  102. {
  103. if(configs.Count>items[i])
  104. {
  105. if (Views[i].Index != items[i])
  106. {
  107. Views[i].init(items[i], configs[items[i]], vindex);
  108. Views[i].baselist = this;
  109. }
  110. Views[i].gameObject.SetActive(true);
  111. vindex++;
  112. }
  113. else
  114. {
  115. Views[i].gameObject.SetActive(false);
  116. }
  117. }
  118. else
  119. {
  120. Views[i].gameObject.SetActive(false);
  121. }
  122. }
  123. }
  124. public virtual void updateConfig(List<BaseConfig> configs)
  125. {
  126. // this.configs = configs;
  127. initList(configs);
  128. }
  129. }