playMaker

Author Topic: ObjectIsNull  (Read 3259 times)

Zyxil

  • Playmaker Newbie
  • *
  • Posts: 10
ObjectIsNull
« on: May 09, 2012, 10:28:33 PM »
Not rocket science, just a copy of GameObjectIsNull with the GO switched to Object.

Code: [Select]
namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(ActionCategory.Logic)]
    [Tooltip("Tests if an Object Variable has a null value.")]
    public class ObjectIsNull : FsmStateAction
    {
        [RequiredField]
        [UIHint(UIHint.Variable)]
        public FsmObject theObject;
        public FsmEvent isNull;
        public FsmEvent isNotNull;
        [UIHint(UIHint.Variable)]
        public FsmBool storeResult;
        public bool everyFrame;

        public override void Reset()
        {
            theObject = null;
            isNull = null;
            isNotNull = null;
            storeResult = null;
            everyFrame = false;
        }

        public override void OnEnter()
        {
            DoIsObjectNull();

            if (!everyFrame)
                Finish();
        }

        public override void OnUpdate()
        {
            DoIsObjectNull();
        }

        void DoIsObjectNull()
        {
            bool oIsNull = theObject == null;

            if (storeResult != null)
                storeResult.Value = oIsNull;

            Fsm.Event(oIsNull ? isNull : isNotNull);
        }
    }
}