From 97da432c35b8c7aaf9dd2c39e2aa4b1f55f36065 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 27 Jan 2021 16:15:06 +0800 Subject: +behaviour designer --- .../Runtime/Basic Tasks/Math/IntOperator.cs | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Client/Assets/Behavior Designer/Runtime/Basic Tasks/Math/IntOperator.cs (limited to 'Client/Assets/Behavior Designer/Runtime/Basic Tasks/Math/IntOperator.cs') diff --git a/Client/Assets/Behavior Designer/Runtime/Basic Tasks/Math/IntOperator.cs b/Client/Assets/Behavior Designer/Runtime/Basic Tasks/Math/IntOperator.cs new file mode 100644 index 00000000..4805508e --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Basic Tasks/Math/IntOperator.cs @@ -0,0 +1,62 @@ +using UnityEngine; + +namespace BehaviorDesigner.Runtime.Tasks.Basic.Math +{ + [TaskCategory("Basic/Math")] + [TaskDescription("Performs a math operation on two integers: Add, Subtract, Multiply, Divide, Min, or Max.")] + public class IntOperator : Action + { + public enum Operation + { + Add, + Subtract, + Multiply, + Divide, + Min, + Max + } + + [Tooltip("The operation to perform")] + public Operation operation; + [Tooltip("The first integer")] + public SharedInt integer1; + [Tooltip("The second integer")] + public SharedInt integer2; + [RequiredField] + [Tooltip("The variable to store the result")] + public SharedInt storeResult; + + public override TaskStatus OnUpdate() + { + switch (operation) { + case Operation.Add: + storeResult.Value = integer1.Value + integer2.Value; + break; + case Operation.Subtract: + storeResult.Value = integer1.Value - integer2.Value; + break; + case Operation.Multiply: + storeResult.Value = integer1.Value * integer2.Value; + break; + case Operation.Divide: + storeResult.Value = integer1.Value / integer2.Value; + break; + case Operation.Min: + storeResult.Value = Mathf.Min(integer1.Value, integer2.Value); + break; + case Operation.Max: + storeResult.Value = Mathf.Max(integer1.Value, integer2.Value); + break; + } + return TaskStatus.Success; + } + + public override void OnReset() + { + operation = Operation.Add; + integer1.Value = 0; + integer2.Value = 0; + storeResult.Value = 0; + } + } +} \ No newline at end of file -- cgit v1.1-26-g67d0