[AI] Behavior Actions 시스템 추가
Ultraworked with [Sisyphus](https://github.com/code-yeonggu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using Unity.Behavior;
|
||||
using UnityEngine;
|
||||
using Action = Unity.Behavior.Action;
|
||||
using Unity.Properties;
|
||||
|
||||
[Serializable, GeneratePropertyBag]
|
||||
[NodeDescription(name: "PlayAnimation", story: "[애니메이션] 재생", category: "Action", id: "b558ee0df6e00cd2e6bb2273b4f59cd2")]
|
||||
public partial class PlayAnimationAction : Action
|
||||
{
|
||||
[SerializeReference]
|
||||
public BlackboardVariable<string> AnimationName = new BlackboardVariable<string>("");
|
||||
|
||||
[SerializeReference]
|
||||
public BlackboardVariable<bool> WaitForCompletion = new BlackboardVariable<bool>(true);
|
||||
|
||||
private Animator animator;
|
||||
private bool animationStarted;
|
||||
|
||||
protected override Status OnStart()
|
||||
{
|
||||
animator = GameObject.GetComponentInChildren<Animator>();
|
||||
|
||||
if (animator == null || string.IsNullOrEmpty(AnimationName.Value))
|
||||
{
|
||||
return Status.Failure;
|
||||
}
|
||||
|
||||
animator.Play(AnimationName.Value);
|
||||
animationStarted = true;
|
||||
|
||||
if (!WaitForCompletion.Value)
|
||||
{
|
||||
return Status.Success;
|
||||
}
|
||||
|
||||
return Status.Running;
|
||||
}
|
||||
|
||||
protected override Status OnUpdate()
|
||||
{
|
||||
if (!WaitForCompletion.Value)
|
||||
{
|
||||
return Status.Success;
|
||||
}
|
||||
|
||||
if (animator == null)
|
||||
{
|
||||
return Status.Failure;
|
||||
}
|
||||
|
||||
var stateInfo = animator.GetCurrentAnimatorStateInfo(0);
|
||||
|
||||
// 애니메이션이 완료되었는지 확인
|
||||
if (stateInfo.IsName(AnimationName.Value) && stateInfo.normalizedTime >= 1f)
|
||||
{
|
||||
return Status.Success;
|
||||
}
|
||||
|
||||
return Status.Running;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user