NormalList.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class NormalList : BaseList
  6. {
  7. public float rowSpacing;
  8. public float columnSpacing;
  9. public GameObject bLeft;
  10. public GameObject bRight;
  11. public TextMesh tPage;
  12. private int nPage=0;
  13. public void clickLeft()
  14. {
  15. nPage--;
  16. if (nPage < 0)
  17. {
  18. nPage = 0;
  19. }
  20. else
  21. {
  22. setPage(nPage);
  23. }
  24. }
  25. public void clickRight()
  26. {
  27. nPage++;
  28. if (nPage > getMaxPage())
  29. {
  30. nPage = getMaxPage();
  31. }
  32. else
  33. {
  34. setPage(nPage);
  35. }
  36. }
  37. public void setPage(int index)
  38. {
  39. nPage = index;
  40. int vIndex=0;
  41. for (int i=0;i<Views.Count ;i++)
  42. {
  43. if(configs.Count>(i+index*(Views.Count)))
  44. {
  45. Views[i].init((i + index * (Views.Count)),configs[(i + index * (Views.Count ))], vIndex);
  46. Views[i].gameObject.SetActive(true);
  47. vIndex++;
  48. }
  49. else
  50. {
  51. Views[i].gameObject.SetActive(false);
  52. }
  53. }
  54. if(tPage!=null)
  55. {
  56. tPage.text = (nPage+1) + "/" + (getMaxPage()+1);
  57. }
  58. }
  59. public override void initList(List<BaseConfig> c)
  60. {
  61. base.initList(c);
  62. for (int i = 0; i < Views.Count; i++)
  63. {
  64. Views[i].transform.localPosition = new Vector3(((i) % Row) * rowSpacing, -((i) / Row) * columnSpacing, 0);
  65. }
  66. setPage(0);
  67. if (bLeft != null)
  68. {
  69. bLeft.AddComponent<Button>().onClick.AddListener(clickLeft);
  70. }
  71. if (bRight != null)
  72. {
  73. bRight.AddComponent<Button>().onClick.AddListener(clickRight);
  74. }
  75. }
  76. public int getMaxPage()
  77. {
  78. return ((configs.Count - 1) / (Views.Count));
  79. }
  80. public override void updateConfig(List<BaseConfig> c)
  81. {
  82. if (this.configs.Count < c.Count)
  83. {
  84. configs = new List<BaseConfig>();
  85. c.ForEach(i => configs.Add(i));
  86. setPage(getMaxPage());
  87. }
  88. else if(nPage>= getMaxPage())
  89. {
  90. configs = new List<BaseConfig>();
  91. c.ForEach(i => configs.Add(i));
  92. setPage(getMaxPage());
  93. }
  94. else
  95. {
  96. configs = new List<BaseConfig>();
  97. c.ForEach(i => configs.Add(i));
  98. }
  99. }
  100. }