summaryrefslogtreecommitdiff
path: root/Client/Assets/Behavior Designer/Runtime/Basic Tasks/Behaviour/IsEnabled.cs
blob: 78fb031f2879eef5483260cf266db48ab48d1766 (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
using UnityEngine;

namespace BehaviorDesigner.Runtime.Tasks.Basic.UnityBehaviour
{
    [TaskCategory("Basic/Behaviour")]
    [TaskDescription("Returns Success if the object is enabled, otherwise Failure.")]
    public class IsEnabled : Conditional
    {
        [Tooltip("The Object to use")]
        public SharedObject specifiedObject;

        public override TaskStatus OnUpdate()
        {
            if (specifiedObject == null && !(specifiedObject.Value is UnityEngine.Behaviour)) {
                Debug.LogWarning("SpecifiedObject is null or not a subclass of UnityEngine.Behaviour");
                return TaskStatus.Failure;
            }

            return (specifiedObject.Value as Behaviour).enabled ? TaskStatus.Success : TaskStatus.Failure;
        }

        public override void OnReset()
        {
            if (specifiedObject != null) {
                specifiedObject.Value = null;
            }
        }
    }
}