129 lines
4.2 KiB
C#
129 lines
4.2 KiB
C#
using Games.LogicObj;
|
||
using GCGame.Table;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using UnityEngine.Events;
|
||
|
||
public class DamageBoard : WorldUIItem
|
||
{
|
||
private static readonly int _defaultMotionId = Animator.StringToHash("DamageBoard"); //默认动画名称
|
||
private float _startTime;
|
||
public Tab_DamageBoardType data;
|
||
private Vector3 _worldPosition;
|
||
|
||
public override WorldUIRoot.WorldUiItemType itemType
|
||
{
|
||
get { return WorldUIRoot.WorldUiItemType.DamageBoard; }
|
||
}
|
||
|
||
public Animator m_animator;
|
||
public Animator m_animator1;
|
||
public Text m_DamageBoardLabel; //字体
|
||
public UIImgText m_ImgText;
|
||
private UnityAction _updateFunc;
|
||
|
||
public override float pixelWidth
|
||
{
|
||
get { return m_DamageBoardLabel.rectTransform.sizeDelta.x; }
|
||
}
|
||
|
||
public static UIPathData PathData
|
||
{
|
||
get { return UIInfo.DamageBoard; }
|
||
}
|
||
|
||
public override UIPathData uiPathData
|
||
{
|
||
get { return PathData; }
|
||
}
|
||
|
||
public override Vector3 worldPosition
|
||
{
|
||
get { return _worldPosition; }
|
||
}
|
||
|
||
//在创建或者复用完成后,调用该接口,显示伤害信息
|
||
public bool ActiveDamageBoard(Tab_DamageBoardType tableData, string strValue, Vector3 worldPos, bool isProfessionSkill = true)
|
||
{
|
||
var result = true;
|
||
data = tableData;
|
||
// 读取该类型的表格项
|
||
// 初始位置 初速度 加速度
|
||
if (tableData.FontName != null && tableData.FontName.Length >= 3)
|
||
{
|
||
m_DamageBoardLabel.gameObject.SetActive(false);
|
||
m_ImgText.gameObject.SetActive(true);
|
||
m_ImgText.transform.localScale = Vector3.one * tableData.MaxSize;
|
||
m_ImgText._ImgFont = DamageBoardManager.damageBoardManager.GetImgFont(tableData.DamageBoardTypeID);
|
||
if (m_ImgText._ImgFont != null)
|
||
{
|
||
m_ImgText.text = strValue;
|
||
m_ImgText.SetCharRootAlig(TextAnchor.MiddleCenter);
|
||
}
|
||
else
|
||
{
|
||
m_ImgText.gameObject.SetActive(false);
|
||
result = false;
|
||
}
|
||
_updateFunc = ScaleImgText;
|
||
}
|
||
else
|
||
{
|
||
m_ImgText.gameObject.SetActive(false);
|
||
m_DamageBoardLabel.gameObject.SetActive(true);
|
||
m_DamageBoardLabel.text = strValue;
|
||
_updateFunc = Dummy;
|
||
}
|
||
if (result)
|
||
{
|
||
// 最后设置位置 大小
|
||
//Add by Lijia,伤害数字高度统一进行2.0的修正,如果以后发现有非2.0的情况,可以找我协商
|
||
_worldPosition = Vector3.up * 2.0f + worldPos;
|
||
transform.localScale = Vector3.one;
|
||
_startTime = Time.time;
|
||
if (tableData.FontName != null && tableData.FontName.Length >= 3)
|
||
{
|
||
var motionName =
|
||
DamageBoardManager.damageBoardManager.GetTypeShowIndex(tableData.DamageBoardTypeID, tableData);
|
||
if (string.IsNullOrEmpty(motionName))
|
||
m_animator1.Play(_defaultMotionId);
|
||
else
|
||
m_animator1.Play(motionName);
|
||
}
|
||
else
|
||
{
|
||
var motionName =
|
||
DamageBoardManager.damageBoardManager.GetTypeShowIndex(tableData.DamageBoardTypeID, tableData);
|
||
if (string.IsNullOrEmpty(motionName))
|
||
m_animator.Play(_defaultMotionId);
|
||
else
|
||
m_animator.Play(motionName);
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
|
||
public override bool CheckDuration()
|
||
{
|
||
var result = Time.time < _startTime + data.ShowTime;
|
||
if (result && _updateFunc != null)
|
||
_updateFunc();
|
||
return result;
|
||
}
|
||
|
||
private void Dummy()
|
||
{
|
||
m_DamageBoardLabel.transform.localScale = Vector3.one * Mathf.Lerp(data.MinSize, data.MaxSize, (Time.time - _startTime) / data.ShowTime);
|
||
}
|
||
|
||
private void ScaleImgText()
|
||
{
|
||
m_ImgText.transform.localScale = Vector3.one * Mathf.Lerp(data.MinSize, data.MaxSize, (Time.time - _startTime) / data.ShowTime);
|
||
}
|
||
|
||
private void OnDisable()
|
||
{
|
||
data = null;
|
||
_updateFunc = null;
|
||
}
|
||
} |