summaryrefslogtreecommitdiff
path: root/Assets/ThirdParty/Behavior Designer/Runtime/Conditionals/Reflection/ComparePropertyValue.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-09-08 10:52:35 +0800
committerchai <chaifix@163.com>2021-09-08 10:52:35 +0800
commit21e186f75b504d832d9c7bef0456edd7d5d3155e (patch)
treee73c43fc78d0326f32da5fadfda57fa8e23c1d90 /Assets/ThirdParty/Behavior Designer/Runtime/Conditionals/Reflection/ComparePropertyValue.cs
parent7bd7b4c6c3be6840cab06aa4d8a38619bce44705 (diff)
+behavior design
Diffstat (limited to 'Assets/ThirdParty/Behavior Designer/Runtime/Conditionals/Reflection/ComparePropertyValue.cs')
-rw-r--r--Assets/ThirdParty/Behavior Designer/Runtime/Conditionals/Reflection/ComparePropertyValue.cs61
1 files changed, 61 insertions, 0 deletions
diff --git a/Assets/ThirdParty/Behavior Designer/Runtime/Conditionals/Reflection/ComparePropertyValue.cs b/Assets/ThirdParty/Behavior Designer/Runtime/Conditionals/Reflection/ComparePropertyValue.cs
new file mode 100644
index 00000000..4f7fbdf1
--- /dev/null
+++ b/Assets/ThirdParty/Behavior Designer/Runtime/Conditionals/Reflection/ComparePropertyValue.cs
@@ -0,0 +1,61 @@
+using UnityEngine;
+using System;
+using System.Reflection;
+
+namespace BehaviorDesigner.Runtime.Tasks
+{
+ [TaskDescription("Compares the property value to the value specified. Returns success if the values are the same.")]
+ [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=152")]
+ [TaskCategory("Reflection")]
+ [TaskIcon("{SkinColor}ReflectionIcon.png")]
+ public class ComparePropertyValue : Conditional
+ {
+ [Tooltip("The GameObject to compare the property of")]
+ public SharedGameObject targetGameObject;
+ [Tooltip("The component to compare the property of")]
+ public SharedString componentName;
+ [Tooltip("The name of the property")]
+ public SharedString propertyName;
+ [Tooltip("The value to compare to")]
+ public SharedVariable compareValue;
+
+ public override TaskStatus OnUpdate()
+ {
+ if (compareValue == null) {
+ Debug.LogWarning("Unable to compare field - compare value is null");
+ return TaskStatus.Failure;
+ }
+
+ var type = TaskUtility.GetTypeWithinAssembly(componentName.Value);
+ if (type == null) {
+ Debug.LogWarning("Unable to compare property - type is null");
+ return TaskStatus.Failure;
+ }
+
+ var component = GetDefaultGameObject(targetGameObject.Value).GetComponent(type);
+ if (component == null) {
+ Debug.LogWarning("Unable to compare 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);
+ var propertyValue = property.GetValue(component, null);
+
+ if (propertyValue == null && compareValue.GetValue() == null) {
+ return TaskStatus.Success;
+ }
+
+ return propertyValue.Equals(compareValue.GetValue()) ? TaskStatus.Success : TaskStatus.Failure;
+ }
+
+ public override void OnReset()
+ {
+ targetGameObject = null;
+ componentName = null;
+ propertyName = null;
+ compareValue = null;
+ }
+ }
+} \ No newline at end of file