BaseList.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.EventSystems;
  6. public abstract class BaseList : BaseWindow {
  7. private BaseView[] _baseViewList;
  8. public BaseView[] BaseViewList {
  9. get {
  10. if (_baseViewList==null) {
  11. _baseViewList = GetComponentsInChildren<BaseView>();
  12. }
  13. return _baseViewList;
  14. }
  15. }
  16. public List<BaseConfig> configs;
  17. public int SumPage { get; set; }
  18. public int CurrentPage { get; set; }
  19. //public int CurrentViewNum=1;
  20. [Header("Can Emplty")]
  21. public SCButton preButton;
  22. [Header("Can Emplty")]
  23. public SCButton nextButton;
  24. [Header("Can Emplty")]
  25. public TextMesh title;
  26. [Header("Can Emplty")]
  27. public TextMesh pageNum;
  28. [Header("Can Emplty")]
  29. public Mark marks;
  30. void UpdateButtonsStatus() {
  31. if (SumPage == 1) {
  32. if (nextButton && nextButton.gameObject.activeSelf == true) {
  33. nextButton.gameObject.SetActive(false);
  34. }
  35. if (preButton && preButton.gameObject.activeSelf == true) {
  36. preButton.gameObject.SetActive(false);
  37. }
  38. } else if (CurrentPage == SumPage) {
  39. if (nextButton && nextButton.gameObject.activeSelf == true) {
  40. nextButton.gameObject.SetActive(false);
  41. }
  42. if (preButton && preButton.gameObject.activeSelf == false) {
  43. preButton.gameObject.SetActive(true);
  44. }
  45. } else if (CurrentPage == 1) {
  46. if (nextButton && nextButton.gameObject.activeSelf == false) {
  47. nextButton.gameObject.SetActive(true);
  48. }
  49. if (preButton && preButton.gameObject.activeSelf == true) {
  50. preButton.gameObject.SetActive(false);
  51. }
  52. } else {
  53. if (nextButton && nextButton.gameObject.activeSelf == false) {
  54. nextButton.gameObject.SetActive(true);
  55. }
  56. if (preButton && preButton.gameObject.activeSelf == false) {
  57. preButton.gameObject.SetActive(true);
  58. }
  59. }
  60. }
  61. public override void Awake() {
  62. base.Awake();
  63. SCButtonAddListener();
  64. }
  65. public void SetTitle(string title) {
  66. if (this.title) {
  67. this.title.text = title;
  68. }
  69. }
  70. public virtual void UpdateConfigs(List<BaseConfig> configs)
  71. {
  72. if (configs == null) {
  73. configs = new List<BaseConfig>();
  74. }
  75. Debug.Log("pei" + 1);
  76. this.configs = configs;
  77. try {
  78. //configs[CurrentViewNum-1].Init();
  79. } catch (Exception e) {
  80. //Debug.Log(e);
  81. }
  82. ///重新计算SumPage
  83. int aPageMaxView = BaseViewList.Length;
  84. Debug.Log("pei" + aPageMaxView+"teng");
  85. int sumConfigCount = configs.Count;
  86. Debug.Log("pei" + sumConfigCount + "fei");
  87. SumPage = sumConfigCount / aPageMaxView + (((sumConfigCount % aPageMaxView) != 0) ? 1 : 0);
  88. Debug.Log("pei" + SumPage + "tengfei");
  89. if (SumPage == 0)
  90. SumPage = 1;
  91. CurrentPage = 1;
  92. //Debug.Log("sumConfigCount:"+ sumConfigCount +" UpdateConfigs:" +SumPage);
  93. Refresh();
  94. }
  95. public virtual void Refresh() {
  96. if (configs == null)
  97. return;
  98. Debug.Log(777);
  99. ///Reset BaseView
  100. foreach (BaseView item in BaseViewList) {
  101. item.gameObject.SetActive(false);
  102. item.UpdateConfig(null);
  103. }
  104. Debug.Log(888);
  105. ///填充BaseView
  106. for (int i = (CurrentPage - 1) * BaseViewList.Length, j = 0; j < ((CurrentPage == SumPage) ? (configs.Count - BaseViewList.Length * (CurrentPage - 1)) : BaseViewList.Length); i++, j++)
  107. {
  108. configs[i].Index = i;
  109. if (BaseViewList.Length > j)
  110. {
  111. BaseViewList[j].gameObject.SetActive(true);
  112. BaseViewList[j].UpdateConfig(configs[i]);
  113. }
  114. }
  115. Debug.Log(999);
  116. UpdateButtonsStatus();
  117. if (pageNum) {
  118. pageNum.text = CurrentPage + "/" + SumPage;
  119. }
  120. if(marks) {
  121. marks.RefreshMarks(SumPage, CurrentPage);
  122. }
  123. }
  124. public void SCButtonAddListener() {
  125. if (preButton) {
  126. preButton.onEnter.AddListener(PreButtonOnEnter);
  127. preButton.onClick.AddListener(PreButtonOnClick);
  128. preButton.onDown.AddListener(PreButtonOnDown);
  129. preButton.onUp.AddListener(PreButtonOnUp);
  130. preButton.onExit.AddListener(PreButtonOnExit);
  131. }
  132. if (nextButton) {
  133. nextButton.onEnter.AddListener(NextButtonOnEnter);
  134. nextButton.onClick.AddListener(NextButtonOnClick);
  135. nextButton.onDown.AddListener(NextButtonOnDown);
  136. nextButton.onUp.AddListener(NextButtonOnUp);
  137. nextButton.onExit.AddListener(NextButtonOnExit);
  138. }
  139. }
  140. public virtual void NextButtonOnEnter() {
  141. }
  142. public virtual void NextButtonOnDown() {
  143. }
  144. public virtual void NextButtonOnUp() {
  145. CurrentPage = (CurrentPage + 1) > SumPage ? SumPage : (CurrentPage + 1);
  146. Refresh();
  147. }
  148. public virtual void NextButtonOnExit() {
  149. }
  150. public virtual void NextButtonOnClick() {
  151. }
  152. public virtual void PreButtonOnEnter() {
  153. }
  154. public virtual void PreButtonOnDown() {
  155. }
  156. public virtual void PreButtonOnUp() {
  157. CurrentPage = (CurrentPage - 1) < 1 ? 1 : (CurrentPage - 1);
  158. Refresh();
  159. }
  160. public virtual void PreButtonOnExit() {
  161. }
  162. public virtual void PreButtonOnClick() {
  163. }
  164. }