diff options
Diffstat (limited to 'Client/Assets/Behavior Designer/Runtime/Basic Tasks/Math/FloatOperator.cs')
-rw-r--r-- | Client/Assets/Behavior Designer/Runtime/Basic Tasks/Math/FloatOperator.cs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/Client/Assets/Behavior Designer/Runtime/Basic Tasks/Math/FloatOperator.cs b/Client/Assets/Behavior Designer/Runtime/Basic Tasks/Math/FloatOperator.cs new file mode 100644 index 00000000..9c4b249f --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Basic Tasks/Math/FloatOperator.cs @@ -0,0 +1,61 @@ +using UnityEngine;
+
+namespace BehaviorDesigner.Runtime.Tasks.Basic.Math
+{
+ [TaskCategory("Basic/Math")]
+ [TaskDescription("Performs a math operation on two floats: Add, Subtract, Multiply, Divide, Min, or Max.")]
+ public class FloatOperator : Action
+ {
+ public enum Operation
+ {
+ Add,
+ Subtract,
+ Multiply,
+ Divide,
+ Min,
+ Max
+ }
+
+ [Tooltip("The operation to perform")]
+ public Operation operation;
+ [Tooltip("The first float")]
+ public SharedFloat float1;
+ [Tooltip("The second float")]
+ public SharedFloat float2;
+ [Tooltip("The variable to store the result")]
+ public SharedFloat storeResult;
+
+ public override TaskStatus OnUpdate()
+ {
+ switch (operation) {
+ case Operation.Add:
+ storeResult.Value = float1.Value + float2.Value;
+ break;
+ case Operation.Subtract:
+ storeResult.Value = float1.Value - float2.Value;
+ break;
+ case Operation.Multiply:
+ storeResult.Value = float1.Value * float2.Value;
+ break;
+ case Operation.Divide:
+ storeResult.Value = float1.Value / float2.Value;
+ break;
+ case Operation.Min:
+ storeResult.Value = Mathf.Min(float1.Value, float2.Value);
+ break;
+ case Operation.Max:
+ storeResult.Value = Mathf.Max(float1.Value, float2.Value);
+ break;
+ }
+ return TaskStatus.Success;
+ }
+
+ public override void OnReset()
+ {
+ operation = Operation.Add;
+ float1.Value = 0;
+ float2.Value = 0;
+ storeResult.Value = 0;
+ }
+ }
+}
\ No newline at end of file |