summaryrefslogtreecommitdiff
path: root/Client/Assets/Behavior Designer/Runtime/Basic Tasks/Math/IntComparison.cs
blob: bcef3078b1c840cbf3201f957d00f70611ea114e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using UnityEngine;

namespace BehaviorDesigner.Runtime.Tasks.Basic.Math
{
    [TaskCategory("Basic/Math")]
    [TaskDescription("Performs comparison between two integers: less than, less than or equal to, equal to, not equal to, greater than or equal to, or greater than.")]
    public class IntComparison : Conditional
    {
        public enum Operation
        {
            LessThan,
            LessThanOrEqualTo,
            EqualTo,
            NotEqualTo,
            GreaterThanOrEqualTo,
            GreaterThan
        }

        [Tooltip("The operation to perform")]
        public Operation operation;
        [Tooltip("The first integer")]
        public SharedInt integer1;
        [Tooltip("The second integer")]
        public SharedInt integer2;

        public override TaskStatus OnUpdate()
        {
            switch (operation) {
                case Operation.LessThan:
                    return integer1.Value < integer2.Value ? TaskStatus.Success : TaskStatus.Failure;
                case Operation.LessThanOrEqualTo:
                    return integer1.Value <= integer2.Value ? TaskStatus.Success : TaskStatus.Failure;
                case Operation.EqualTo:
                    return integer1.Value == integer2.Value ? TaskStatus.Success : TaskStatus.Failure;
                case Operation.NotEqualTo:
                    return integer1.Value != integer2.Value ? TaskStatus.Success : TaskStatus.Failure;
                case Operation.GreaterThanOrEqualTo:
                    return integer1.Value >= integer2.Value ? TaskStatus.Success : TaskStatus.Failure;
                case Operation.GreaterThan:
                    return integer1.Value > integer2.Value ? TaskStatus.Success : TaskStatus.Failure;
            }
            return TaskStatus.Failure;
        }

        public override void OnReset()
        {
            operation = Operation.LessThan;
            integer1.Value = 0;
            integer2.Value = 0;
        }
    }
}