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/BehaviorTreeReference.cs | 17 ++++ .../Runtime/Actions/BehaviorTreeReference.cs.meta | 8 ++ .../Behavior Designer/Runtime/Actions/Idle.cs | 15 ++++ .../Behavior Designer/Runtime/Actions/Idle.cs.meta | 8 ++ .../Behavior Designer/Runtime/Actions/Log.cs | 33 ++++++++ .../Behavior Designer/Runtime/Actions/Log.cs.meta | 8 ++ .../Runtime/Actions/PerformInterruption.cs | 29 +++++++ .../Runtime/Actions/PerformInterruption.cs.meta | 8 ++ .../Runtime/Actions/Reflection.meta | 5 ++ .../Runtime/Actions/Reflection/GetFieldValue.cs | 58 ++++++++++++++ .../Actions/Reflection/GetFieldValue.cs.meta | 8 ++ .../Runtime/Actions/Reflection/GetPropertyValue.cs | 58 ++++++++++++++ .../Actions/Reflection/GetPropertyValue.cs.meta | 8 ++ .../Runtime/Actions/Reflection/InvokeMethod.cs | 86 +++++++++++++++++++++ .../Actions/Reflection/InvokeMethod.cs.meta | 8 ++ .../Runtime/Actions/Reflection/SetFieldValue.cs | 57 ++++++++++++++ .../Actions/Reflection/SetFieldValue.cs.meta | 8 ++ .../Runtime/Actions/Reflection/SetPropertyValue.cs | 57 ++++++++++++++ .../Actions/Reflection/SetPropertyValue.cs.meta | 8 ++ .../Runtime/Actions/RestartBehaviorTree.cs | 56 ++++++++++++++ .../Runtime/Actions/RestartBehaviorTree.cs.meta | 8 ++ .../Behavior Designer/Runtime/Actions/SendEvent.cs | 73 ++++++++++++++++++ .../Runtime/Actions/SendEvent.cs.meta | 8 ++ .../Runtime/Actions/StartBehaviorTree.cs | 90 ++++++++++++++++++++++ .../Runtime/Actions/StartBehaviorTree.cs.meta | 8 ++ .../Runtime/Actions/StopBehaviorTree.cs | 57 ++++++++++++++ .../Runtime/Actions/StopBehaviorTree.cs.meta | 8 ++ .../Behavior Designer/Runtime/Actions/Wait.cs | 67 ++++++++++++++++ .../Behavior Designer/Runtime/Actions/Wait.cs.meta | 8 ++ 29 files changed, 870 insertions(+) create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/BehaviorTreeReference.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/BehaviorTreeReference.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/Idle.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/Idle.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/Log.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/Log.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/PerformInterruption.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/PerformInterruption.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/Reflection.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/Reflection/GetFieldValue.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/Reflection/GetFieldValue.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/Reflection/GetPropertyValue.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/Reflection/GetPropertyValue.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/Reflection/InvokeMethod.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/Reflection/InvokeMethod.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/Reflection/SetFieldValue.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/Reflection/SetFieldValue.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/Reflection/SetPropertyValue.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/Reflection/SetPropertyValue.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/RestartBehaviorTree.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/RestartBehaviorTree.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/SendEvent.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/SendEvent.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/StartBehaviorTree.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/StartBehaviorTree.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/StopBehaviorTree.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/StopBehaviorTree.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/Wait.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Actions/Wait.cs.meta (limited to 'Client/Assets/Behavior Designer/Runtime/Actions') diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/BehaviorTreeReference.cs b/Client/Assets/Behavior Designer/Runtime/Actions/BehaviorTreeReference.cs new file mode 100644 index 00000000..5bf87b40 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/BehaviorTreeReference.cs @@ -0,0 +1,17 @@ +using UnityEngine; + +namespace BehaviorDesigner.Runtime.Tasks +{ + // Wrapper class for the Behavior Reference task. The Behavior Tree Reference task allows you to run another behavior tree within the current behavior tree. + // One use for this task is if you have an unit that plays a series of tasks to attack. You may want the unit to attack at different points within + // the behavior tree, and you want that attack to always be the same. Instead of copying and pasting the same tasks over and over you can just use + // an external behavior and then the tasks are always guaranteed to be the same. This example is demonstrated in the RTS sample project located at + // http://www.opsive.com/assets/BehaviorDesigner/samples.php. + [TaskDescription("Behavior Tree Reference allows you to run another behavior tree within the current behavior tree.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=53")] + [TaskIcon("BehaviorTreeReferenceIcon.png")] + public class BehaviorTreeReference : BehaviorReference + { + // intentionally left blank - subclass of BehaviorReference + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/BehaviorTreeReference.cs.meta b/Client/Assets/Behavior Designer/Runtime/Actions/BehaviorTreeReference.cs.meta new file mode 100644 index 00000000..f81a791a --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/BehaviorTreeReference.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: af7b6fcbc7258f34aad1bb82b5b3fdc8 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/Idle.cs b/Client/Assets/Behavior Designer/Runtime/Actions/Idle.cs new file mode 100644 index 00000000..04574a79 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/Idle.cs @@ -0,0 +1,15 @@ +using UnityEngine; + +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("Returns a TaskStatus of running. Will only stop when interrupted or a conditional abort is triggered.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=112")] + [TaskIcon("{SkinColor}IdleIcon.png")] + public class Idle : Action + { + public override TaskStatus OnUpdate() + { + return TaskStatus.Running; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/Idle.cs.meta b/Client/Assets/Behavior Designer/Runtime/Actions/Idle.cs.meta new file mode 100644 index 00000000..6b5a4977 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/Idle.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 759252a4ffada80419ef06ce1c625246 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/Log.cs b/Client/Assets/Behavior Designer/Runtime/Actions/Log.cs new file mode 100644 index 00000000..b3ce1f2a --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/Log.cs @@ -0,0 +1,33 @@ +using UnityEngine; + +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("Log is a simple task which will output the specified text and return success. It can be used for debugging.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=16")] + [TaskIcon("{SkinColor}LogIcon.png")] + public class Log : Action + { + [Tooltip("Text to output to the log")] + public SharedString text; + [Tooltip("Is this text an error?")] + public SharedBool logError; + + public override TaskStatus OnUpdate() + { + // Log the text and return success + //if (logError.Value) { + // Debug.LogError(text); + //} else { + // Debug.Log(text); + //} + return TaskStatus.Success; + } + + public override void OnReset() + { + // Reset the properties back to their original values + text = ""; + logError = false; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/Log.cs.meta b/Client/Assets/Behavior Designer/Runtime/Actions/Log.cs.meta new file mode 100644 index 00000000..31b9601b --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/Log.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d53794347878c7c479da37533dce2024 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/PerformInterruption.cs b/Client/Assets/Behavior Designer/Runtime/Actions/PerformInterruption.cs new file mode 100644 index 00000000..05c20a68 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/PerformInterruption.cs @@ -0,0 +1,29 @@ +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("Perform the actual interruption. This will immediately stop the specified tasks from running and will return success or failure depending on the value of interrupt success.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=17")] + [TaskIcon("{SkinColor}PerformInterruptionIcon.png")] + public class PerformInterruption : Action + { + [Tooltip("The list of tasks to interrupt. Can be any number of tasks")] + public Interrupt[] interruptTasks; + [Tooltip("When we interrupt the task should we return a task status of success?")] + public SharedBool interruptSuccess; + + public override TaskStatus OnUpdate() + { + // Loop through all of the tasks and fire an interruption. Once complete return success. + for (int i = 0; i < interruptTasks.Length; ++i) { + interruptTasks[i].DoInterrupt(interruptSuccess.Value ? TaskStatus.Success : TaskStatus.Failure); + } + return TaskStatus.Success; + } + + public override void OnReset() + { + // Reset the properties back to their original values. + interruptTasks = null; + interruptSuccess = false; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/PerformInterruption.cs.meta b/Client/Assets/Behavior Designer/Runtime/Actions/PerformInterruption.cs.meta new file mode 100644 index 00000000..028b3699 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/PerformInterruption.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 72d2d6051b23e86468e2f715f044dad8 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/Reflection.meta b/Client/Assets/Behavior Designer/Runtime/Actions/Reflection.meta new file mode 100644 index 00000000..ee7a8834 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/Reflection.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2 +guid: 70f925868ab5ebe4cbc702810c2c5857 +folderAsset: yes +DefaultImporter: + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/GetFieldValue.cs b/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/GetFieldValue.cs new file mode 100644 index 00000000..1a4631a1 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/GetFieldValue.cs @@ -0,0 +1,58 @@ +using UnityEngine; +using System; +using System.Reflection; + +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("Gets the value from the field specified. Returns success if the field was retrieved.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=147")] + [TaskCategory("Reflection")] + [TaskIcon("{SkinColor}ReflectionIcon.png")] + public class GetFieldValue : Action + { + [Tooltip("The GameObject to get the field on")] + public SharedGameObject targetGameObject; + [Tooltip("The component to get the field on")] + public SharedString componentName; + [Tooltip("The name of the field")] + public SharedString fieldName; + [Tooltip("The value of the field")] + [RequiredField] + public SharedVariable fieldValue; + + public override TaskStatus OnUpdate() + { + if (fieldValue == null) { + //Debug.LogWarning("Unable to get field - field value is null"); + return TaskStatus.Failure; + } + + var type = TaskUtility.GetTypeWithinAssembly(componentName.Value); + if (type == null) { + //Debug.LogWarning("Unable to get field - type is null"); + return TaskStatus.Failure; + } + + var component = GetDefaultGameObject(targetGameObject.Value).GetComponent(type); + if (component == null) { + //Debug.LogWarning("Unable to get the field with component " + componentName.Value); + return TaskStatus.Failure; + } + + // If you are receiving a compiler error on the Windows Store platform see this topic: + // http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=46 + var field = component.GetType().GetField(fieldName.Value); + fieldValue.SetValue(field.GetValue(component)); + + return TaskStatus.Success; + } + + public override void OnReset() + { + targetGameObject = null; + componentName = null; + fieldName = null; + fieldValue = null; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/GetFieldValue.cs.meta b/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/GetFieldValue.cs.meta new file mode 100644 index 00000000..34bf75c3 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/GetFieldValue.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bc317dd7feb2085499edb0d0c4604640 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/GetPropertyValue.cs b/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/GetPropertyValue.cs new file mode 100644 index 00000000..63e50c26 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/GetPropertyValue.cs @@ -0,0 +1,58 @@ +using UnityEngine; +using System; +using System.Reflection; + +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("Gets the value from the property specified. Returns success if the property was retrieved.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=148")] + [TaskCategory("Reflection")] + [TaskIcon("{SkinColor}ReflectionIcon.png")] + public class GetPropertyValue : Action + { + [Tooltip("The GameObject to get the property of")] + public SharedGameObject targetGameObject; + [Tooltip("The component to get the property of")] + public SharedString componentName; + [Tooltip("The name of the property")] + public SharedString propertyName; + [Tooltip("The value of the property")] + [RequiredField] + public SharedVariable propertyValue; + + public override TaskStatus OnUpdate() + { + if (propertyValue == null) { + //Debug.LogWarning("Unable to get property - property value is null"); + return TaskStatus.Failure; + } + + var type = TaskUtility.GetTypeWithinAssembly(componentName.Value); + if (type == null) { + //Debug.LogWarning("Unable to get property - type is null"); + return TaskStatus.Failure; + } + + var component = GetDefaultGameObject(targetGameObject.Value).GetComponent(type); + if (component == null) { + //Debug.LogWarning("Unable to get the property with component " + componentName.Value); + return TaskStatus.Failure; + } + + // If you are receiving a compiler error on the Windows Store platform see this topic: + // http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=46 + var property = component.GetType().GetProperty(propertyName.Value); + propertyValue.SetValue(property.GetValue(component, null)); + + return TaskStatus.Success; + } + + public override void OnReset() + { + targetGameObject = null; + componentName = null; + propertyName = null; + propertyValue = null; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/GetPropertyValue.cs.meta b/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/GetPropertyValue.cs.meta new file mode 100644 index 00000000..587385b3 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/GetPropertyValue.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: dda9c9b7c6ff2ee4f95a2e208cddae64 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/InvokeMethod.cs b/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/InvokeMethod.cs new file mode 100644 index 00000000..5780c350 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/InvokeMethod.cs @@ -0,0 +1,86 @@ +using UnityEngine; +using System; +using System.Collections.Generic; +using System.Reflection; + +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("Invokes the specified method with the specified parameters. Can optionally store the return value. Returns success if the method was invoked.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=145")] + [TaskCategory("Reflection")] + [TaskIcon("{SkinColor}ReflectionIcon.png")] + public class InvokeMethod : Action + { + [Tooltip("The GameObject to invoke the method on")] + public SharedGameObject targetGameObject; + [Tooltip("The component to invoke the method on")] + public SharedString componentName; + [Tooltip("The name of the method")] + public SharedString methodName; + [Tooltip("The first parameter of the method")] + public SharedVariable parameter1; + [Tooltip("The second parameter of the method")] + public SharedVariable parameter2; + [Tooltip("The third parameter of the method")] + public SharedVariable parameter3; + [Tooltip("The fourth parameter of the method")] + public SharedVariable parameter4; + [Tooltip("Store the result of the invoke call")] + public SharedVariable storeResult; + + public override TaskStatus OnUpdate() + { + var type = TaskUtility.GetTypeWithinAssembly(componentName.Value); + if (type == null) { + //Debug.LogWarning("Unable to invoke - type is null"); + return TaskStatus.Failure; + } + + var component = GetDefaultGameObject(targetGameObject.Value).GetComponent(type); + if (component == null) { + //Debug.LogWarning("Unable to invoke method with component " + componentName.Value); + return TaskStatus.Failure; + } + + var parameterList = new List(); + var parameterTypeList = new List(); + SharedVariable sharedVariable = null; + for (int i = 0; i < 4; ++i) { + var parameterField = GetType().GetField("parameter" + (i + 1)); + if ((sharedVariable = parameterField.GetValue(this) as SharedVariable) != null) { + parameterList.Add(sharedVariable.GetValue()); + parameterTypeList.Add(sharedVariable.GetType().GetProperty("Value").PropertyType); + } else { + break; + } + } + // If you are receiving a compiler error on the Windows Store platform see this topic: + // http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=46 + var methodInfo = component.GetType().GetMethod(methodName.Value, parameterTypeList.ToArray()); + + if (methodInfo == null) { + //Debug.LogWarning("Unable to invoke method " + methodName.Value + " on component " + componentName.Value); + return TaskStatus.Failure; + } + + var result = methodInfo.Invoke(component, parameterList.ToArray()); + if (storeResult != null) { + storeResult.SetValue(result); + } + + return TaskStatus.Success; + } + + public override void OnReset() + { + targetGameObject = null; + componentName = null; + methodName = null; + parameter1 = null; + parameter2 = null; + parameter3 = null; + parameter4 = null; + storeResult = null; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/InvokeMethod.cs.meta b/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/InvokeMethod.cs.meta new file mode 100644 index 00000000..eed4a86a --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/InvokeMethod.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 359bd67578f53034ab2eb00e7696d317 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/SetFieldValue.cs b/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/SetFieldValue.cs new file mode 100644 index 00000000..c0c9e2f0 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/SetFieldValue.cs @@ -0,0 +1,57 @@ +using UnityEngine; +using System; +using System.Reflection; + +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("Sets the field to the value specified. Returns success if the field was set.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=149")] + [TaskCategory("Reflection")] + [TaskIcon("{SkinColor}ReflectionIcon.png")] + public class SetFieldValue : Action + { + [Tooltip("The GameObject to set the field on")] + public SharedGameObject targetGameObject; + [Tooltip("The component to set the field on")] + public SharedString componentName; + [Tooltip("The name of the field")] + public SharedString fieldName; + [Tooltip("The value to set")] + public SharedVariable fieldValue; + + public override TaskStatus OnUpdate() + { + if (fieldValue == null) { + //Debug.LogWarning("Unable to get field - field value is null"); + return TaskStatus.Failure; + } + + var type = TaskUtility.GetTypeWithinAssembly(componentName.Value); + if (type == null) { + //Debug.LogWarning("Unable to set field - type is null"); + return TaskStatus.Failure; + } + + var component = GetDefaultGameObject(targetGameObject.Value).GetComponent(type); + if (component == null) { + //Debug.LogWarning("Unable to set the field with component " + componentName.Value); + return TaskStatus.Failure; + } + + // If you are receiving a compiler error on the Windows Store platform see this topic: + // http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=46 + var field = component.GetType().GetField(fieldName.Value); + field.SetValue(component, fieldValue.GetValue()); + + return TaskStatus.Success; + } + + public override void OnReset() + { + targetGameObject = null; + componentName = null; + fieldName = null; + fieldValue = null; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/SetFieldValue.cs.meta b/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/SetFieldValue.cs.meta new file mode 100644 index 00000000..433a991c --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/SetFieldValue.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 21e389787213ba24ab1a6817def634ae +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/SetPropertyValue.cs b/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/SetPropertyValue.cs new file mode 100644 index 00000000..570aefb0 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/SetPropertyValue.cs @@ -0,0 +1,57 @@ +using UnityEngine; +using System; +using System.Reflection; + +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("Sets the property to the value specified. Returns success if the property was set.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=150")] + [TaskCategory("Reflection")] + [TaskIcon("{SkinColor}ReflectionIcon.png")] + public class SetPropertyValue : Action + { + [Tooltip("The GameObject to set the property on")] + public SharedGameObject targetGameObject; + [Tooltip("The component to set the property on")] + public SharedString componentName; + [Tooltip("The name of the property")] + public SharedString propertyName; + [Tooltip("The value to set")] + public SharedVariable propertyValue; + + public override TaskStatus OnUpdate() + { + if (propertyValue == null) { + //Debug.LogWarning("Unable to get field - field value is null"); + return TaskStatus.Failure; + } + + var type = TaskUtility.GetTypeWithinAssembly(componentName.Value); + if (type == null) { + //Debug.LogWarning("Unable to set property - type is null"); + return TaskStatus.Failure; + } + + var component = GetDefaultGameObject(targetGameObject.Value).GetComponent(type); + if (component == null) { + //Debug.LogWarning("Unable to set the property with component " + componentName.Value); + return TaskStatus.Failure; + } + + // If you are receiving a compiler error on the Windows Store platform see this topic: + // http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=46 + var property = component.GetType().GetProperty(propertyName.Value); + property.SetValue(component, propertyValue.GetValue(), null); + + return TaskStatus.Success; + } + + public override void OnReset() + { + targetGameObject = null; + componentName = null; + propertyName = null; + propertyValue = null; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/SetPropertyValue.cs.meta b/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/SetPropertyValue.cs.meta new file mode 100644 index 00000000..012823b6 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/Reflection/SetPropertyValue.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d98b13b7ae4b36b4092b439731466d9b +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/RestartBehaviorTree.cs b/Client/Assets/Behavior Designer/Runtime/Actions/RestartBehaviorTree.cs new file mode 100644 index 00000000..a63d9e6c --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/RestartBehaviorTree.cs @@ -0,0 +1,56 @@ +using UnityEngine; + +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("Restarts a behavior tree, returns success after it has been restarted.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=66")] + [TaskIcon("{SkinColor}RestartBehaviorTreeIcon.png")] + public class RestartBehaviorTree : Action + { + [Tooltip("The GameObject of the behavior tree that should be restarted. If null use the current behavior")] + public SharedGameObject behaviorGameObject; + [Tooltip("The group of the behavior tree that should be restarted")] + public SharedInt group; + + private Behavior behavior; + + public override void OnAwake() + { + 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; + } + + // Stop the behavior tree + behavior.DisableBehavior(); + // Start the behavior tree back up + behavior.EnableBehavior(); + // Return success + return TaskStatus.Success; + } + + public override void OnReset() + { + // Reset the properties back to their original values. + behavior = null; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/RestartBehaviorTree.cs.meta b/Client/Assets/Behavior Designer/Runtime/Actions/RestartBehaviorTree.cs.meta new file mode 100644 index 00000000..d1110668 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/RestartBehaviorTree.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2765e7ece98046542880a1249b87e096 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/SendEvent.cs b/Client/Assets/Behavior Designer/Runtime/Actions/SendEvent.cs new file mode 100644 index 00000000..76007309 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/SendEvent.cs @@ -0,0 +1,73 @@ +using UnityEngine; + +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("Sends an event to the behavior tree, returns success after sending the event.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=121")] + [TaskIcon("{SkinColor}SendEventIcon.png")] + public class SendEvent : Action + { + [Tooltip("The GameObject of the behavior tree that should have the event sent to it. If null use the current behavior")] + public SharedGameObject targetGameObject; + [Tooltip("The event to send")] + public SharedString eventName; + [Tooltip("The group of the behavior tree that the event should be sent to")] + public SharedInt group; + [Tooltip("Optionally specify a first argument to send")] + [SharedRequired] + public SharedVariable argument1; + [Tooltip("Optionally specify a second argument to send")] + [SharedRequired] + public SharedVariable argument2; + [Tooltip("Optionally specify a third argument to send")] + [SharedRequired] + public SharedVariable argument3; + + private BehaviorTree behaviorTree; + + public override void OnStart() + { + var behaviorTrees = GetDefaultGameObject(targetGameObject.Value).GetComponents(); + if (behaviorTrees.Length == 1) { + behaviorTree = behaviorTrees[0]; + } else if (behaviorTrees.Length > 1) { + for (int i = 0; i < behaviorTrees.Length; ++i) { + if (behaviorTrees[i].Group == group.Value) { + behaviorTree = behaviorTrees[i]; + break; + } + } + // If the group can't be found then use the first behavior tree + if (behaviorTree == null) { + behaviorTree = behaviorTrees[0]; + } + } + } + + public override TaskStatus OnUpdate() + { + // Send the event and return success + if (argument1 == null || argument1.IsNone) { + behaviorTree.SendEvent(eventName.Value); + } else { + if (argument2 == null || argument2.IsNone) { + behaviorTree.SendEvent(eventName.Value, argument1.GetValue()); + } else { + if (argument3 == null || argument3.IsNone) { + behaviorTree.SendEvent(eventName.Value, argument1.GetValue(), argument2.GetValue()); + } else { + behaviorTree.SendEvent(eventName.Value, argument1.GetValue(), argument2.GetValue(), argument3.GetValue()); + } + } + } + return TaskStatus.Success; + } + + public override void OnReset() + { + // Reset the properties back to their original values + targetGameObject = null; + eventName = ""; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/SendEvent.cs.meta b/Client/Assets/Behavior Designer/Runtime/Actions/SendEvent.cs.meta new file mode 100644 index 00000000..82bd42cd --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/SendEvent.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 53b90428a37913c40b6d415ced4e12f9 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/StartBehaviorTree.cs b/Client/Assets/Behavior Designer/Runtime/Actions/StartBehaviorTree.cs new file mode 100644 index 00000000..e817713a --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/StartBehaviorTree.cs @@ -0,0 +1,90 @@ +using UnityEngine; + +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("Start a new behavior tree and return success after it has been started.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=20")] + [TaskIcon("{SkinColor}StartBehaviorTreeIcon.png")] + public class StartBehaviorTree : Action + { + [Tooltip("The GameObject of the behavior tree that should be started. If null use the current behavior")] + public SharedGameObject behaviorGameObject; + [Tooltip("The group of the behavior tree that should be started")] + public SharedInt group; + [Tooltip("Should this task wait for the behavior tree to complete?")] + public SharedBool waitForCompletion = false; + [Tooltip("Should the variables be synchronized?")] + public SharedBool synchronizeVariables; + + private bool behaviorComplete; + 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]; + } + } + + if (behavior != null) { + var variables = Owner.GetAllVariables(); + for (int i = 0; i < variables.Count; ++i) { + behavior.SetVariable(variables[i].Name, variables[i]); + } + + behavior.EnableBehavior(); + + if (waitForCompletion.Value) { + behaviorComplete = false; + behavior.OnBehaviorEnd += BehaviorEnded; + } + } + } + + public override TaskStatus OnUpdate() + { + if (behavior == null) { + return TaskStatus.Failure; + } + + // Return a status of running if we are waiting for the behavior tree to end and it hasn't ended yet + if (waitForCompletion.Value && !behaviorComplete) { + return TaskStatus.Running; + } + + return TaskStatus.Success; + } + + private void BehaviorEnded() + { + behaviorComplete = true; + } + + public override void OnEnd() + { + if (behavior != null && waitForCompletion.Value) { + behavior.OnBehaviorEnd -= BehaviorEnded; + } + } + + public override void OnReset() + { + // Reset the properties back to their original values. + behaviorGameObject = null; + group = 0; + waitForCompletion = false; + synchronizeVariables = false; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/StartBehaviorTree.cs.meta b/Client/Assets/Behavior Designer/Runtime/Actions/StartBehaviorTree.cs.meta new file mode 100644 index 00000000..e62076c2 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/StartBehaviorTree.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bc3d67c80371297439385b30f4be506c +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: 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 diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/StopBehaviorTree.cs.meta b/Client/Assets/Behavior Designer/Runtime/Actions/StopBehaviorTree.cs.meta new file mode 100644 index 00000000..6f958c5e --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/StopBehaviorTree.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 130afc7e6aa6e0c4aba29097334aa66b +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/Wait.cs b/Client/Assets/Behavior Designer/Runtime/Actions/Wait.cs new file mode 100644 index 00000000..41f77a21 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/Wait.cs @@ -0,0 +1,67 @@ +using UnityEngine; + +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("Wait a specified amount of time. The task will return running until the task is done waiting. It will return success after the wait time has elapsed.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=22")] + [TaskIcon("{SkinColor}WaitIcon.png")] + public class Wait : Action + { + [Tooltip("The amount of time to wait")] + public SharedFloat waitTime = 1; + [Tooltip("Should the wait be randomized?")] + public SharedBool randomWait = false; + [Tooltip("The minimum wait time if random wait is enabled")] + public SharedFloat randomWaitMin = 1; + [Tooltip("The maximum wait time if random wait is enabled")] + public SharedFloat randomWaitMax = 1; + + // The time to wait + private float waitDuration; + // The time that the task started to wait. + private float startTime; + // Remember the time that the task is paused so the time paused doesn't contribute to the wait time. + private float pauseTime; + + public override void OnStart() + { + // Remember the start time. + startTime = Time.time; + if (randomWait.Value) { + waitDuration = Random.Range(randomWaitMin.Value, randomWaitMax.Value); + } else { + waitDuration = waitTime.Value; + } + } + + public override TaskStatus OnUpdate() + { + // The task is done waiting if the time waitDuration has elapsed since the task was started. + if (startTime + waitDuration < Time.time) { + return TaskStatus.Success; + } + // Otherwise we are still waiting. + return TaskStatus.Running; + } + + public override void OnPause(bool paused) + { + if (paused) { + // Remember the time that the behavior was paused. + pauseTime = Time.time; + } else { + // Add the difference between Time.time and pauseTime to figure out a new start time. + startTime += (Time.time - pauseTime); + } + } + + public override void OnReset() + { + // Reset the public properties back to their original values + waitTime = 1; + randomWait = false; + randomWaitMin = 1; + randomWaitMax = 1; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Actions/Wait.cs.meta b/Client/Assets/Behavior Designer/Runtime/Actions/Wait.cs.meta new file mode 100644 index 00000000..85bfa79a --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Actions/Wait.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 67824d2e00531d84db9973773e4426e9 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: -- cgit v1.1-26-g67d0