From 97da432c35b8c7aaf9dd2c39e2aa4b1f55f36065 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 27 Jan 2021 16:15:06 +0800 Subject: +behaviour designer --- .../Runtime/Conditionals/HasReceivedEvent.cs | 102 +++++++++++++++++++++ .../Runtime/Conditionals/HasReceivedEvent.cs.meta | 8 ++ .../Runtime/Conditionals/Physics.meta | 5 + .../Conditionals/Physics/HasEnteredCollision.cs | 41 +++++++++ .../Physics/HasEnteredCollision.cs.meta | 8 ++ .../Conditionals/Physics/HasEnteredCollision2D.cs | 41 +++++++++ .../Physics/HasEnteredCollision2D.cs.meta | 8 ++ .../Conditionals/Physics/HasEnteredTrigger.cs | 41 +++++++++ .../Conditionals/Physics/HasEnteredTrigger.cs.meta | 8 ++ .../Conditionals/Physics/HasEnteredTrigger2D.cs | 41 +++++++++ .../Physics/HasEnteredTrigger2D.cs.meta | 8 ++ .../Conditionals/Physics/HasExitedCollision.cs | 40 ++++++++ .../Physics/HasExitedCollision.cs.meta | 8 ++ .../Conditionals/Physics/HasExitedCollision2D.cs | 41 +++++++++ .../Physics/HasExitedCollision2D.cs.meta | 8 ++ .../Conditionals/Physics/HasExitedTrigger.cs | 41 +++++++++ .../Conditionals/Physics/HasExitedTrigger.cs.meta | 8 ++ .../Conditionals/Physics/HasExitedTrigger2D.cs | 41 +++++++++ .../Physics/HasExitedTrigger2D.cs.meta | 8 ++ .../Runtime/Conditionals/RandomProbability.cs | 46 ++++++++++ .../Runtime/Conditionals/RandomProbability.cs.meta | 8 ++ .../Runtime/Conditionals/Reflection.meta | 5 + .../Conditionals/Reflection/CompareFieldValue.cs | 61 ++++++++++++ .../Reflection/CompareFieldValue.cs.meta | 8 ++ .../Reflection/ComparePropertyValue.cs | 61 ++++++++++++ .../Reflection/ComparePropertyValue.cs.meta | 8 ++ 26 files changed, 703 insertions(+) create mode 100644 Client/Assets/Behavior Designer/Runtime/Conditionals/HasReceivedEvent.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Conditionals/HasReceivedEvent.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Conditionals/Physics.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredCollision.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredCollision.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredCollision2D.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredCollision2D.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredTrigger.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredTrigger.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredTrigger2D.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredTrigger2D.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedCollision.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedCollision.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedCollision2D.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedCollision2D.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedTrigger.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedTrigger.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedTrigger2D.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedTrigger2D.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Conditionals/RandomProbability.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Conditionals/RandomProbability.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Conditionals/Reflection.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Conditionals/Reflection/CompareFieldValue.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Conditionals/Reflection/CompareFieldValue.cs.meta create mode 100644 Client/Assets/Behavior Designer/Runtime/Conditionals/Reflection/ComparePropertyValue.cs create mode 100644 Client/Assets/Behavior Designer/Runtime/Conditionals/Reflection/ComparePropertyValue.cs.meta (limited to 'Client/Assets/Behavior Designer/Runtime/Conditionals') diff --git a/Client/Assets/Behavior Designer/Runtime/Conditionals/HasReceivedEvent.cs b/Client/Assets/Behavior Designer/Runtime/Conditionals/HasReceivedEvent.cs new file mode 100644 index 00000000..b9c16252 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Conditionals/HasReceivedEvent.cs @@ -0,0 +1,102 @@ +using UnityEngine; + +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("Returns success as soon as the event specified by eventName has been received.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=123")] + [TaskIcon("{SkinColor}HasReceivedEventIcon.png")] + public class HasReceivedEvent : Conditional + { + [Tooltip("The name of the event to receive")] + public SharedString eventName = ""; + [Tooltip("Optionally store the first sent argument")] + [SharedRequired] + public SharedVariable storedValue1; + [Tooltip("Optionally store the second sent argument")] + [SharedRequired] + public SharedVariable storedValue2; + [Tooltip("Optionally store the third sent argument")] + [SharedRequired] + public SharedVariable storedValue3; + + private bool eventReceived = false; + + public override void OnAwake() + { + // Let the behavior tree know that we are interested in receiving the event specified + Owner.RegisterEvent(eventName.Value, ReceivedEvent); + Owner.RegisterEvent(eventName.Value, ReceivedEvent); + Owner.RegisterEvent(eventName.Value, ReceivedEvent); + Owner.RegisterEvent(eventName.Value, ReceivedEvent); + } + + public override TaskStatus OnUpdate() + { + return eventReceived ? TaskStatus.Success : TaskStatus.Failure; + } + + public override void OnEnd() + { + eventReceived = false; + } + + private void ReceivedEvent() + { + eventReceived = true; + } + + private void ReceivedEvent(object arg1) + { + ReceivedEvent(); + + if (storedValue1 != null && !storedValue1.IsNone) { + storedValue1.SetValue(arg1); + } + } + + private void ReceivedEvent(object arg1, object arg2) + { + ReceivedEvent(); + + if (storedValue1 != null && !storedValue1.IsNone) { + storedValue1.SetValue(arg1); + } + + if (storedValue2 != null && !storedValue2.IsNone) { + storedValue2.SetValue(arg2); + } + } + + private void ReceivedEvent(object arg1, object arg2, object arg3) + { + ReceivedEvent(); + + if (storedValue1 != null && !storedValue1.IsNone) { + storedValue1.SetValue(arg1); + } + + if (storedValue2 != null && !storedValue2.IsNone) { + storedValue2.SetValue(arg2); + } + + if (storedValue3 != null && !storedValue3.IsNone) { + storedValue3.SetValue(arg3); + } + } + + public override void OnBehaviorComplete() + { + // Stop receiving the event when the behavior tree is complete + Owner.UnregisterEvent(eventName.Value, ReceivedEvent); + Owner.UnregisterEvent(eventName.Value, ReceivedEvent); + Owner.UnregisterEvent(eventName.Value, ReceivedEvent); + Owner.UnregisterEvent(eventName.Value, ReceivedEvent); + } + + public override void OnReset() + { + // Reset the properties back to their original values + eventName = ""; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Conditionals/HasReceivedEvent.cs.meta b/Client/Assets/Behavior Designer/Runtime/Conditionals/HasReceivedEvent.cs.meta new file mode 100644 index 00000000..9fd1d4e1 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Conditionals/HasReceivedEvent.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7c0c7f545b074cb48bd552b038ede7af +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics.meta b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics.meta new file mode 100644 index 00000000..cdb80d4e --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2 +guid: 0c5a19b8daa7dbf4abe7505888ef0376 +folderAsset: yes +DefaultImporter: + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredCollision.cs b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredCollision.cs new file mode 100644 index 00000000..480e4093 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredCollision.cs @@ -0,0 +1,41 @@ +using UnityEngine; + +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("Returns success when a collision starts.")] + [TaskCategory("Physics")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=110")] + public class HasEnteredCollision : Conditional + { + [Tooltip("The tag of the GameObject to check for a collision against")] + public SharedString tag = ""; + [Tooltip("The object that started the collision")] + public SharedGameObject collidedGameObject; + + private bool enteredCollision = false; + + public override TaskStatus OnUpdate() + { + return enteredCollision ? TaskStatus.Success : TaskStatus.Failure; + } + + public override void OnEnd() + { + enteredCollision = false; + } + + public override void OnCollisionEnter(Collision collision) + { + if (string.IsNullOrEmpty(tag.Value) || tag.Value.Equals(collision.gameObject.tag)) { + collidedGameObject.Value = collision.gameObject; + enteredCollision = true; + } + } + + public override void OnReset() + { + tag = ""; + collidedGameObject = null; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredCollision.cs.meta b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredCollision.cs.meta new file mode 100644 index 00000000..b6f4d04b --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredCollision.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c1841a802d7ceda449423f001897ecae +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredCollision2D.cs b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredCollision2D.cs new file mode 100644 index 00000000..51feb050 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredCollision2D.cs @@ -0,0 +1,41 @@ +using UnityEngine; + +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("Returns success when a 2D collision starts.")] + [TaskCategory("Physics")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=110")] + public class HasEnteredCollision2D : Conditional + { + [Tooltip("The tag of the GameObject to check for a collision against")] + public SharedString tag = ""; + [Tooltip("The object that started the collision")] + public SharedGameObject collidedGameObject; + + private bool enteredCollision = false; + + public override TaskStatus OnUpdate() + { + return enteredCollision ? TaskStatus.Success : TaskStatus.Failure; + } + + public override void OnEnd() + { + enteredCollision = false; + } + + public override void OnCollisionEnter2D(Collision2D collision) + { + if (string.IsNullOrEmpty(tag.Value) || tag.Value.Equals(collision.gameObject.tag)) { + collidedGameObject.Value = collision.gameObject; + enteredCollision = true; + } + } + + public override void OnReset() + { + tag = ""; + collidedGameObject = null; + } + } +} diff --git a/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredCollision2D.cs.meta b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredCollision2D.cs.meta new file mode 100644 index 00000000..1f0e945e --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredCollision2D.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0ac128198630a2d4b9fee93cc9a1f8fd +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredTrigger.cs b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredTrigger.cs new file mode 100644 index 00000000..648850fd --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredTrigger.cs @@ -0,0 +1,41 @@ +using UnityEngine; + +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("Returns success when an object enters the trigger.")] + [TaskCategory("Physics")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=110")] + public class HasEnteredTrigger : Conditional + { + [Tooltip("The tag of the GameObject to check for a trigger against")] + public SharedString tag = ""; + [Tooltip("The object that entered the trigger")] + public SharedGameObject otherGameObject; + + private bool enteredTrigger = false; + + public override TaskStatus OnUpdate() + { + return enteredTrigger ? TaskStatus.Success : TaskStatus.Failure; + } + + public override void OnEnd() + { + enteredTrigger = false; + } + + public override void OnTriggerEnter(Collider other) + { + if (string.IsNullOrEmpty(tag.Value) || tag.Value.Equals(other.gameObject.tag)) { + otherGameObject.Value = other.gameObject; + enteredTrigger = true; + } + } + + public override void OnReset() + { + tag = ""; + otherGameObject = null; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredTrigger.cs.meta b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredTrigger.cs.meta new file mode 100644 index 00000000..bccb63ad --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredTrigger.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5987844efe0fca7499cec04a9e3962cc +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredTrigger2D.cs b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredTrigger2D.cs new file mode 100644 index 00000000..05dfe9ec --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredTrigger2D.cs @@ -0,0 +1,41 @@ +using UnityEngine; + +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("Returns success when an object enters the 2D trigger.")] + [TaskCategory("Physics")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=110")] + public class HasEnteredTrigger2D : Conditional + { + [Tooltip("The tag of the GameObject to check for a trigger against")] + public SharedString tag = ""; + [Tooltip("The object that entered the trigger")] + public SharedGameObject otherGameObject; + + private bool enteredTrigger = false; + + public override TaskStatus OnUpdate() + { + return enteredTrigger ? TaskStatus.Success : TaskStatus.Failure; + } + + public override void OnEnd() + { + enteredTrigger = false; + } + + public override void OnTriggerEnter2D(Collider2D other) + { + if (string.IsNullOrEmpty(tag.Value) || tag.Value.Equals(other.gameObject.tag)) { + otherGameObject.Value = other.gameObject; + enteredTrigger = true; + } + } + + public override void OnReset() + { + tag = ""; + otherGameObject = null; + } + } +} diff --git a/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredTrigger2D.cs.meta b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredTrigger2D.cs.meta new file mode 100644 index 00000000..4e98e7c7 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasEnteredTrigger2D.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 84e2afb791fe67243a15e45e4af81bb4 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedCollision.cs b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedCollision.cs new file mode 100644 index 00000000..05a4fe3d --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedCollision.cs @@ -0,0 +1,40 @@ +using UnityEngine; + +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("Returns success when a collision ends.")] + [TaskCategory("Physics")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=110")] + public class HasExitedCollision : Conditional + { + [Tooltip("The tag of the GameObject to check for a collision against")] + public SharedString tag = ""; + [Tooltip("The object that exited the collision")] + public SharedGameObject collidedGameObject; + + private bool exitedCollision = false; + + public override TaskStatus OnUpdate() + { + return exitedCollision ? TaskStatus.Success : TaskStatus.Failure; + } + + public override void OnEnd() + { + exitedCollision = false; + } + + public override void OnCollisionExit(Collision collision) + { + if (string.IsNullOrEmpty(tag.Value) || tag.Value.Equals(collision.gameObject.tag)) { + collidedGameObject.Value = collision.gameObject; + exitedCollision = true; + } + } + + public override void OnReset() + { + collidedGameObject = null; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedCollision.cs.meta b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedCollision.cs.meta new file mode 100644 index 00000000..40e22c8b --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedCollision.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 900905a3e42f74c49a6e503349ee651e +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedCollision2D.cs b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedCollision2D.cs new file mode 100644 index 00000000..e5a1a03a --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedCollision2D.cs @@ -0,0 +1,41 @@ +using UnityEngine; + +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("Returns success when a 2D collision ends.")] + [TaskCategory("Physics")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=110")] + public class HasExitedCollision2D : Conditional + { + [Tooltip("The tag of the GameObject to check for a collision against")] + public SharedString tag = ""; + [Tooltip("The object that exited the collision")] + public SharedGameObject collidedGameObject; + + private bool exitedCollision = false; + + public override TaskStatus OnUpdate() + { + return exitedCollision ? TaskStatus.Success : TaskStatus.Failure; + } + + public override void OnEnd() + { + exitedCollision = false; + } + + public override void OnCollisionExit2D(Collision2D collision) + { + if (string.IsNullOrEmpty(tag.Value) || tag.Value.Equals(collision.gameObject.tag)) { + collidedGameObject.Value = collision.gameObject; + exitedCollision = true; + } + } + + public override void OnReset() + { + tag = ""; + collidedGameObject = null; + } + } +} diff --git a/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedCollision2D.cs.meta b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedCollision2D.cs.meta new file mode 100644 index 00000000..48510c2a --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedCollision2D.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 31cf8edd114ac5c4db22ec65babb3dd3 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedTrigger.cs b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedTrigger.cs new file mode 100644 index 00000000..ec33e923 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedTrigger.cs @@ -0,0 +1,41 @@ +using UnityEngine; + +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("Returns success when an object exits the trigger.")] + [TaskCategory("Physics")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=110")] + public class HasExitedTrigger : Conditional + { + [Tooltip("The tag of the GameObject to check for a trigger against")] + public SharedString tag = ""; + [Tooltip("The object that exited the trigger")] + public SharedGameObject otherGameObject; + + private bool exitedTrigger = false; + + public override TaskStatus OnUpdate() + { + return exitedTrigger ? TaskStatus.Success : TaskStatus.Failure; + } + + public override void OnEnd() + { + exitedTrigger = false; + } + + public override void OnTriggerExit(Collider other) + { + if (string.IsNullOrEmpty(tag.Value) || tag.Value.Equals(other.gameObject.tag)) { + otherGameObject.Value = other.gameObject; + exitedTrigger = true; + } + } + + public override void OnReset() + { + tag = ""; + otherGameObject = null; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedTrigger.cs.meta b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedTrigger.cs.meta new file mode 100644 index 00000000..83c2828f --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedTrigger.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c7ccd4a2c35d4c748b65ccd086e777e1 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedTrigger2D.cs b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedTrigger2D.cs new file mode 100644 index 00000000..95ad2f1a --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedTrigger2D.cs @@ -0,0 +1,41 @@ +using UnityEngine; + +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("Returns success when an object exits the 2D trigger.")] + [TaskCategory("Physics")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=110")] + public class HasExitedTrigger2D : Conditional + { + [Tooltip("The tag of the GameObject to check for a trigger against")] + public SharedString tag = ""; + [Tooltip("The object that exited the trigger")] + public SharedGameObject otherGameObject; + + private bool exitedTrigger = false; + + public override TaskStatus OnUpdate() + { + return exitedTrigger ? TaskStatus.Success : TaskStatus.Failure; + } + + public override void OnEnd() + { + exitedTrigger = false; + } + + public override void OnTriggerExit2D(Collider2D other) + { + if (string.IsNullOrEmpty(tag.Value) || tag.Value.Equals(other.gameObject.tag)) { + otherGameObject.Value = other.gameObject; + exitedTrigger = true; + } + } + + public override void OnReset() + { + tag = ""; + otherGameObject = null; + } + } +} diff --git a/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedTrigger2D.cs.meta b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedTrigger2D.cs.meta new file mode 100644 index 00000000..3d6d4f8a --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Conditionals/Physics/HasExitedTrigger2D.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ff0486d46da2f7844ac74c6e2ad5af89 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Conditionals/RandomProbability.cs b/Client/Assets/Behavior Designer/Runtime/Conditionals/RandomProbability.cs new file mode 100644 index 00000000..a4c48c6f --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Conditionals/RandomProbability.cs @@ -0,0 +1,46 @@ +using UnityEngine; + +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("The random probability task will return success when the random probability is above the succeed probability. It will otherwise return failure.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=33")] + public class RandomProbability : Conditional + { + [Tooltip("The chance that the task will return success")] + public SharedFloat successProbability = 0.5f; + [Tooltip("Seed the random number generator to make things easier to debug")] + public SharedInt seed; + [Tooltip("Do we want to use the seed?")] + public SharedBool useSeed; + + private System.Random random; + + public override void OnAwake() + { + // If specified, use the seed provided. + if (useSeed.Value) { + random = new System.Random(seed.Value); + } else { + random = new System.Random(); + } + } + + public override TaskStatus OnUpdate() + { + // Return success if random value is less than the success probability. Otherwise return failure. + float randomValue = (float)random.NextDouble(); + if (randomValue < successProbability.Value) { + return TaskStatus.Success; + } + return TaskStatus.Failure; + } + + public override void OnReset() + { + // Reset the public properties back to their original values + successProbability = 0.5f; + seed = 0; + useSeed = false; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Conditionals/RandomProbability.cs.meta b/Client/Assets/Behavior Designer/Runtime/Conditionals/RandomProbability.cs.meta new file mode 100644 index 00000000..85b11855 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Conditionals/RandomProbability.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 468a21510e9558c49a47238ebe4c2270 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Conditionals/Reflection.meta b/Client/Assets/Behavior Designer/Runtime/Conditionals/Reflection.meta new file mode 100644 index 00000000..8e65537d --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Conditionals/Reflection.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2 +guid: caf1fead4d83193488aaa4560c36880c +folderAsset: yes +DefaultImporter: + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Conditionals/Reflection/CompareFieldValue.cs b/Client/Assets/Behavior Designer/Runtime/Conditionals/Reflection/CompareFieldValue.cs new file mode 100644 index 00000000..d66bf706 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Conditionals/Reflection/CompareFieldValue.cs @@ -0,0 +1,61 @@ +using UnityEngine; +using System; +using System.Reflection; + +namespace BehaviorDesigner.Runtime.Tasks +{ + [TaskDescription("Compares the field value to the value specified. Returns success if the values are the same.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=151")] + [TaskCategory("Reflection")] + [TaskIcon("{SkinColor}ReflectionIcon.png")] + public class CompareFieldValue : Conditional + { + [Tooltip("The GameObject to compare the field on")] + public SharedGameObject targetGameObject; + [Tooltip("The component to compare the field on")] + public SharedString componentName; + [Tooltip("The name of the field")] + public SharedString fieldName; + [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 field - type is null"); + return TaskStatus.Failure; + } + + var component = GetDefaultGameObject(targetGameObject.Value).GetComponent(type); + if (component == null) { + Debug.LogWarning("Unable to compare 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); + var fieldValue = field.GetValue(component); + + if (fieldValue == null && compareValue.GetValue() == null) { + return TaskStatus.Success; + } + + return fieldValue.Equals(compareValue.GetValue()) ? TaskStatus.Success : TaskStatus.Failure; + } + + public override void OnReset() + { + targetGameObject = null; + componentName = null; + fieldName = null; + compareValue = null; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Behavior Designer/Runtime/Conditionals/Reflection/CompareFieldValue.cs.meta b/Client/Assets/Behavior Designer/Runtime/Conditionals/Reflection/CompareFieldValue.cs.meta new file mode 100644 index 00000000..42f0e6bb --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Conditionals/Reflection/CompareFieldValue.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: cc6496fb6757b684c8cc0c4ac8929319 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Behavior Designer/Runtime/Conditionals/Reflection/ComparePropertyValue.cs b/Client/Assets/Behavior Designer/Runtime/Conditionals/Reflection/ComparePropertyValue.cs new file mode 100644 index 00000000..4f7fbdf1 --- /dev/null +++ b/Client/Assets/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 diff --git a/Client/Assets/Behavior Designer/Runtime/Conditionals/Reflection/ComparePropertyValue.cs.meta b/Client/Assets/Behavior Designer/Runtime/Conditionals/Reflection/ComparePropertyValue.cs.meta new file mode 100644 index 00000000..59fbef22 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Conditionals/Reflection/ComparePropertyValue.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f8b0fa403f826a74087ece4b81fec1c7 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: -- cgit v1.1-26-g67d0