BaseList.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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;
  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. maxCount = Row * Column;
  24. Views = new List<BaseView>();
  25. BaseView view = this.GetComponentInChildren<BaseView>();
  26. // Debug.Log("viewviewviewview");
  27. view.gameObject.SetActive(false);
  28. Views.Add(view);
  29. BaseView cloneView;
  30. for (int i = 0; i < maxCount - 1; i++)
  31. {
  32. cloneView = Instantiate(view);
  33. cloneView.transform.parent = this.transform;
  34. cloneView.name = view.name + "_" + (i+1);
  35. cloneView.transform.localScale = view.transform.localScale;
  36. cloneView.transform.localRotation = view.transform.localRotation;
  37. Views.Add(cloneView);
  38. }
  39. }
  40. public virtual void initList(List<BaseConfig> c)
  41. {
  42. configs = new List<BaseConfig>();
  43. c.ForEach(i => configs.Add(i));
  44. int vindex=0;
  45. for (int i = 0; i < Views.Count; i++)
  46. {
  47. if(i< configs.Count)
  48. {
  49. Views[i].init(i, configs[i], vindex);
  50. Views[i].gameObject.SetActive(true);
  51. vindex++;
  52. }
  53. else
  54. {
  55. Views[i].gameObject.SetActive(false);
  56. }
  57. }
  58. maxRowItemCount = (this.configs.Count - 1) / Row + 1;
  59. maxColumItemCount = (this.configs.Count - 1) / Column + 1;
  60. // rCount = maxItemCount;
  61. }
  62. public void showItems(int start,int end,bool isShow=false)
  63. {
  64. int vindex = 0;
  65. for (int i = 0; i < Views.Count; i++)
  66. {
  67. Views[i].sx = i;
  68. if ((i + start) < configs.Count&&i<= (end - start)&& (i + start)>=0)
  69. {
  70. if (Views[i].Index!= (i + start))
  71. {
  72. Views[i].init((i + start),configs[(i + start)], vindex);
  73. }
  74. if (Views[i].isShow|| isShow)
  75. {
  76. Views[i].gameObject.SetActive(true);
  77. vindex++;
  78. }
  79. }
  80. else
  81. {
  82. Views[i].gameObject.SetActive(false);
  83. }
  84. }
  85. }
  86. public void showItems(List<int> items)
  87. {
  88. int vindex = 0;
  89. for (int i = 0; i < items.Count; i++)
  90. {
  91. if(items[i]>=0)
  92. {
  93. if(configs.Count>items[i])
  94. {
  95. if (Views[i].Index != items[i])
  96. {
  97. Views[i].init(items[i], configs[items[i]], vindex);
  98. }
  99. Views[i].gameObject.SetActive(true);
  100. vindex++;
  101. }
  102. else
  103. {
  104. Views[i].gameObject.SetActive(false);
  105. }
  106. }
  107. else
  108. {
  109. Views[i].gameObject.SetActive(false);
  110. }
  111. }
  112. }
  113. public virtual void updateConfig(List<BaseConfig> configs)
  114. {
  115. // this.configs = configs;
  116. initList(configs);
  117. }
  118. public virtual void UpdateConfigs(List<BaseConfig> configs)
  119. {
  120. // this.configs = configs;
  121. initList(configs);
  122. }
  123. }