using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
///
/// 弧形曲面原型控制器
///
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();
if (_hightControllerRect != null)
_hightControllerRect = _uiCanvasRect.transform.Find("HeightController").GetComponent();
if (_widthControllerRect != null)
_widthControllerRect = _hightControllerRect.transform.Find("WidthController").GetComponent();
_arrows = _widthControllerRect.transform.Find("Arrows_Double").GetComponent();
_distanceText = _widthControllerRect.transform.Find("DistanceDescription_txt").GetComponent();
_descriptsText = _widthControllerRect.transform.Find("Description_txt").GetComponent();
_distanceRectTransform = _distanceText.transform.GetComponent();
_descriptsRectTransform = _descriptsText.transform.GetComponent();
_distanceText.gameObject.SetActive(false);
_arrows.gameObject.SetActive(false);
_descriptsText.gameObject.SetActive(false);
}
///
/// 设置当前CUIBase状态
///
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();
}
if (_descriptsRectTransform == null)
{
_descriptsRectTransform = _descriptsText.transform.GetComponent();
}
_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;
}
}
///
/// 设置当前展示信息状态
///
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;
}
}
///
/// 设置当前展示信息状态
///
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;
}
}
///
/// 重置CUIInfo
///
///
public void ReSetCurvedUIInfo(CurvedUIInfo cuiInfo)
{
_curvedUIInfo = cuiInfo;
SetCurrentCurvedUIState();
}
}