59 lines
1.8 KiB
C#
59 lines
1.8 KiB
C#
|
using Games.LogicObj;
|
|||
|
using UnityEngine;
|
|||
|
/// <summary>
|
|||
|
/// 世界UI面板物体的基类
|
|||
|
/// </summary>
|
|||
|
// 统一由WorldUiRoot监听主摄像机移动事件,然后更新位置和尺寸
|
|||
|
public abstract class WorldUIItem : MonoBehaviour
|
|||
|
{
|
|||
|
// 标志物品类型
|
|||
|
public abstract WorldUIRoot.WorldUiItemType itemType { get; }
|
|||
|
// 代替typeof(T)的枚举数值
|
|||
|
public abstract UIPathData uiPathData { get; }
|
|||
|
// 是否根据世界位置进行缩放
|
|||
|
public virtual bool scaleByWorldPos
|
|||
|
{
|
|||
|
get { return true; }
|
|||
|
}
|
|||
|
// 在世界坐标系的位置
|
|||
|
public abstract Vector3 worldPosition { get; }
|
|||
|
// 在Ui坐标系下尺寸;认为Ui坐标系尺寸单位为标准像素尺寸
|
|||
|
public abstract float pixelWidth { get; }
|
|||
|
|
|||
|
public RectTransform rectTransform { get; private set; }
|
|||
|
|
|||
|
protected virtual void Awake()
|
|||
|
{
|
|||
|
rectTransform = (RectTransform)transform;
|
|||
|
}
|
|||
|
|
|||
|
public virtual bool CheckDuration()
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public virtual void BackToPool()
|
|||
|
{
|
|||
|
if (WorldUIRoot.Instance != null)
|
|||
|
WorldUIRoot.Instance.Recovery(uiPathData, this);
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 检查是否能够取得世界位置坐标
|
|||
|
/// </summary>
|
|||
|
// 注:之前代码有防御 名称面板 丢失绑定目标等错误情况,因此可以重载该函数来做错误判断;
|
|||
|
public virtual bool CheckPositionValid()
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public virtual void SetPositionAndScale(Vector3 position, float scale)
|
|||
|
{
|
|||
|
// 正确的遮挡关系
|
|||
|
if (rectTransform == null)
|
|||
|
{
|
|||
|
rectTransform = gameObject.GetComponent<RectTransform>();
|
|||
|
}
|
|||
|
rectTransform.anchoredPosition3D = position;
|
|||
|
rectTransform.localScale = Vector3.one * scale;
|
|||
|
}
|
|||
|
}
|