2026-03-20 12:07:44 -04:00
|
|
|
|
using System.Collections.Generic;
|
2025-11-25 08:19:33 -05:00
|
|
|
|
using Cielonos.MainGame.Characters;
|
|
|
|
|
|
using Cielonos.MainGame.FunctionalAnimation;
|
|
|
|
|
|
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 SLSUtilities.FunctionalAnimation;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
2025-12-08 05:27:53 -05:00
|
|
|
|
namespace Cielonos.MainGame.Characters.AI
|
2025-11-25 08:19:33 -05:00
|
|
|
|
{
|
|
|
|
|
|
[Description("让角色播放一个功能动画,播放过程中会检测打断情况。")]
|
|
|
|
|
|
[NodeIcon("Assets/Sprites/Icon/Play.png")]
|
|
|
|
|
|
[Category("Cielonos")]
|
2025-12-08 05:27:53 -05:00
|
|
|
|
public class PlayFuncAnim : AutomataActionBase
|
2025-11-25 08:19:33 -05:00
|
|
|
|
{
|
2025-12-08 05:27:53 -05:00
|
|
|
|
protected CharacterBase target;
|
2025-11-25 08:19:33 -05:00
|
|
|
|
[Tooltip("是否选择其他目标,默认目标为玩家。")]
|
|
|
|
|
|
public bool isOtherTarget = false;
|
|
|
|
|
|
[Tooltip("如果选择了其他目标,则需要指定目标对象。")]
|
|
|
|
|
|
public SharedVariable<GameObject> targetGameObject;
|
|
|
|
|
|
|
2025-12-08 05:27:53 -05:00
|
|
|
|
private AnimationSubcontrollerBase animationSc => self.animationSc;
|
|
|
|
|
|
private FunctionalAnimationSubmodule funcAnimSm;
|
|
|
|
|
|
private RuntimeFuncAnim funcAnim;
|
|
|
|
|
|
private float currentPlayTime => funcAnimSm.currentPlayTime;
|
2026-03-20 12:07:44 -04:00
|
|
|
|
private float currentTotalPlayTime => funcAnimSm.currentTotalPlayTime;
|
2025-12-08 05:27:53 -05:00
|
|
|
|
|
2025-11-25 08:19:33 -05:00
|
|
|
|
[Header("Animation Settings")]
|
|
|
|
|
|
[Tooltip("要播放的功能动画名称。")]
|
|
|
|
|
|
public string animationName;
|
|
|
|
|
|
[Tooltip("是否选择其他功能动画子模块,默认子模块为全身动作子模块。")]
|
|
|
|
|
|
public bool isOtherFuncAnimSm = false;
|
|
|
|
|
|
[Tooltip("如果选择了其他功能动画子模块,则需要指定子模块名称。")]
|
|
|
|
|
|
public string funcAnimSmName = "";
|
|
|
|
|
|
[Tooltip("动画过渡时间,单位秒。")]
|
|
|
|
|
|
public float transitionDuration = 0.1f;
|
|
|
|
|
|
[Tooltip("如果勾选此项,当动画被打断,返回Success(执行下一步),否则返回Failure(重新执行此步骤)。")]
|
|
|
|
|
|
public bool disruptionReturnSuccess = true;
|
2026-03-20 12:07:44 -04:00
|
|
|
|
[Tooltip("是否在开始播放动画时转向目标。")]
|
|
|
|
|
|
public bool willTurnToTargetAtStart = true;
|
|
|
|
|
|
[Tooltip("是否在播放过程中持续转向目标。")]
|
|
|
|
|
|
public bool willTurnToTargetDuringPlaying = false;
|
2025-11-25 08:19:33 -05:00
|
|
|
|
[Tooltip("是否调整根吸附以贴近目标。")]
|
|
|
|
|
|
public bool willAdjustAdsorption = true;
|
2026-03-20 12:07:44 -04:00
|
|
|
|
[Tooltip("是否持续调整根吸附以贴近目标,直到动画结束。")]
|
|
|
|
|
|
public bool willKeepAdjustingAdsorption = false;
|
2025-11-25 08:19:33 -05:00
|
|
|
|
[Tooltip("根吸附调整的最小距离。")]
|
|
|
|
|
|
public float adsorptionMinDistance = 2;
|
2025-12-08 05:27:53 -05:00
|
|
|
|
|
|
|
|
|
|
[Header("Other Settings")]
|
|
|
|
|
|
[Tooltip("是否记录此动作到动作记录子模块中。")]
|
|
|
|
|
|
public bool willRecordAction = true;
|
2025-11-25 08:19:33 -05:00
|
|
|
|
|
|
|
|
|
|
private bool successPlayed = false;
|
2026-03-20 12:07:44 -04:00
|
|
|
|
private bool frameBuffer;
|
2025-11-25 08:19:33 -05:00
|
|
|
|
|
|
|
|
|
|
public override void OnAwake()
|
|
|
|
|
|
{
|
2025-12-08 05:27:53 -05:00
|
|
|
|
base.OnAwake();
|
2025-11-25 08:19:33 -05:00
|
|
|
|
funcAnimSm = isOtherFuncAnimSm ? null : animationSc.fullBodyFuncAnimSm;
|
|
|
|
|
|
target = isOtherTarget ? targetGameObject.Value.GetComponent<CharacterBase>() : MainGameManager.Player;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnStart()
|
|
|
|
|
|
{
|
|
|
|
|
|
successPlayed = funcAnimSm.Play(animationName);
|
2026-03-20 12:07:44 -04:00
|
|
|
|
frameBuffer = false;
|
2025-11-25 08:19:33 -05:00
|
|
|
|
if (successPlayed)
|
|
|
|
|
|
{
|
2026-03-20 12:07:44 -04:00
|
|
|
|
funcAnim = funcAnimSm.currentRuntimeFuncAnim;
|
2025-11-25 08:19:33 -05:00
|
|
|
|
|
2026-03-20 12:07:44 -04:00
|
|
|
|
if (willTurnToTargetAtStart)
|
2025-11-25 08:19:33 -05:00
|
|
|
|
{
|
2026-04-28 15:46:32 -04:00
|
|
|
|
self.movementSc.SmartTurnToTarget(target);
|
2025-11-25 08:19:33 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (willAdjustAdsorption)
|
|
|
|
|
|
{
|
2026-03-20 12:07:44 -04:00
|
|
|
|
if (!willKeepAdjustingAdsorption)
|
|
|
|
|
|
{
|
|
|
|
|
|
funcAnim.AddUpdateUntilEvent(new SetRootAdsorptionAdjustment.Once(target, adsorptionMinDistance));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
funcAnim.AddUpdateEvent(new SetRootAdsorptionAdjustment.Keep(target, adsorptionMinDistance));
|
|
|
|
|
|
}
|
2025-11-25 08:19:33 -05:00
|
|
|
|
}
|
2026-03-20 12:07:44 -04:00
|
|
|
|
|
2025-12-08 05:27:53 -05:00
|
|
|
|
if (willRecordAction)
|
|
|
|
|
|
{
|
|
|
|
|
|
self.actionRecordSm.AddRecord(animationName);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-25 08:19:33 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override TaskStatus OnUpdate()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!successPlayed)
|
|
|
|
|
|
{
|
2026-03-20 12:07:44 -04:00
|
|
|
|
if (!frameBuffer)
|
2025-12-08 05:27:53 -05:00
|
|
|
|
{
|
2026-03-20 12:07:44 -04:00
|
|
|
|
frameBuffer = true;
|
2025-12-08 05:27:53 -05:00
|
|
|
|
return TaskStatus.Running;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return TaskStatus.Failure;
|
|
|
|
|
|
}
|
2025-11-25 08:19:33 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-20 12:07:44 -04:00
|
|
|
|
if (funcAnimSm.currentRuntimeFuncAnim == funcAnim && funcAnimSm.CheckDisruption(DisruptionType.NormalAction))
|
2025-11-25 08:19:33 -05:00
|
|
|
|
{
|
2026-03-20 12:07:44 -04:00
|
|
|
|
if (!frameBuffer)
|
|
|
|
|
|
{
|
|
|
|
|
|
frameBuffer = true;
|
|
|
|
|
|
return TaskStatus.Running;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2025-11-25 08:19:33 -05:00
|
|
|
|
{
|
|
|
|
|
|
return TaskStatus.Success;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (funcAnim.isDisrupted || funcAnimSm.currentRuntimeFuncAnim != funcAnim)
|
|
|
|
|
|
{
|
|
|
|
|
|
//if (self.isDuringGetHit) return TaskStatus.Running;
|
|
|
|
|
|
|
2026-03-20 12:07:44 -04:00
|
|
|
|
if (!frameBuffer)
|
|
|
|
|
|
{
|
|
|
|
|
|
frameBuffer = true;
|
|
|
|
|
|
return TaskStatus.Running;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return disruptionReturnSuccess ? TaskStatus.Success : TaskStatus.Failure;
|
|
|
|
|
|
}
|
2025-11-25 08:19:33 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-20 12:07:44 -04:00
|
|
|
|
if (willTurnToTargetDuringPlaying)
|
|
|
|
|
|
{
|
|
|
|
|
|
self.movementSc.TurnToTargetByAngle(target, 360f);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-25 08:19:33 -05:00
|
|
|
|
return TaskStatus.Running;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|