Files
Cielonos/Assets/Opsive/BehaviorDesigner/Add-Ons/CielonosPack/Actions/FuncAnim/SetFuncAnimSpeed.cs
SoulliesOfficial 9a9e48f8a5
2026-06-27 12:52:03 -04:00

61 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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";
}
}
}