타임 리미터 제작, 그에 맞는 오더 서브트리 변경
This commit is contained in:
parent
447335ef20
commit
d911c1205d
BIN
Assets/_DDD/_Addressables/AI/Customer/Subtree/CustomerDefault.asset
(Stored with Git LFS)
BIN
Assets/_DDD/_Addressables/AI/Customer/Subtree/CustomerDefault.asset
(Stored with Git LFS)
Binary file not shown.
BIN
Assets/_DDD/_Addressables/AI/Customer/Subtree/OrderSubtree.asset
(Stored with Git LFS)
BIN
Assets/_DDD/_Addressables/AI/Customer/Subtree/OrderSubtree.asset
(Stored with Git LFS)
Binary file not shown.
@ -3,6 +3,7 @@
|
|||||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Decorators;
|
using Opsive.BehaviorDesigner.Runtime.Tasks.Decorators;
|
||||||
using Opsive.GraphDesigner.Runtime;
|
using Opsive.GraphDesigner.Runtime;
|
||||||
|
using Opsive.GraphDesigner.Runtime.Variables;
|
||||||
using Opsive.Shared.Utility;
|
using Opsive.Shared.Utility;
|
||||||
using Unity.Burst;
|
using Unity.Burst;
|
||||||
using Unity.Entities;
|
using Unity.Entities;
|
||||||
@ -140,7 +141,9 @@ public struct TimeLimiterComponent : IBufferElementData
|
|||||||
public TaskStatus TimeoutStatus;
|
public TaskStatus TimeoutStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct TimeLimiterTag : IComponentData, IEnableableComponent { }
|
public struct TimeLimiterTag : IComponentData, IEnableableComponent
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
[DisableAutoCreation]
|
[DisableAutoCreation]
|
||||||
public partial struct TimeLimiterTaskSystem : ISystem
|
public partial struct TimeLimiterTaskSystem : ISystem
|
||||||
@ -148,7 +151,8 @@ public partial struct TimeLimiterTaskSystem : ISystem
|
|||||||
[BurstCompile]
|
[BurstCompile]
|
||||||
private void OnUpdate(ref SystemState state)
|
private void OnUpdate(ref SystemState state)
|
||||||
{
|
{
|
||||||
var query = SystemAPI.QueryBuilder().WithAllRW<BranchComponent>().WithAllRW<TaskComponent>().WithAllRW<TimeLimiterComponent>().WithAll<TimeLimiterTag, EvaluationComponent>().Build();
|
var query = SystemAPI.QueryBuilder().WithAllRW<BranchComponent>().WithAllRW<TaskComponent>()
|
||||||
|
.WithAllRW<TimeLimiterComponent>().WithAll<TimeLimiterTag, EvaluationComponent>().Build();
|
||||||
state.Dependency = new TimeLimiterJob()
|
state.Dependency = new TimeLimiterJob()
|
||||||
{
|
{
|
||||||
CurrentTime = (float)SystemAPI.Time.ElapsedTime
|
CurrentTime = (float)SystemAPI.Time.ElapsedTime
|
||||||
@ -188,13 +192,15 @@ public void Execute(ref DynamicBuffer<BranchComponent> branchComponents,
|
|||||||
branchComponents[taskComponent.BranchIndex] = branchComponent;
|
branchComponents[taskComponent.BranchIndex] = branchComponent;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taskComponent.Status != TaskStatus.Running)
|
if (taskComponent.Status != TaskStatus.Running)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeLimiterComponent.StartTime >= 0f &&
|
if (timeLimiterComponent.StartTime >= 0f &&
|
||||||
CurrentTime - timeLimiterComponent.StartTime >= timeLimiterComponent.TimeLimit) {
|
CurrentTime - timeLimiterComponent.StartTime >= timeLimiterComponent.TimeLimit)
|
||||||
|
{
|
||||||
// 시간 초과
|
// 시간 초과
|
||||||
taskComponent.Status = timeLimiterComponent.TimeoutStatus;
|
taskComponent.Status = timeLimiterComponent.TimeoutStatus;
|
||||||
taskComponents[taskComponent.Index] = taskComponent;
|
taskComponents[taskComponent.Index] = taskComponent;
|
||||||
@ -202,7 +208,8 @@ public void Execute(ref DynamicBuffer<BranchComponent> branchComponents,
|
|||||||
// 자식 태스크가 실행 중이면 중단
|
// 자식 태스크가 실행 중이면 중단
|
||||||
childTaskComponent = taskComponents[taskComponent.Index + 1];
|
childTaskComponent = taskComponents[taskComponent.Index + 1];
|
||||||
if (childTaskComponent.Status == TaskStatus.Running ||
|
if (childTaskComponent.Status == TaskStatus.Running ||
|
||||||
childTaskComponent.Status == TaskStatus.Queued) {
|
childTaskComponent.Status == TaskStatus.Queued)
|
||||||
|
{
|
||||||
childTaskComponent.Status = timeLimiterComponent.TimeoutStatus;
|
childTaskComponent.Status = timeLimiterComponent.TimeoutStatus;
|
||||||
taskComponents[taskComponent.Index + 1] = childTaskComponent;
|
taskComponents[taskComponent.Index + 1] = childTaskComponent;
|
||||||
}
|
}
|
||||||
@ -214,7 +221,8 @@ public void Execute(ref DynamicBuffer<BranchComponent> branchComponents,
|
|||||||
|
|
||||||
childTaskComponent = taskComponents[taskComponent.Index + 1];
|
childTaskComponent = taskComponents[taskComponent.Index + 1];
|
||||||
if (childTaskComponent.Status == TaskStatus.Queued ||
|
if (childTaskComponent.Status == TaskStatus.Queued ||
|
||||||
childTaskComponent.Status == TaskStatus.Running) {
|
childTaskComponent.Status == TaskStatus.Running)
|
||||||
|
{
|
||||||
// The child should keep running.
|
// The child should keep running.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -228,4 +236,90 @@ public void Execute(ref DynamicBuffer<BranchComponent> branchComponents,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[NodeDescription("자식 태스크의 실행 시간을 제한합니다 (GameObject 워크플로우)")]
|
||||||
|
public class SharedTimeLimiter : DecoratorNode
|
||||||
|
{
|
||||||
|
[Tooltip("최대 실행 시간(초)")]
|
||||||
|
[SerializeField] private SharedVariable<float> m_TimeLimit = 30f;
|
||||||
|
|
||||||
|
[Tooltip("시간 초과 시 반환할 상태")]
|
||||||
|
[SerializeField] private TaskStatus m_TimeoutStatus = TaskStatus.Failure;
|
||||||
|
|
||||||
|
public SharedVariable<float> TimeLimit
|
||||||
|
{
|
||||||
|
get => m_TimeLimit;
|
||||||
|
set => m_TimeLimit = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TaskStatus TimeoutStatus
|
||||||
|
{
|
||||||
|
get => m_TimeoutStatus;
|
||||||
|
set => m_TimeoutStatus = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private float m_StartTime;
|
||||||
|
private float m_PauseTime = -1f;
|
||||||
|
|
||||||
|
public override void OnStart()
|
||||||
|
{
|
||||||
|
base.OnStart();
|
||||||
|
m_StartTime = Time.time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override TaskStatus OnUpdate()
|
||||||
|
{
|
||||||
|
var taskComponents = m_BehaviorTree.World.EntityManager.GetBuffer<TaskComponent>(m_BehaviorTree.Entity);
|
||||||
|
ref var child = ref taskComponents.ElementAt(Index + 1);
|
||||||
|
|
||||||
|
if (Time.time - m_StartTime >= m_TimeLimit.Value)
|
||||||
|
{
|
||||||
|
if (child.Status == TaskStatus.Running || child.Status == TaskStatus.Queued)
|
||||||
|
{
|
||||||
|
child.Status = m_TimeoutStatus;
|
||||||
|
taskComponents[Index + 1] = child;
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_TimeoutStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (child.Status == TaskStatus.Success || child.Status == TaskStatus.Failure)
|
||||||
|
{
|
||||||
|
return child.Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TaskStatus.Running;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnBehaviorTreeStopped(bool paused)
|
||||||
|
{
|
||||||
|
base.OnBehaviorTreeStopped(paused);
|
||||||
|
if (paused) m_PauseTime = Time.time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnBehaviorTreeStarted()
|
||||||
|
{
|
||||||
|
base.OnBehaviorTreeStarted();
|
||||||
|
if (m_PauseTime >= 0f)
|
||||||
|
{
|
||||||
|
m_StartTime += (Time.time - m_PauseTime);
|
||||||
|
m_PauseTime = -1f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override MemberVisibility GetSaveReflectionType(int index) => MemberVisibility.None;
|
||||||
|
|
||||||
|
public override object Save(World world, Entity entity)
|
||||||
|
{
|
||||||
|
// [제한 시간, 경과 시간] 저장
|
||||||
|
return new object[] { m_TimeLimit.Value, Time.time - m_StartTime };
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Load(object saveData, World world, Entity entity)
|
||||||
|
{
|
||||||
|
var data = (object[])saveData;
|
||||||
|
m_TimeLimit.Value = (float)data[0];
|
||||||
|
m_StartTime = Time.time - (float)data[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user