123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- /// <summary>
- /// 弧形曲面原型控制器
- /// </summary>
- public class CurvedUIBaseController : MonoBehaviour
- {
- public enum ShowInfoType
- {
- text,
- distance
- }
- public Transform _base;
- public RectTransform _uiCanvasRect;
- public RectTransform _hightControllerRect;
- public RectTransform _widthControllerRect;
- public RectTransform _arrows;
- public Text _distanceText;
- private RectTransform _distanceRectTransform;
- public Text _descriptsText;
- private RectTransform _descriptsRectTransform;
- public CurvedUIInfo _curvedUIInfo;
- private void Awake()
- {
- Init();
- }
- private void Init()
- {
- if (_base != null)
- _base = this.transform.Find("Base");
- if (_uiCanvasRect != null)
- _uiCanvasRect = _base.transform.Find("Canvas").GetComponent<RectTransform>();
- if (_hightControllerRect != null)
- _hightControllerRect = _uiCanvasRect.transform.Find("HeightController").GetComponent<RectTransform>();
- if (_widthControllerRect != null)
- _widthControllerRect = _hightControllerRect.transform.Find("WidthController").GetComponent<RectTransform>();
- _arrows = _widthControllerRect.transform.Find("Arrows_Double").GetComponent<RectTransform>();
- _distanceText = _widthControllerRect.transform.Find("DistanceDescription_txt").GetComponent<Text>();
- _descriptsText = _widthControllerRect.transform.Find("Description_txt").GetComponent<Text>();
- _distanceRectTransform = _distanceText.transform.GetComponent<RectTransform>();
- _descriptsRectTransform = _descriptsText.transform.GetComponent<RectTransform>();
- _distanceText.gameObject.SetActive(false);
- _arrows.gameObject.SetActive(false);
- _descriptsText.gameObject.SetActive(false);
- }
- /// <summary>
- /// 设置当前CUIBase状态
- /// </summary>
- public void SetCurrentCurvedUIState()
- {
- this.transform.position = _curvedUIInfo._centerPoint.position + _curvedUIInfo._centerPoint.transform.right * _curvedUIInfo._redio;
- this.transform.LookAt(this.transform.position + _curvedUIInfo._centerPoint.transform.forward, _curvedUIInfo._centerPoint.up);
- float _uiHeightValue = 2 * _curvedUIInfo._redio * Mathf.PI * 1000;
- _uiCanvasRect.SetHeight(_uiHeightValue);
- _hightControllerRect.SetHeight(_uiHeightValue);
- _widthControllerRect.SetWidth(_curvedUIInfo._widthValue * 1000);
- if (_distanceRectTransform == null)
- {
- _distanceRectTransform = _distanceText.transform.GetComponent<RectTransform>();
- }
- if (_descriptsRectTransform == null)
- {
- _descriptsRectTransform = _descriptsText.transform.GetComponent<RectTransform>();
- }
- _arrows.SetLocalPositionY(_uiHeightValue / 4 - 20);
- _distanceRectTransform.SetLocalPositionY(_uiHeightValue / 4);
- _descriptsRectTransform.SetLocalPositionY(_uiHeightValue / 4 - 10);
- SetInfoTypeState(_curvedUIInfo);
- }
- [ContextMenu("Open")]
- public void OpenCurvedUI(Action callBack = null)
- {
- if (!CurvedUIPool.Instance.isPlayCurvedLoadAni)
- {
- InitCurvedOpenState(true);
- return;
- }
- InitCurvedOpenState(false);
- _widthControllerRect.DoWidth(_curvedUIInfo._widthValue * 1000, 1,
- () =>
- {
- float _uiHeightValue = 2 * _curvedUIInfo._redio * Mathf.PI * 1000;
- _hightControllerRect.DoHeight(_uiHeightValue, 1
- , () =>
- {
- callBack?.Invoke();
- InitCurvedOpenState(true);
- });
- }
- );
- }
- [ContextMenu("Close")]
- public void CloseCurvedUI(Action callBack = null)
- {
- if (!CurvedUIPool.Instance.isPlayCurvedLoadAni)
- {
- InitCurvedOpenState(false);
- return;
- }
- InitCurvedOpenState(true);
- _hightControllerRect.DoHeight(0, 1, () =>
- {
- _widthControllerRect.DoWidth(0, 1, () =>
- {
- callBack?.Invoke();
- InitCurvedOpenState(false);
- });
- switch (_curvedUIInfo._showInfoType)
- {
- case ShowInfoType.text:
- _descriptsText.gameObject.SetActive(false);
- break;
- case ShowInfoType.distance:
- _distanceText.gameObject.SetActive(false);
- break;
- }
- });
- }
- public void InitCurvedOpenState(bool openState)
- {
- if (_curvedUIInfo == null) return;
- float _uiHeightValue = openState ? 2 * _curvedUIInfo._redio * Mathf.PI * 1000 : 0;
- _hightControllerRect.SetHeight(openState ? _uiHeightValue : 0);
- _widthControllerRect.SetWidth(openState ? _curvedUIInfo._widthValue * 1000 : 0);
- switch (_curvedUIInfo._showInfoType)
- {
- case ShowInfoType.text:
- _descriptsText.gameObject.SetActive(openState);
- break;
- case ShowInfoType.distance:
- _distanceText.gameObject.SetActive(openState);
- break;
- }
- }
- /// <summary>
- /// 设置当前展示信息状态
- /// </summary>
- public void SetInfoTypeState()
- {
- switch (_curvedUIInfo._showInfoType)
- {
- case ShowInfoType.text:
- _distanceText.gameObject.SetActive(false);
- _arrows.gameObject.SetActive(false);
- _descriptsText.gameObject.SetActive(true);
- break;
- case ShowInfoType.distance:
- _distanceText.gameObject.SetActive(true);
- _arrows.gameObject.SetActive(true);
- _descriptsText.gameObject.SetActive(false);
- break;
- default:
- break;
- }
- }
- /// <summary>
- /// 设置当前展示信息状态
- /// </summary>
- public void SetInfoTypeState(CurvedUIInfo info)
- {
- switch (info._showInfoType)
- {
- case ShowInfoType.text:
- _distanceText.gameObject.SetActive(false);
- _arrows.gameObject.SetActive(false);
- _descriptsText.gameObject.SetActive(true);
- _descriptsText.text = info._descriptsText;
- break;
- case ShowInfoType.distance:
- _distanceText.gameObject.SetActive(true);
- _arrows.gameObject.SetActive(true);
- _descriptsText.gameObject.SetActive(false);
- _distanceText.text = info._distanceText;
- break;
- default:
- break;
- }
- }
- /// <summary>
- /// 重置CUIInfo
- /// </summary>
- /// <param name="cuiInfo"></param>
- public void ReSetCurvedUIInfo(CurvedUIInfo cuiInfo)
- {
- _curvedUIInfo = cuiInfo;
- SetCurrentCurvedUIState();
- }
- }
|