UIClubCreateComponentSystem.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using static System.Net.Mime.MediaTypeNames;
  7. namespace ET.Client
  8. {
  9. [FriendOf(typeof(UIClubCreateComponent))]
  10. public static class UIClubCreateComponentSystem
  11. {
  12. [ObjectSystem]
  13. public class UIClubCreateComponentAwakeSystem : AwakeSystem<UIClubCreateComponent>
  14. {
  15. protected override void Awake(UIClubCreateComponent self, params object[] param)
  16. {
  17. ReferenceCollector rc = self.GetParent<UI>().GameObject.GetComponent<ReferenceCollector>();
  18. self.returnBtn = rc.Get<GameObject>("returnBtn");
  19. self.createBtn = rc.Get<GameObject>("createBtn");
  20. self.joinBtn = rc.Get<GameObject>("joinBtn");
  21. self.inputClubObj = rc.Get<GameObject>("inputClubObj");
  22. self.inputClubCloseBtn = rc.Get<GameObject>("inputClubCloseBtn");
  23. self.inputClearBtn = rc.Get<GameObject>("inputClear");
  24. self.inputBackBtn = rc.Get<GameObject>("inputBack");
  25. self.showTxt = rc.Get<GameObject>("showTxt");
  26. self.createObj = rc.Get<GameObject>("createObj");
  27. self.createObjCloseBtn = rc.Get<GameObject>("createObjCloseBtn");
  28. self.sureBtn = rc.Get<GameObject>("sureBtn");
  29. for (int i = 0; i <= 9; i++)
  30. {
  31. var tempInput = rc.Get<GameObject>("input" + i);
  32. int index = i;
  33. tempInput.GetComponent<Button>().onClick.AddListener(() => { self.OnInputNumber(index); });
  34. }
  35. self.returnBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnReturnBtn(); });
  36. self.createBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnCreateOrJoinBtn(0); });
  37. self.joinBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnCreateOrJoinBtn(1); });
  38. self.inputClubCloseBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnInputClubCloseBtn(); });
  39. self.createObjCloseBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnCreateObjCloseOrSureBtn(0); });
  40. self.sureBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnCreateObjCloseOrSureBtn(1); });
  41. self.inputBackBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnInputBack(); });
  42. self.inputClearBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnInputClear(); });
  43. self.Init();
  44. }
  45. }
  46. private static void Init(this UIClubCreateComponent self)
  47. {
  48. self.inputClubObj.SetActive(false);
  49. self.createObj.SetActive(false);
  50. }
  51. public static async void OnCreateObjCloseOrSureBtn(this UIClubCreateComponent self,int index)
  52. {
  53. await SoundManager.Instance.PlaySound("clickbtnsound");
  54. self.createObj.SetActive(false);
  55. }
  56. public static void OnInputClubCloseBtn(this UIClubCreateComponent self)
  57. {
  58. self.inputClubObj.SetActive(false);
  59. }
  60. public static async void OnCreateOrJoinBtn(this UIClubCreateComponent self,int index)
  61. {
  62. await SoundManager.Instance.PlaySound("clickbtnsound");
  63. if (index == 0)
  64. {
  65. self.createObj.SetActive(true);
  66. }
  67. else
  68. {
  69. self.inputClubObj.SetActive(true);
  70. self.inputText = string.Empty;
  71. }
  72. }
  73. public static async void OnReturnBtn(this UIClubCreateComponent self)
  74. {
  75. await SoundManager.Instance.PlaySound("clickbtnsound");
  76. self.ReturnMain().Coroutine();
  77. }
  78. #region 输入面板信息
  79. public static async void OnInputNumber(this UIClubCreateComponent self, int index)
  80. {
  81. await SoundManager.Instance.PlaySound("clickbtnsound");
  82. self.updateShowText(index.ToString());
  83. }
  84. private static void updateShowText(this UIClubCreateComponent self, string add = "")
  85. {
  86. if (!string.IsNullOrEmpty(add) && self.inputText.Length < 6)
  87. {
  88. self.inputText = self.inputText + add;
  89. }
  90. if (self.inputText.Length == 6)
  91. {
  92. //已经6位了。。。
  93. //加入俱乐部请求。。
  94. }
  95. self.showTxt.GetComponent<UnityEngine.UI.Text>().text = self.inputText;
  96. }
  97. public static async void OnInputBack(this UIClubCreateComponent self)
  98. {
  99. await SoundManager.Instance.PlaySound("clickbtnsound");
  100. if (self.inputText.Length > 0)
  101. {
  102. self.inputText = self.inputText.Substring(0, self.inputText.Length - 1);
  103. self.showTxt.GetComponent<UnityEngine.UI.Text>().text = self.inputText;
  104. }
  105. }
  106. public static async void OnInputClear(this UIClubCreateComponent self)
  107. {
  108. await SoundManager.Instance.PlaySound("clickbtnsound");
  109. self.inputText = string.Empty;
  110. self.updateShowText();
  111. }
  112. #endregion
  113. static async ETTask ReturnMain(this UIClubCreateComponent self)
  114. {
  115. var scene = self.ClientScene();
  116. await UIHelper.Remove(scene, UIType.UIClubCreate);
  117. await UIHelper.Create(scene, UIType.UIMain, UILayer.Low);
  118. }
  119. public static async void OnCloseAsync(this UIClubCreateComponent self)
  120. {
  121. await UIHelper.Remove(self.ClientScene(),UIType.UIClubCreate);
  122. }
  123. }
  124. }