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/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 ++ 10 files changed, 356 insertions(+) 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 (limited to 'Client/Assets/Behavior Designer/Runtime/Actions/Reflection') 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: -- cgit v1.1-26-g67d0