From 97da432c35b8c7aaf9dd2c39e2aa4b1f55f36065 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 27 Jan 2021 16:15:06 +0800 Subject: +behaviour designer --- .../Runtime/Actions/StopBehaviorTree.cs | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/StopBehaviorTree.cs (limited to 'Client/Assets/Behavior Designer/Runtime/Actions/StopBehaviorTree.cs') diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/StopBehaviorTree.cs b/Client/Assets/Behavior Designer/Runtime/Actions/StopBehaviorTree.cs new file mode 100644 index 00000000..fe753c5b --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/StopBehaviorTree.cs @@ -0,0 +1,57 @@ +using UnityEngine; + +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("Pause or disable a behavior tree and return success after it has been stopped.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=21")] + [TaskIcon("{SkinColor}StopBehaviorTreeIcon.png")] + public class StopBehaviorTree : Action + { + [Tooltip("The GameObject of the behavior tree that should be stopped. If null use the current behavior")] + public SharedGameObject behaviorGameObject; + [Tooltip("The group of the behavior tree that should be stopped")] + public SharedInt group; + [Tooltip("Should the behavior be paused or completely disabled")] + public SharedBool pauseBehavior = false; + + private Behavior behavior; + + public override void OnStart() + { + var behaviorTrees = GetDefaultGameObject(behaviorGameObject.Value).GetComponents(); + if (behaviorTrees.Length == 1) { + behavior = behaviorTrees[0]; + } else if (behaviorTrees.Length > 1) { + for (int i = 0; i < behaviorTrees.Length; ++i) { + if (behaviorTrees[i].Group == group.Value) { + behavior = behaviorTrees[i]; + break; + } + } + // If the group can't be found then use the first behavior tree + if (behavior == null) { + behavior = behaviorTrees[0]; + } + } + } + + public override TaskStatus OnUpdate() + { + if (behavior == null) { + return TaskStatus.Failure; + } + + // Start the behavior and return success. + behavior.DisableBehavior(pauseBehavior.Value); + return TaskStatus.Success; + } + + public override void OnReset() + { + // Reset the properties back to their original values + behaviorGameObject = null; + group = 0; + pauseBehavior = false; + } + } +} \ No newline at end of file -- cgit v1.1-26-g67d0