102 lines
2.6 KiB
C#
102 lines
2.6 KiB
C#
using Games.LogicObj;
|
||
using Games.Scene;
|
||
using GCGame.Table;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
/// <summary>
|
||
/// 通用显示在WorldUiRoot层的小文字
|
||
/// </summary>
|
||
public class AnchoredText : WorldUIItem
|
||
{
|
||
private WorldUIRoot.AnchoredTextData _data;
|
||
|
||
private bool _objExist;
|
||
private float _height;
|
||
|
||
private Text _text;
|
||
private Vector3 _worldPosition;
|
||
|
||
public override WorldUIRoot.WorldUiItemType itemType
|
||
{
|
||
get { return WorldUIRoot.WorldUiItemType.AnchorText; }
|
||
}
|
||
|
||
public static UIPathData PathData
|
||
{
|
||
get { return UIInfo.AnchoredText; }
|
||
}
|
||
|
||
public override UIPathData uiPathData
|
||
{
|
||
get { return PathData; }
|
||
}
|
||
|
||
// 在世界坐标系的位置
|
||
public override Vector3 worldPosition
|
||
{
|
||
get { return _worldPosition; }
|
||
}
|
||
|
||
// 在Ui坐标系下尺寸;认为Ui坐标系尺寸单位为标准像素尺寸
|
||
public override float pixelWidth
|
||
{
|
||
get { return rectTransform.rect.width; }
|
||
}
|
||
|
||
public override bool CheckDuration()
|
||
{
|
||
var result = Time.unscaledTime < _data.endTime;
|
||
if (result)
|
||
_text.text = Mathf.FloorToInt(_data.endTime - Time.unscaledTime).ToString();
|
||
return result;
|
||
}
|
||
|
||
public override bool CheckPositionValid()
|
||
{
|
||
// Hack:这个位置是最早获得CameraPosUpdate的;
|
||
var obj = ObjManager.Instance.FindObjCharacterInScene(_data.objId);
|
||
if (obj != null && obj.BaseAttr != null && obj.BaseAttr.RoleData != null)
|
||
{
|
||
if (!_objExist)
|
||
{
|
||
var charModel = TableManager.GetCharModelByID(obj.BaseAttr.RoleData.CharModelID, 0);
|
||
if (charModel != null)
|
||
{
|
||
_height = charModel == null ? 0f : charModel.HeadInfoHeight;
|
||
_objExist = true;
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
else
|
||
_objExist = false;
|
||
if (_objExist)
|
||
{
|
||
_text.enabled = true;
|
||
_worldPosition = obj.Position;
|
||
_worldPosition += new Vector3(0f, _height);
|
||
}
|
||
else
|
||
_text.enabled = false;
|
||
return true;
|
||
}
|
||
|
||
public void SetInitData(WorldUIRoot.AnchoredTextData data)
|
||
{
|
||
_data = data;
|
||
_objExist = false;
|
||
}
|
||
|
||
protected override void Awake()
|
||
{
|
||
base.Awake();
|
||
_text = rectTransform.GetComponent<Text>();
|
||
}
|
||
|
||
public override void SetPositionAndScale(Vector3 position, float scale)
|
||
{
|
||
base.SetPositionAndScale(position + Vector3.up * 40f, scale);
|
||
}
|
||
} |