CurvedUIBaseController.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. /// <summary>
  7. /// 弧形曲面原型控制器
  8. /// </summary>
  9. public class CurvedUIBaseController : MonoBehaviour
  10. {
  11. public enum ShowInfoType
  12. {
  13. text,
  14. distance
  15. }
  16. public Transform _base;
  17. public RectTransform _uiCanvasRect;
  18. public RectTransform _hightControllerRect;
  19. public RectTransform _widthControllerRect;
  20. public RectTransform _arrows;
  21. public Text _distanceText;
  22. private RectTransform _distanceRectTransform;
  23. public Text _descriptsText;
  24. private RectTransform _descriptsRectTransform;
  25. public CurvedUIInfo _curvedUIInfo;
  26. private void Awake()
  27. {
  28. Init();
  29. }
  30. private void Init()
  31. {
  32. if (_base != null)
  33. _base = this.transform.Find("Base");
  34. if (_uiCanvasRect != null)
  35. _uiCanvasRect = _base.transform.Find("Canvas").GetComponent<RectTransform>();
  36. if (_hightControllerRect != null)
  37. _hightControllerRect = _uiCanvasRect.transform.Find("HeightController").GetComponent<RectTransform>();
  38. if (_widthControllerRect != null)
  39. _widthControllerRect = _hightControllerRect.transform.Find("WidthController").GetComponent<RectTransform>();
  40. _arrows = _widthControllerRect.transform.Find("Arrows_Double").GetComponent<RectTransform>();
  41. _distanceText = _widthControllerRect.transform.Find("DistanceDescription_txt").GetComponent<Text>();
  42. _descriptsText = _widthControllerRect.transform.Find("Description_txt").GetComponent<Text>();
  43. _distanceRectTransform = _distanceText.transform.GetComponent<RectTransform>();
  44. _descriptsRectTransform = _descriptsText.transform.GetComponent<RectTransform>();
  45. _distanceText.gameObject.SetActive(false);
  46. _arrows.gameObject.SetActive(false);
  47. _descriptsText.gameObject.SetActive(false);
  48. }
  49. /// <summary>
  50. /// 设置当前CUIBase状态
  51. /// </summary>
  52. public void SetCurrentCurvedUIState()
  53. {
  54. this.transform.position = _curvedUIInfo._centerPoint.position + _curvedUIInfo._centerPoint.transform.right * _curvedUIInfo._redio;
  55. this.transform.LookAt(this.transform.position + _curvedUIInfo._centerPoint.transform.forward, _curvedUIInfo._centerPoint.up);
  56. float _uiHeightValue = 2 * _curvedUIInfo._redio * Mathf.PI * 1000;
  57. _uiCanvasRect.SetHeight(_uiHeightValue);
  58. _hightControllerRect.SetHeight(_uiHeightValue);
  59. _widthControllerRect.SetWidth(_curvedUIInfo._widthValue * 1000);
  60. if (_distanceRectTransform == null)
  61. {
  62. _distanceRectTransform = _distanceText.transform.GetComponent<RectTransform>();
  63. }
  64. if (_descriptsRectTransform == null)
  65. {
  66. _descriptsRectTransform = _descriptsText.transform.GetComponent<RectTransform>();
  67. }
  68. _arrows.SetLocalPositionY(_uiHeightValue / 4 - 20);
  69. _distanceRectTransform.SetLocalPositionY(_uiHeightValue / 4);
  70. _descriptsRectTransform.SetLocalPositionY(_uiHeightValue / 4 - 10);
  71. SetInfoTypeState(_curvedUIInfo);
  72. }
  73. [ContextMenu("Open")]
  74. public void OpenCurvedUI(Action callBack = null)
  75. {
  76. if (!CurvedUIPool.Instance.isPlayCurvedLoadAni)
  77. {
  78. InitCurvedOpenState(true);
  79. return;
  80. }
  81. InitCurvedOpenState(false);
  82. _widthControllerRect.DoWidth(_curvedUIInfo._widthValue * 1000, 1,
  83. () =>
  84. {
  85. float _uiHeightValue = 2 * _curvedUIInfo._redio * Mathf.PI * 1000;
  86. _hightControllerRect.DoHeight(_uiHeightValue, 1
  87. , () =>
  88. {
  89. callBack?.Invoke();
  90. InitCurvedOpenState(true);
  91. });
  92. }
  93. );
  94. }
  95. [ContextMenu("Close")]
  96. public void CloseCurvedUI(Action callBack = null)
  97. {
  98. if (!CurvedUIPool.Instance.isPlayCurvedLoadAni)
  99. {
  100. InitCurvedOpenState(false);
  101. return;
  102. }
  103. InitCurvedOpenState(true);
  104. _hightControllerRect.DoHeight(0, 1, () =>
  105. {
  106. _widthControllerRect.DoWidth(0, 1, () =>
  107. {
  108. callBack?.Invoke();
  109. InitCurvedOpenState(false);
  110. });
  111. switch (_curvedUIInfo._showInfoType)
  112. {
  113. case ShowInfoType.text:
  114. _descriptsText.gameObject.SetActive(false);
  115. break;
  116. case ShowInfoType.distance:
  117. _distanceText.gameObject.SetActive(false);
  118. break;
  119. }
  120. });
  121. }
  122. public void InitCurvedOpenState(bool openState)
  123. {
  124. if (_curvedUIInfo == null) return;
  125. float _uiHeightValue = openState ? 2 * _curvedUIInfo._redio * Mathf.PI * 1000 : 0;
  126. _hightControllerRect.SetHeight(openState ? _uiHeightValue : 0);
  127. _widthControllerRect.SetWidth(openState ? _curvedUIInfo._widthValue * 1000 : 0);
  128. switch (_curvedUIInfo._showInfoType)
  129. {
  130. case ShowInfoType.text:
  131. _descriptsText.gameObject.SetActive(openState);
  132. break;
  133. case ShowInfoType.distance:
  134. _distanceText.gameObject.SetActive(openState);
  135. break;
  136. }
  137. }
  138. /// <summary>
  139. /// 设置当前展示信息状态
  140. /// </summary>
  141. public void SetInfoTypeState()
  142. {
  143. switch (_curvedUIInfo._showInfoType)
  144. {
  145. case ShowInfoType.text:
  146. _distanceText.gameObject.SetActive(false);
  147. _arrows.gameObject.SetActive(false);
  148. _descriptsText.gameObject.SetActive(true);
  149. break;
  150. case ShowInfoType.distance:
  151. _distanceText.gameObject.SetActive(true);
  152. _arrows.gameObject.SetActive(true);
  153. _descriptsText.gameObject.SetActive(false);
  154. break;
  155. default:
  156. break;
  157. }
  158. }
  159. /// <summary>
  160. /// 设置当前展示信息状态
  161. /// </summary>
  162. public void SetInfoTypeState(CurvedUIInfo info)
  163. {
  164. switch (info._showInfoType)
  165. {
  166. case ShowInfoType.text:
  167. _distanceText.gameObject.SetActive(false);
  168. _arrows.gameObject.SetActive(false);
  169. _descriptsText.gameObject.SetActive(true);
  170. _descriptsText.text = info._descriptsText;
  171. break;
  172. case ShowInfoType.distance:
  173. _distanceText.gameObject.SetActive(true);
  174. _arrows.gameObject.SetActive(true);
  175. _descriptsText.gameObject.SetActive(false);
  176. _distanceText.text = info._distanceText;
  177. break;
  178. default:
  179. break;
  180. }
  181. }
  182. /// <summary>
  183. /// 重置CUIInfo
  184. /// </summary>
  185. /// <param name="cuiInfo"></param>
  186. public void ReSetCurvedUIInfo(CurvedUIInfo cuiInfo)
  187. {
  188. _curvedUIInfo = cuiInfo;
  189. SetCurrentCurvedUIState();
  190. }
  191. }