61 lines
2.1 KiB
C#
61 lines
2.1 KiB
C#
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||
using Opsive.GraphDesigner.Runtime;
|
||
using Opsive.GraphDesigner.Runtime.Variables;
|
||
using Opsive.Shared.Utility;
|
||
using Sirenix.OdinInspector;
|
||
using UnityEngine;
|
||
|
||
namespace Cielonos.MainGame.Characters.AI
|
||
{
|
||
[Description("设置动作播放速度。可用于立即调节当前动画速度,或将速度写入行为树变量以供后续 Payload 获取。")]
|
||
[NodeIcon("Assets/Sprites/Icon/Play.png")]
|
||
[Category("Cielonos")]
|
||
public class SetFuncAnimSpeed : AutomataActionBase
|
||
{
|
||
[Tooltip("是否立即改变当前动作播放器的速度?\n若为 false,则将速度存入行为树变量,由后面的 FuncAnimPayload 驱动。")]
|
||
public bool immediateSet = false;
|
||
|
||
[Tooltip("需要设置的目标播放速度。")]
|
||
public SharedVariable<float> speed = 1f;
|
||
|
||
[Tooltip("如果不是立即设置,保存到哪个行为树共享变量名中?")]
|
||
[HideIf("immediateSet")]
|
||
public string variableName = "FuncAnimSpeed";
|
||
|
||
public override TaskStatus OnUpdate()
|
||
{
|
||
float speedVal = speed != null ? speed.Value : 1f;
|
||
|
||
if (immediateSet)
|
||
{
|
||
var funcAnimSm = self.animationSc?.fullBodyFuncAnimSm;
|
||
if (funcAnimSm != null && funcAnimSm.IsPlaying)
|
||
{
|
||
funcAnimSm.currentPlaySpeedMultiplier = speedVal;
|
||
try
|
||
{
|
||
float overrideSpeed = funcAnimSm.currentData.animInfo.overridePlaySpeed;
|
||
funcAnimSm.Animator.SetFloat("ActionSpeed", overrideSpeed * speedVal);
|
||
}
|
||
catch { }
|
||
}
|
||
}
|
||
else
|
||
{
|
||
mainBehaviorTree.SetVariableValue(variableName, speedVal);
|
||
}
|
||
|
||
return TaskStatus.Success;
|
||
}
|
||
|
||
public override void Reset()
|
||
{
|
||
self = null;
|
||
immediateSet = false;
|
||
speed = 1f;
|
||
variableName = "FuncAnimSpeed";
|
||
}
|
||
}
|
||
}
|