NormalList.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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].baselist = this;
  47. Views[i].gameObject.SetActive(true);
  48. vIndex++;
  49. }
  50. else
  51. {
  52. Views[i].gameObject.SetActive(false);
  53. }
  54. }
  55. if(tPage!=null)
  56. {
  57. tPage.text = (nPage+1) + "/" + (getMaxPage()+1);
  58. }
  59. }
  60. public override void initList(List<BaseConfig> c)
  61. {
  62. base.initList(c);
  63. for (int i = 0; i < Views.Count; i++)
  64. {
  65. Views[i].transform.localPosition = new Vector3(((i) % Row) * rowSpacing, -((i) / Row) * columnSpacing, 0);
  66. }
  67. setPage(0);
  68. if (bLeft != null)
  69. {
  70. bLeft.AddComponent<Button>().onClick.AddListener(clickLeft);
  71. }
  72. if (bRight != null)
  73. {
  74. bRight.AddComponent<Button>().onClick.AddListener(clickRight);
  75. }
  76. }
  77. public int getMaxPage()
  78. {
  79. return ((configs.Count - 1) / (Views.Count));
  80. }
  81. public override void updateConfig(List<BaseConfig> c)
  82. {
  83. if (this.configs.Count < c.Count)
  84. {
  85. configs = new List<BaseConfig>();
  86. c.ForEach(i => configs.Add(i));
  87. setPage(getMaxPage());
  88. }
  89. else if(nPage>= getMaxPage())
  90. {
  91. configs = new List<BaseConfig>();
  92. c.ForEach(i => configs.Add(i));
  93. setPage(getMaxPage());
  94. }
  95. else
  96. {
  97. configs = new List<BaseConfig>();
  98. c.ForEach(i => configs.Add(i));
  99. }
  100. }
  101. }