From 97da432c35b8c7aaf9dd2c39e2aa4b1f55f36065 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 27 Jan 2021 16:15:06 +0800 Subject: +behaviour designer --- .../Runtime/Decorators/ConditionalEvaluator.cs | 104 +++++++++++++++++++++ .../Decorators/ConditionalEvaluator.cs.meta | 8 ++ .../Runtime/Decorators/Interrupt.cs | 49 ++++++++++ .../Runtime/Decorators/Interrupt.cs.meta | 8 ++ .../Runtime/Decorators/Inverter.cs | 41 ++++++++ .../Runtime/Decorators/Inverter.cs.meta | 8 ++ .../Runtime/Decorators/Repeater.cs | 48 ++++++++++ .../Runtime/Decorators/Repeater.cs.meta | 8 ++ .../Runtime/Decorators/ReturnFailure.cs | 39 ++++++++ .../Runtime/Decorators/ReturnFailure.cs.meta | 8 ++ .../Runtime/Decorators/ReturnSuccess.cs | 38 ++++++++ .../Runtime/Decorators/ReturnSuccess.cs.meta | 8 ++ .../Runtime/Decorators/TaskGuard.cs | 77 +++++++++++++++ .../Runtime/Decorators/TaskGuard.cs.meta | 8 ++ .../Runtime/Decorators/UntilFailure.cs | 29 ++++++ .../Runtime/Decorators/UntilFailure.cs.meta | 8 ++ .../Runtime/Decorators/UntilSuccess.cs | 29 ++++++ .../Runtime/Decorators/UntilSuccess.cs.meta | 8 ++ 18 files changed, 526 insertions(+) create mode 100644 Client/Assets/Behavior Designer/Runtime/Decorators/ConditionalEvaluator.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Decorators/ConditionalEvaluator.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Decorators/Interrupt.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Decorators/Interrupt.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Decorators/Inverter.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Decorators/Inverter.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Decorators/Repeater.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Decorators/Repeater.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Decorators/ReturnFailure.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Decorators/ReturnFailure.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Decorators/ReturnSuccess.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Decorators/ReturnSuccess.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Decorators/TaskGuard.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Decorators/TaskGuard.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Decorators/UntilFailure.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Decorators/UntilFailure.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Decorators/UntilSuccess.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Decorators/UntilSuccess.cs.meta (limited to 'Client/Assets/Behavior Designer/Runtime/Decorators') diff --git a/Client/Assets/Behavior Designer/Runtime/Decorators/ConditionalEvaluator.cs b/Client/Assets/Behavior Designer/Runtime/Decorators/ConditionalEvaluator.cs new file mode 100644 index 00000000..7c2c20f7 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Decorators/ConditionalEvaluator.cs @@ -0,0 +1,104 @@ +using UnityEngine; +using BehaviorDesigner.Runtime; +using BehaviorDesigner.Runtime.Tasks; + +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("Evaluates the specified conditional task. If the conditional task returns success then the child task is run and the child status is returned. If the conditional task does not " + + "return success then the child task is not run and a failure status is immediately returned.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=146")] + [TaskIcon("{SkinColor}ConditionalEvaluatorIcon.png")] + public class ConditionalEvaluator : Decorator + { + [Tooltip("Should the conditional task be reevaluated every tick?")] + public SharedBool reevaluate; + [InspectTask] + [Tooltip("The conditional task to evaluate")] + public Conditional conditionalTask; + + // The status of the child after it has finished running. + private TaskStatus executionStatus = TaskStatus.Inactive; + private bool checkConditionalTask = true; + private bool conditionalTaskFailed = false; + + public override void OnAwake() + { + if (conditionalTask != null) { + conditionalTask.Owner = Owner; + conditionalTask.GameObject = gameObject; + conditionalTask.Transform = transform; + conditionalTask.OnAwake(); + } + } + + public override void OnStart() + { + if (conditionalTask != null) { + conditionalTask.OnStart(); + } + } + + public override bool CanExecute() + { + // CanExecute is called when checking the condition within a while loop so it will be called at least twice. Ensure the conditional task is checked only once + if (checkConditionalTask) { + checkConditionalTask = false; + OnUpdate(); + } + + if (conditionalTaskFailed) { + return false; + } + return executionStatus == TaskStatus.Inactive || executionStatus == TaskStatus.Running; + } + + public override bool CanReevaluate() + { + return reevaluate.Value; + } + + public override TaskStatus OnUpdate() + { + var childStatus = conditionalTask.OnUpdate(); + conditionalTaskFailed = conditionalTask == null || childStatus == TaskStatus.Failure; + return childStatus; + } + + public override void OnChildExecuted(TaskStatus childStatus) + { + // Update the execution status after a child has finished running. + executionStatus = childStatus; + } + + public override TaskStatus OverrideStatus() + { + // This version of OverrideStatus is called when the conditional evaluator fails reevaluation and has to stop all of its children. + // Therefore, the return status will always be failure + return TaskStatus.Failure; + } + + public override TaskStatus OverrideStatus(TaskStatus status) + { + if (conditionalTaskFailed) + return TaskStatus.Failure; + return status; + } + + public override void OnEnd() + { + // Reset the variables back to their starting values. + executionStatus = TaskStatus.Inactive; + checkConditionalTask = true; + conditionalTaskFailed = false; + if (conditionalTask != null) { + conditionalTask.OnEnd(); + } + } + + public override void OnReset() + { + // Reset the public properties back to their original values. + conditionalTask = null; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Decorators/ConditionalEvaluator.cs.meta b/Client/Assets/Behavior Designer/Runtime/Decorators/ConditionalEvaluator.cs.meta new file mode 100644 index 00000000..8f2340fd --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Decorators/ConditionalEvaluator.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 632578e05169d1d45a1ab77ae8bb45ad +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Decorators/Interrupt.cs b/Client/Assets/Behavior Designer/Runtime/Decorators/Interrupt.cs new file mode 100644 index 00000000..a7e575a6 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Decorators/Interrupt.cs @@ -0,0 +1,49 @@ +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("The interrupt task will stop all child tasks from running if it is interrupted. The interruption can be triggered by the perform interruption task. " + + "The interrupt task will keep running its child until this interruption is called. If no interruption happens and the child task completed its " + + "execution the interrupt task will return the value assigned by the child task.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=35")] + [TaskIcon("{SkinColor}InterruptIcon.png")] + public class Interrupt : Decorator + { + // When an interruption occurs return with this status. + private TaskStatus interruptStatus = TaskStatus.Failure; + // The status of the child after it has finished running. + private TaskStatus executionStatus = TaskStatus.Inactive; + + public override bool CanExecute() + { + // Continue executing until the child task returns success or failure. + return executionStatus == TaskStatus.Inactive || executionStatus == TaskStatus.Running; + } + + public override void OnChildExecuted(TaskStatus childStatus) + { + // Update the execution status after a child has finished running. + executionStatus = childStatus; + } + + public void DoInterrupt(TaskStatus status) + { + // An interruption has occurred. Update the interrupt status and notify the Behavior Manager. The Behavior Manager will stop all + // child tasks from running. + interruptStatus = status; + + BehaviorManager.instance.Interrupt(Owner, this); + } + + public override TaskStatus OverrideStatus() + { + // Return the interruption status as our status. + return interruptStatus; + } + + public override void OnEnd() + { + // Reset the variables back to their starting values. + interruptStatus = TaskStatus.Failure; + executionStatus = TaskStatus.Inactive; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Decorators/Interrupt.cs.meta b/Client/Assets/Behavior Designer/Runtime/Decorators/Interrupt.cs.meta new file mode 100644 index 00000000..b95c844c --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Decorators/Interrupt.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 81c44aaaa87500145831c0e167a5bfd3 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Decorators/Inverter.cs b/Client/Assets/Behavior Designer/Runtime/Decorators/Inverter.cs new file mode 100644 index 00000000..ce70d2f6 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Decorators/Inverter.cs @@ -0,0 +1,41 @@ +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("The inverter task will invert the return value of the child task after it has finished executing. " + + "If the child returns success, the inverter task will return failure. If the child returns failure, the inverter task will return success.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=36")] + [TaskIcon("{SkinColor}InverterIcon.png")] + public class Inverter : Decorator + { + // The status of the child after it has finished running. + private TaskStatus executionStatus = TaskStatus.Inactive; + + public override bool CanExecute() + { + // Continue executing until the child task returns success or failure. + return executionStatus == TaskStatus.Inactive || executionStatus == TaskStatus.Running; + } + + public override void OnChildExecuted(TaskStatus childStatus) + { + // Update the execution status after a child has finished running. + executionStatus = childStatus; + } + + public override TaskStatus Decorate(TaskStatus status) + { + // Invert the task status. + if (status == TaskStatus.Success) { + return TaskStatus.Failure; + } else if (status == TaskStatus.Failure) { + return TaskStatus.Success; + } + return status; + } + + public override void OnEnd() + { + // Reset the execution status back to its starting values. + executionStatus = TaskStatus.Inactive; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Decorators/Inverter.cs.meta b/Client/Assets/Behavior Designer/Runtime/Decorators/Inverter.cs.meta new file mode 100644 index 00000000..7c24be8a --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Decorators/Inverter.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 577fcf144ebc85642889f2dd11147272 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Decorators/Repeater.cs b/Client/Assets/Behavior Designer/Runtime/Decorators/Repeater.cs new file mode 100644 index 00000000..b6c3d733 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Decorators/Repeater.cs @@ -0,0 +1,48 @@ +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription(@"The repeater task will repeat execution of its child task until the child task has been run a specified number of times. " + + "It has the option of continuing to execute the child task even if the child task returns a failure.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=37")] + [TaskIcon("{SkinColor}RepeaterIcon.png")] + public class Repeater : Decorator + { + [Tooltip("The number of times to repeat the execution of its child task")] + public SharedInt count = 1; + [Tooltip("Allows the repeater to repeat forever")] + public SharedBool repeatForever; + [Tooltip("Should the task return if the child task returns a failure")] + public SharedBool endOnFailure; + + // The number of times the child task has been run. + private int executionCount = 0; + // The status of the child after it has finished running. + private TaskStatus executionStatus = TaskStatus.Inactive; + + public override bool CanExecute() + { + // Continue executing until we've reached the count or the child task returned failure and we should stop on a failure. + return (repeatForever.Value || executionCount < count.Value) && (!endOnFailure.Value || (endOnFailure.Value && executionStatus != TaskStatus.Failure)); + } + + public override void OnChildExecuted(TaskStatus childStatus) + { + // The child task has finished execution. Increase the execution count and update the execution status. + executionCount++; + executionStatus = childStatus; + } + + public override void OnEnd() + { + // Reset the variables back to their starting values. + executionCount = 0; + executionStatus = TaskStatus.Inactive; + } + + public override void OnReset() + { + // Reset the public properties back to their original values. + count = 0; + endOnFailure = true; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Decorators/Repeater.cs.meta b/Client/Assets/Behavior Designer/Runtime/Decorators/Repeater.cs.meta new file mode 100644 index 00000000..72b0fda5 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Decorators/Repeater.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e62515fa6915f0d4f88b808e2e77d3ff +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Decorators/ReturnFailure.cs b/Client/Assets/Behavior Designer/Runtime/Decorators/ReturnFailure.cs new file mode 100644 index 00000000..e76aa35c --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Decorators/ReturnFailure.cs @@ -0,0 +1,39 @@ +using UnityEngine; +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("The return failure task will always return failure except when the child task is running.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=38")] + [TaskIcon("{SkinColor}ReturnFailureIcon.png")] + public class ReturnFailure : Decorator + { + // The status of the child after it has finished running. + private TaskStatus executionStatus = TaskStatus.Inactive; + + public override bool CanExecute() + { + // Continue executing until the child task returns success or failure. + return executionStatus == TaskStatus.Inactive || executionStatus == TaskStatus.Running; + } + + public override void OnChildExecuted(TaskStatus childStatus) + { + // Update the execution status after a child has finished running. + executionStatus = childStatus; + } + + public override TaskStatus Decorate(TaskStatus status) + { + // Return failure even if the child task returned success. + if (status == TaskStatus.Success) { + return TaskStatus.Failure; + } + return status; + } + + public override void OnEnd() + { + // Reset the execution status back to its starting values. + executionStatus = TaskStatus.Inactive; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Decorators/ReturnFailure.cs.meta b/Client/Assets/Behavior Designer/Runtime/Decorators/ReturnFailure.cs.meta new file mode 100644 index 00000000..f8a3c82d --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Decorators/ReturnFailure.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f34d21f1bb4e761478bdf76222fcf135 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Decorators/ReturnSuccess.cs b/Client/Assets/Behavior Designer/Runtime/Decorators/ReturnSuccess.cs new file mode 100644 index 00000000..e44e69d4 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Decorators/ReturnSuccess.cs @@ -0,0 +1,38 @@ +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("The return success task will always return success except when the child task is running.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=39")] + [TaskIcon("{SkinColor}ReturnSuccessIcon.png")] + public class ReturnSuccess : Decorator + { + // The status of the child after it has finished running. + private TaskStatus executionStatus = TaskStatus.Inactive; + + public override bool CanExecute() + { + // Continue executing until the child task returns success or failure. + return executionStatus == TaskStatus.Inactive || executionStatus == TaskStatus.Running; + } + + public override void OnChildExecuted(TaskStatus childStatus) + { + // Update the execution status after a child has finished running. + executionStatus = childStatus; + } + + public override TaskStatus Decorate(TaskStatus status) + { + // Return success even if the child task returned failure. + if (status == TaskStatus.Failure) { + return TaskStatus.Success; + } + return status; + } + + public override void OnEnd() + { + // Reset the execution status back to its starting values. + executionStatus = TaskStatus.Inactive; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Decorators/ReturnSuccess.cs.meta b/Client/Assets/Behavior Designer/Runtime/Decorators/ReturnSuccess.cs.meta new file mode 100644 index 00000000..88c9f2c4 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Decorators/ReturnSuccess.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 27d103b9f961fd44da3c4d83dadd90ca +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Decorators/TaskGuard.cs b/Client/Assets/Behavior Designer/Runtime/Decorators/TaskGuard.cs new file mode 100644 index 00000000..86bb841e --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Decorators/TaskGuard.cs @@ -0,0 +1,77 @@ +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("The task guard task is similar to a semaphore in multithreaded programming. The task guard task is there to ensure a limited resource is not being overused. " + + "\n\nFor example, you may place a task guard above a task that plays an animation. Elsewhere within your behavior tree you may also have another task that plays a different " + + "animation but uses the same bones for that animation. Because of this you don't want that animation to play twice at the same time. Placing a task guard will let you " + + "specify how many times a particular task can be accessed at the same time.\n\nIn the previous animation task example you would specify an access count of 1. With this setup " + + "the animation task can be only controlled by one task at a time. If the first task is playing the animation and a second task wants to control the animation as well, it will " + + "either have to wait or skip over the task completely.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=40")] + [TaskIcon("{SkinColor}TaskGuardIcon.png")] + public class TaskGuard : Decorator + { + [Tooltip("The number of times the child tasks can be accessed by parallel tasks at once")] + public SharedInt maxTaskAccessCount; + [Tooltip("The linked tasks that also guard a task. If the task guard is not linked against any other tasks it doesn't have much purpose. Marked as LinkedTask to " + + "ensure all tasks linked are linked to the same set of tasks")] + [LinkedTask] + public TaskGuard[] linkedTaskGuards = null; + [Tooltip("If true the task will wait until the child task is available. If false then any unavailable child tasks will be skipped over")] + public SharedBool waitUntilTaskAvailable; + + // The number of tasks that are currently using a particular task. + private int executingTasks = 0; + // True if the current task is executing. + private bool executing = false; + + public override bool CanExecute() + { + // The child task can execute if the number of executing tasks is less than the maximum number of tasks allowed. + return executingTasks < maxTaskAccessCount.Value && !executing; + } + + public override void OnChildStarted() + { + // The child task has started to run. Increase the executing tasks counter and notify all of the other linked tasks. + executingTasks++; + executing = true; + for (int i = 0; i < linkedTaskGuards.Length; ++i) { + linkedTaskGuards[i].taskExecuting(true); + } + } + + public override TaskStatus OverrideStatus(TaskStatus status) + { + // return a running status if the children are currently waiting for a task to become available + return (!executing && waitUntilTaskAvailable.Value) ? TaskStatus.Running : status; + } + + public void taskExecuting(bool increase) + { + // A linked task is currently executing a task that is being guarded. If the task just started executing then increase will be true and if it is ending then + // true will be false. + executingTasks += (increase ? 1 : -1); + } + + public override void OnEnd() + { + // The child task has been executed or skipped over. Only decrement the executing tasks count if the child task was being executed. Following that + // notify all of the linked tasks that we are done executing. + if (executing) { + executingTasks--; + for (int i = 0; i < linkedTaskGuards.Length; ++i) { + linkedTaskGuards[i].taskExecuting(false); + } + executing = false; + } + } + + public override void OnReset() + { + // Reset the public properties back to their original values + maxTaskAccessCount = null; + linkedTaskGuards = null; + waitUntilTaskAvailable = true; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Decorators/TaskGuard.cs.meta b/Client/Assets/Behavior Designer/Runtime/Decorators/TaskGuard.cs.meta new file mode 100644 index 00000000..9302e5bd --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Decorators/TaskGuard.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7e2ae4ab352f20c41be106f92efc3b43 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Decorators/UntilFailure.cs b/Client/Assets/Behavior Designer/Runtime/Decorators/UntilFailure.cs new file mode 100644 index 00000000..4bcd2c5d --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Decorators/UntilFailure.cs @@ -0,0 +1,29 @@ +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("The until failure task will keep executing its child task until the child task returns failure.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=41")] + [TaskIcon("{SkinColor}UntilFailureIcon.png")] + public class UntilFailure : Decorator + { + // The status of the child after it has finished running. + private TaskStatus executionStatus = TaskStatus.Inactive; + + public override bool CanExecute() + { + // Keep running until the child task returns failure. + return executionStatus == TaskStatus.Success || executionStatus == TaskStatus.Inactive; + } + + public override void OnChildExecuted(TaskStatus childStatus) + { + // Update the execution status after a child has finished running. + executionStatus = childStatus; + } + + public override void OnEnd() + { + // Reset the execution status back to its starting values. + executionStatus = TaskStatus.Inactive; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Decorators/UntilFailure.cs.meta b/Client/Assets/Behavior Designer/Runtime/Decorators/UntilFailure.cs.meta new file mode 100644 index 00000000..4c09971c --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Decorators/UntilFailure.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 934b87f8f563272469cd9a9b14046ae7 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Decorators/UntilSuccess.cs b/Client/Assets/Behavior Designer/Runtime/Decorators/UntilSuccess.cs new file mode 100644 index 00000000..77e0f77b --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Decorators/UntilSuccess.cs @@ -0,0 +1,29 @@ +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("The until success task will keep executing its child task until the child task returns success.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=42")] + [TaskIcon("{SkinColor}UntilSuccessIcon.png")] + public class UntilSuccess : Decorator + { + // The status of the child after it has finished running. + private TaskStatus executionStatus = TaskStatus.Inactive; + + public override bool CanExecute() + { + // Keep running until the child task returns success. + return executionStatus == TaskStatus.Failure || executionStatus == TaskStatus.Inactive; + } + + public override void OnChildExecuted(TaskStatus childStatus) + { + // Update the execution status after a child has finished running. + executionStatus = childStatus; + } + + public override void OnEnd() + { + // Reset the execution status back to its starting values. + executionStatus = TaskStatus.Inactive; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Decorators/UntilSuccess.cs.meta b/Client/Assets/Behavior Designer/Runtime/Decorators/UntilSuccess.cs.meta new file mode 100644 index 00000000..0d832e40 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Decorators/UntilSuccess.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6d5c2cbf6c58f6b419831477bde98317 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: -- cgit v1.1-26-g67d0