GraphicHelpPanel.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using Common.Combat;
  2. using Fort23.Core;
  3. using Fort23.UTool;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. namespace Fort23.Mono
  7. {
  8. [UIBinding(prefab = "GraphicHelpPanel")]
  9. public partial class GraphicHelpPanel : UIPanel
  10. {
  11. public Button CloseBtn;
  12. public CustomStateController CustomStateController;
  13. public RectTransform MoveRoot;
  14. public int CurIndex;
  15. public int GraphicCount;
  16. public GameObjectPool GameObjectPool;
  17. private void Init()
  18. {
  19. IsShowAppBar = false;
  20. }
  21. public override async CTask<bool> AsyncInit(object[] uiData)
  22. {
  23. CTask<bool> InitCTask = CTask<bool>.Create();
  24. string name = (string)uiData[0];
  25. GraphicCount = (int)uiData[1];
  26. GameObjectPool = await GObjectPool.Instance.FetchAsync<GameObjectPool>(name);
  27. GameObjectPool.own.transform.SetParent(Root);
  28. GameObjectPool.own.transform.localScale = Vector3.one;
  29. GameObjectPool.own.transform.localPosition = Vector3.zero;
  30. CustomInit(GameObjectPool.own.GetComponent<ReferenceCollector>());
  31. InitCTask.SetResult(true);
  32. return await InitCTask;
  33. }
  34. public void CustomInit(ReferenceCollector referenceCollector)
  35. {
  36. CloseBtn = referenceCollector.Get<Button>("Btn_Close");
  37. CloseBtn.onClick.AddListener(CustomClose);
  38. CustomStateController = referenceCollector.Get<CustomStateController>("State");
  39. MoveRoot = referenceCollector.Get<RectTransform>("Root");
  40. CurIndex = 0;
  41. if (CurIndex == GraphicCount - 1)
  42. {
  43. Btn_Right.gameObject.SetActive(false);
  44. }
  45. else
  46. {
  47. Btn_Right.gameObject.SetActive(true);
  48. }
  49. if (CurIndex > 0)
  50. {
  51. Btn_Left.gameObject.SetActive(true);
  52. }
  53. else
  54. {
  55. Btn_Left.gameObject.SetActive(false);
  56. }
  57. }
  58. protected override void AddEvent()
  59. {
  60. }
  61. protected override void DelEvent()
  62. {
  63. }
  64. public override void AddButtonEvent()
  65. {
  66. Btn_Right.onClick.AddListener(Right);
  67. Btn_Left.onClick.AddListener(Left);
  68. MaskBtn.onClick.AddListener(CustomClose);
  69. }
  70. private void CustomClose()
  71. {
  72. UIManager.Instance.HideUIUIPanel<GraphicHelpPanel>();
  73. }
  74. private void Left()
  75. {
  76. if (CurIndex > 0)
  77. {
  78. MoveRoot.transform.localPosition += Vector3.right * 1103;
  79. CurIndex--;
  80. CustomStateController.ChangeState(CurIndex);
  81. }
  82. if (CurIndex == 0)
  83. {
  84. Btn_Left.gameObject.SetActive(false);
  85. }
  86. if (CurIndex < GraphicCount - 1)
  87. {
  88. Btn_Right.gameObject.SetActive(true);
  89. }
  90. }
  91. private void Right()
  92. {
  93. if (CurIndex < GraphicCount - 1)
  94. {
  95. MoveRoot.transform.localPosition -= Vector3.right * 1103;
  96. CurIndex++;
  97. CustomStateController.ChangeState(CurIndex);
  98. }
  99. if (CurIndex == GraphicCount - 1)
  100. {
  101. Btn_Right.gameObject.SetActive(false);
  102. }
  103. if (CurIndex > 0)
  104. {
  105. Btn_Left.gameObject.SetActive(true);
  106. }
  107. }
  108. public override void Close()
  109. {
  110. GObjectPool.Instance.Recycle(GameObjectPool);
  111. GameObjectPool = null;
  112. CloseBtn.onClick.RemoveAllListeners();
  113. base.Close();
  114. }
  115. }
  116. }