74 lines
1.7 KiB
C#
74 lines
1.7 KiB
C#
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
|
|
namespace AlicizaX.AnimationFlow.Runtime
|
|
{
|
|
[Category("Animation")]
|
|
[System.Serializable]
|
|
public class TranslateTo : ActionNode
|
|
{
|
|
[LabelText("持续时间")] public float duration = 1f;
|
|
[LabelText("过渡类型")] public EaseType easyType;
|
|
|
|
[ChildGameObjectsOnly] [LabelText("对象")]
|
|
public Transform target;
|
|
|
|
[LabelText("设置起点")] public bool setFrom;
|
|
|
|
[LabelText("开始")] [ShowIf("setFrom", true)]
|
|
public Vector3 from;
|
|
|
|
[LabelText("结束")] public Vector3 to;
|
|
|
|
protected Vector3 orgValue;
|
|
protected Vector3 enterValue;
|
|
|
|
public override void OnInit()
|
|
{
|
|
orgValue = target.localPosition;
|
|
}
|
|
|
|
|
|
public override void OnReset()
|
|
{
|
|
target.localPosition = orgValue;
|
|
}
|
|
|
|
public override void OnEnter()
|
|
{
|
|
if (setFrom)
|
|
{
|
|
target.localPosition = from;
|
|
}
|
|
|
|
enterValue = target.localPosition;
|
|
}
|
|
|
|
public override void OnUpdate(float dt)
|
|
{
|
|
target.localPosition = Easing.Ease(easyType, enterValue, to, elapsedTime / duration);
|
|
}
|
|
|
|
public override bool Valid()
|
|
{
|
|
Debug.Log(target != null && duration > 0);
|
|
return target != null && duration > 0;
|
|
}
|
|
|
|
public override float Duration()
|
|
{
|
|
return duration;
|
|
}
|
|
|
|
public override bool HasSubTitle()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public override string SubTitle()
|
|
{
|
|
return target != null ? target.name : null;
|
|
}
|
|
}
|
|
}
|