[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:
8
Assets/Scripts/AI/BehaviorActions/Actions.meta
Normal file
8
Assets/Scripts/AI/BehaviorActions/Actions.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 09f6a44dd1b90c348a0dfb17312c5804
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using Unity.Behavior;
|
||||
using UnityEngine;
|
||||
using Action = Unity.Behavior.Action;
|
||||
using Unity.Properties;
|
||||
|
||||
[Serializable, GeneratePropertyBag]
|
||||
[NodeDescription(name: "ChaseTarget", story: "타겟 추적", category: "Action", id: "0889fbb015b8bf414ef569af08bb6868")]
|
||||
public partial class ChaseTargetAction : Action
|
||||
{
|
||||
|
||||
[SerializeReference]
|
||||
public BlackboardVariable<GameObject> Target;
|
||||
|
||||
[SerializeReference]
|
||||
public BlackboardVariable<float> Speed = new BlackboardVariable<float>(0f);
|
||||
|
||||
[SerializeReference]
|
||||
public BlackboardVariable<float> StopDistance = new BlackboardVariable<float>(2f);
|
||||
|
||||
private UnityEngine.AI.NavMeshAgent agent;
|
||||
|
||||
protected override Status OnStart()
|
||||
{
|
||||
if (Target.Value == null)
|
||||
{
|
||||
return Status.Failure;
|
||||
}
|
||||
|
||||
agent = GameObject.GetComponent<UnityEngine.AI.NavMeshAgent>();
|
||||
if (agent == null)
|
||||
{
|
||||
Debug.LogWarning("[ChaseTarget] NavMeshAgent not found");
|
||||
return Status.Failure;
|
||||
}
|
||||
|
||||
// Speed가 0 이하면 NavMeshAgent의 기존 speed 유지 (EnemyData에서 설정한 값)
|
||||
if (Speed.Value > 0f)
|
||||
{
|
||||
agent.speed = Speed.Value;
|
||||
}
|
||||
agent.stoppingDistance = StopDistance.Value;
|
||||
agent.isStopped = false;
|
||||
|
||||
return Status.Running;
|
||||
}
|
||||
|
||||
protected override Status OnUpdate()
|
||||
{
|
||||
if (Target.Value == null)
|
||||
{
|
||||
return Status.Failure;
|
||||
}
|
||||
|
||||
// 이미 사거리 내에 있으면 성공
|
||||
float distance = Vector3.Distance(GameObject.transform.position, Target.Value.transform.position);
|
||||
if (distance <= StopDistance.Value)
|
||||
{
|
||||
agent.isStopped = true;
|
||||
return Status.Success;
|
||||
}
|
||||
|
||||
// 타겟 위치로 이동
|
||||
agent.SetDestination(Target.Value.transform.position);
|
||||
return Status.Running;
|
||||
}
|
||||
|
||||
protected override void OnEnd()
|
||||
{
|
||||
if (agent != null)
|
||||
{
|
||||
agent.isStopped = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14296786101ccd742ac9f752f1fd3393
|
||||
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using Unity.Behavior;
|
||||
using UnityEngine;
|
||||
using Action = Unity.Behavior.Action;
|
||||
using Unity.Properties;
|
||||
|
||||
[Serializable, GeneratePropertyBag]
|
||||
[NodeDescription(name: "FindTarget", story: "[타겟] 탐색", category: "Action", id: "bb947540549026f3c5625c6d19213311")]
|
||||
public partial class FindTargetAction : Action
|
||||
{
|
||||
[SerializeReference]
|
||||
public BlackboardVariable<GameObject> Target;
|
||||
|
||||
[SerializeReference]
|
||||
public BlackboardVariable<string> Tag = new BlackboardVariable<string>("Player");
|
||||
|
||||
protected override Status OnStart()
|
||||
{
|
||||
if (Tag.Value == null || string.IsNullOrEmpty(Tag.Value))
|
||||
{
|
||||
return Status.Failure;
|
||||
}
|
||||
|
||||
GameObject foundTarget = GameObject.FindGameObjectWithTag(Tag.Value);
|
||||
|
||||
if (foundTarget == null)
|
||||
{
|
||||
return Status.Failure;
|
||||
}
|
||||
|
||||
Target.Value = foundTarget;
|
||||
return Status.Success;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f569cb803bceb7c4291d0f3074346741
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3bc57afe07d75aa4e80ef5394b57f774
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using Unity.Behavior;
|
||||
using UnityEngine;
|
||||
using Action = Unity.Behavior.Action;
|
||||
using Unity.Properties;
|
||||
|
||||
[Serializable, GeneratePropertyBag]
|
||||
[NodeDescription(name: "RotateToTarget", story: "[대상을] 바라보도록 회전", category: "Action", id: "30341f7e1af0565c0aca0253341b3e28")]
|
||||
public partial class RotateToTargetAction : Action
|
||||
{
|
||||
[SerializeReference]
|
||||
public BlackboardVariable<GameObject> Target;
|
||||
|
||||
[SerializeReference]
|
||||
public BlackboardVariable<float> RotationSpeed = new BlackboardVariable<float>(10f);
|
||||
|
||||
[SerializeReference]
|
||||
public BlackboardVariable<float> AngleThreshold = new BlackboardVariable<float>(5f);
|
||||
|
||||
protected override Status OnUpdate()
|
||||
{
|
||||
if (Target.Value == null)
|
||||
{
|
||||
return Status.Failure;
|
||||
}
|
||||
|
||||
Vector3 direction = Target.Value.transform.position - GameObject.transform.position;
|
||||
direction.y = 0f;
|
||||
|
||||
if (direction == Vector3.zero)
|
||||
{
|
||||
return Status.Success;
|
||||
}
|
||||
|
||||
Quaternion targetRotation = Quaternion.LookRotation(direction);
|
||||
float angleDifference = Quaternion.Angle(GameObject.transform.rotation, targetRotation);
|
||||
|
||||
// 임계값 이내면 성공
|
||||
if (angleDifference <= AngleThreshold.Value)
|
||||
{
|
||||
return Status.Success;
|
||||
}
|
||||
|
||||
// 부드럽게 회전
|
||||
GameObject.transform.rotation = Quaternion.Slerp(
|
||||
GameObject.transform.rotation,
|
||||
targetRotation,
|
||||
RotationSpeed.Value * Time.deltaTime
|
||||
);
|
||||
|
||||
return Status.Running;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33182146e0ade8443a539cf7780735e2
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using Unity.Behavior;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using Action = Unity.Behavior.Action;
|
||||
using Unity.Properties;
|
||||
|
||||
[Serializable, GeneratePropertyBag]
|
||||
[NodeDescription(name: "SetAnimatorTrigger", story: "애니메이션 [트리거] 설정", category: "Action", id: "bfef104cbd43df3d01f24570a4caa8ed")]
|
||||
public partial class SetAnimatorTriggerAction : Action
|
||||
{
|
||||
[SerializeReference]
|
||||
public BlackboardVariable<string> TriggerName = new BlackboardVariable<string>("");
|
||||
|
||||
protected override Status OnStart()
|
||||
{
|
||||
if (string.IsNullOrEmpty(TriggerName.Value))
|
||||
{
|
||||
return Status.Failure;
|
||||
}
|
||||
|
||||
Animator animator = GameObject.GetComponentInChildren<Animator>();
|
||||
|
||||
if (animator == null)
|
||||
{
|
||||
return Status.Failure;
|
||||
}
|
||||
|
||||
animator.SetTrigger(TriggerName.Value);
|
||||
return Status.Success;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 77cf4f2ff35fe3040af16374f428a648
|
||||
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using Unity.Behavior;
|
||||
using UnityEngine;
|
||||
using Action = Unity.Behavior.Action;
|
||||
using Unity.Properties;
|
||||
|
||||
[Serializable, GeneratePropertyBag]
|
||||
[NodeDescription(name: "SetTargetInRange", story: "[거리] 내에 [대상이] 있는지 확인", category: "Action", id: "93b7a5d823a58618d5371c01ef894948")]
|
||||
public partial class SetTargetInRangeAction : Action
|
||||
{
|
||||
[SerializeReference]
|
||||
public BlackboardVariable<GameObject> Target;
|
||||
|
||||
[SerializeReference]
|
||||
public BlackboardVariable<string> Tag = new BlackboardVariable<string>("Player");
|
||||
|
||||
[SerializeReference]
|
||||
public BlackboardVariable<float> Range = new BlackboardVariable<float>(10f);
|
||||
|
||||
protected override Status OnStart()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Tag.Value))
|
||||
{
|
||||
return Status.Failure;
|
||||
}
|
||||
|
||||
// 모든 타겟 태그 오브젝트 찾기
|
||||
GameObject[] targets = GameObject.FindGameObjectsWithTag(Tag.Value);
|
||||
|
||||
if (targets == null || targets.Length == 0)
|
||||
{
|
||||
return Status.Failure;
|
||||
}
|
||||
|
||||
// 가장 가까운 타겟 찾기
|
||||
GameObject nearestTarget = null;
|
||||
float nearestDistance = Range.Value; // Range 내에서만 검색
|
||||
|
||||
foreach (GameObject potentialTarget in targets)
|
||||
{
|
||||
float distance = Vector3.Distance(
|
||||
GameObject.transform.position,
|
||||
potentialTarget.transform.position
|
||||
);
|
||||
|
||||
if (distance < nearestDistance)
|
||||
{
|
||||
nearestDistance = distance;
|
||||
nearestTarget = potentialTarget;
|
||||
}
|
||||
}
|
||||
|
||||
if (nearestTarget == null)
|
||||
{
|
||||
return Status.Failure;
|
||||
}
|
||||
|
||||
Target.Value = nearestTarget;
|
||||
return Status.Success;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 02cd3ab41f67bf344b667b6a0c12a4d0
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using Unity.Behavior;
|
||||
using UnityEngine;
|
||||
using Action = Unity.Behavior.Action;
|
||||
using Unity.Properties;
|
||||
|
||||
[Serializable, GeneratePropertyBag]
|
||||
[NodeDescription(name: "StopMovement", story: "이동 정지", category: "Action", id: "1a0e2eb87421ed94502031790df56f37")]
|
||||
public partial class StopMovementAction : Action
|
||||
{
|
||||
|
||||
protected override Status OnStart()
|
||||
{
|
||||
UnityEngine.AI.NavMeshAgent agent = GameObject.GetComponent<UnityEngine.AI.NavMeshAgent>();
|
||||
|
||||
if (agent != null)
|
||||
{
|
||||
agent.isStopped = true;
|
||||
}
|
||||
|
||||
return Status.Success;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: afacb51ec60675d498bfc8b7ce942368
|
||||
31
Assets/Scripts/AI/BehaviorActions/Actions/WaitAction.cs
Normal file
31
Assets/Scripts/AI/BehaviorActions/Actions/WaitAction.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using Unity.Behavior;
|
||||
using UnityEngine;
|
||||
using Action = Unity.Behavior.Action;
|
||||
using Unity.Properties;
|
||||
|
||||
[Serializable, GeneratePropertyBag]
|
||||
[NodeDescription(name: "Wait", story: "대기", category: "Action", id: "73b84bd4bc0eb61c998ac84c9853a69d")]
|
||||
public partial class WaitAction : Action
|
||||
{
|
||||
[SerializeReference]
|
||||
public BlackboardVariable<float> Duration = new BlackboardVariable<float>(1f);
|
||||
|
||||
private float startTime;
|
||||
|
||||
protected override Status OnStart()
|
||||
{
|
||||
startTime = Time.time;
|
||||
return Status.Running;
|
||||
}
|
||||
|
||||
protected override Status OnUpdate()
|
||||
{
|
||||
if (Time.time - startTime >= Duration.Value)
|
||||
{
|
||||
return Status.Success;
|
||||
}
|
||||
return Status.Running;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 324b69471491c9448ae5d71a426dd596
|
||||
8
Assets/Scripts/AI/BehaviorActions/Conditions.meta
Normal file
8
Assets/Scripts/AI/BehaviorActions/Conditions.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 422be729ebdf10b43b44b80b8593258a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Unity.Behavior;
|
||||
using Unity.Properties;
|
||||
using Condition = Unity.Behavior.Condition;
|
||||
|
||||
namespace Colosseum.AI.BehaviorActions.Conditions
|
||||
{
|
||||
/// <summary>
|
||||
/// 타겟이 존재하는지 확인합니다.
|
||||
/// </summary>
|
||||
[Serializable, GeneratePropertyBag]
|
||||
[NodeDescription(name: "Has Target", story: "Has [Target]", category: "Combat")]
|
||||
public partial class HasTargetCondition : Condition
|
||||
{
|
||||
[SerializeReference]
|
||||
public BlackboardVariable<GameObject> Target;
|
||||
|
||||
public override bool IsTrue()
|
||||
{
|
||||
return Target.Value != null && Target.Value.activeInHierarchy;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5aba729f8b5ddea468304d6b1bf43dce
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Unity.Behavior;
|
||||
using Unity.Properties;
|
||||
using Condition = Unity.Behavior.Condition;
|
||||
using Colosseum.Enemy;
|
||||
|
||||
namespace Colosseum.AI.BehaviorActions.Conditions
|
||||
{
|
||||
/// <summary>
|
||||
/// 체력이 지정된 비율 이하인지 확인합니다.
|
||||
/// </summary>
|
||||
[Serializable, GeneratePropertyBag]
|
||||
[NodeDescription(name: "Is Health Below", story: "Check if health is below [HealthPercent] percent", category: "Combat")]
|
||||
public partial class IsHealthBelowCondition : Condition
|
||||
{
|
||||
[SerializeReference]
|
||||
public BlackboardVariable<float> HealthPercent = new BlackboardVariable<float>(50f);
|
||||
|
||||
public override bool IsTrue()
|
||||
{
|
||||
EnemyBase enemy = GameObject.GetComponent<EnemyBase>();
|
||||
|
||||
if (enemy == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
float currentHealthPercent = (enemy.CurrentHealth / enemy.MaxHealth) * 100f;
|
||||
return currentHealthPercent <= HealthPercent.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e03ad43d6a068dd44bef3d524d20a4c1
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Unity.Behavior;
|
||||
using Unity.Properties;
|
||||
using Condition = Unity.Behavior.Condition;
|
||||
|
||||
namespace Colosseum.AI.BehaviorActions.Conditions
|
||||
{
|
||||
/// <summary>
|
||||
/// 타겟이 공격 사거리 내에 있는지 확인합니다.
|
||||
/// </summary>
|
||||
[Serializable, GeneratePropertyBag]
|
||||
[NodeDescription(name: "Is In Attack Range", story: "Is [Target] within [Range]", category: "Combat")]
|
||||
public partial class IsInAttackRangeCondition : Condition
|
||||
{
|
||||
[SerializeReference]
|
||||
public BlackboardVariable<GameObject> Target;
|
||||
|
||||
[SerializeReference]
|
||||
public BlackboardVariable<float> Range = new BlackboardVariable<float>(2f);
|
||||
|
||||
public override bool IsTrue()
|
||||
{
|
||||
if (Target.Value == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
float distance = Vector3.Distance(
|
||||
GameObject.transform.position,
|
||||
Target.Value.transform.position
|
||||
);
|
||||
|
||||
return distance <= Range.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 10007872b79b2b641980c0d8dfd4f6a4
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Unity.Behavior;
|
||||
using Unity.Properties;
|
||||
using Condition = Unity.Behavior.Condition;
|
||||
|
||||
namespace Colosseum.AI.BehaviorActions.Conditions
|
||||
{
|
||||
/// <summary>
|
||||
/// 타겟이 지정된 거리 내에 있는지 확인합니다.
|
||||
/// </summary>
|
||||
[Serializable, GeneratePropertyBag]
|
||||
[NodeDescription(name: "Is In Range", story: "Is [Target] within [Range] distance", category: "Combat")]
|
||||
public partial class IsInRangeCondition : Condition
|
||||
{
|
||||
[SerializeReference]
|
||||
public BlackboardVariable<GameObject> Target;
|
||||
|
||||
[SerializeReference]
|
||||
public BlackboardVariable<float> Range = new BlackboardVariable<float>(2f);
|
||||
|
||||
public override bool IsTrue()
|
||||
{
|
||||
if (Target.Value == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
float distance = Vector3.Distance(GameObject.transform.position, Target.Value.transform.position);
|
||||
return distance <= Range.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0035b82da5a602d44b552684970273a8
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Unity.Behavior;
|
||||
using Unity.Properties;
|
||||
using Condition = Unity.Behavior.Condition;
|
||||
|
||||
namespace Colosseum.AI.BehaviorActions.Conditions
|
||||
{
|
||||
/// <summary>
|
||||
/// 무작위 확률로 성공/실패를 반환합니다.
|
||||
/// </summary>
|
||||
[Serializable, GeneratePropertyBag]
|
||||
[NodeDescription(name: "Random Chance", story: "Random chance of [Chance] percent", category: "Utility")]
|
||||
public partial class RandomChanceCondition : Condition
|
||||
{
|
||||
[SerializeReference]
|
||||
public BlackboardVariable<float> Chance = new BlackboardVariable<float>(50f);
|
||||
|
||||
public override bool IsTrue()
|
||||
{
|
||||
float roll = UnityEngine.Random.Range(0f, 100f);
|
||||
return roll <= Chance.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3abe3d08ab4653b43a5a1708770fd3a1
|
||||
Reference in New Issue
Block a user