arthurdiniz0_outer-math/OuterMath Unity Project/Assets/PlayMaker/Actions/Array/ArrayClear.cs
// (c) Copyright HutongGames, LLC 2010-2014. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(ActionCategory.Array)]
    [Tooltip("Sets all items in an Array to their default value: 0, empty string, false, or null depending on their type. Optionally defines a reset value to use.")]
    public class ArrayClear : FsmStateAction
    {
        [UIHint(UIHint.Variable)] 
        [Tooltip("The Array Variable to clear.")] 
        public FsmArray array;

        [MatchElementType("array")] 
        [Tooltip("Optional reset value. Leave as None for default value.")] 
        public FsmVar resetValue;

        public override void Reset()
        {
            array = null;
            resetValue = new FsmVar {useVariable = true};
        }

        public override void OnEnter()
        {
            int count = array.Length;

            array.Reset();
            array.Resize(count);

            if (!resetValue.IsNone)
            {
                resetValue.UpdateValue();
                object _val = resetValue.GetValue();
                for (int i = 0; i < count; i++)
                {
                    array.Set(i, _val);
                }
            }
            Finish();
        }


#if UNITY_EDITOR
        public override string AutoName()
        {
            return ActionHelpers.AutoName(this, array);
        }
#endif
    }
}