arthurdiniz0_outer-math/OuterMath Unity Project/Assets/PlayMaker/Actions/SpriteRenderer/GetSpriteSortingLayer.cs
// (c) Copyright HutongGames, LLC 2010-2019. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(ActionCategory.SpriteRenderer)]
    [Tooltip("Get the Sorting Layer name and/or Id of a of a SpriteRenderer component.")]
    public class GetSpriteSortingLayer : ComponentAction<SpriteRenderer>
    {
        [RequiredField]
        [CheckForComponent(typeof(SpriteRenderer))]
        [Tooltip("The GameObject with the SpriteRenderer component.")]
        public FsmOwnerDefault gameObject;

        [UIHint(UIHint.Variable)]
        [Tooltip("The sorting layer name")]
        public FsmString sortingLayerName;

        [UIHint(UIHint.Variable)]
        [Tooltip("The sorting layer id")]
        public FsmInt sortingLayerId;

        public override void Reset()
        {
            gameObject = null;
            sortingLayerName = null;
            sortingLayerId = null;
        }

        public override void OnEnter()
        {
            if (!UpdateCache(Fsm.GetOwnerDefaultTarget(gameObject)))
            {
                return;
            }

            if (!sortingLayerName.IsNone) sortingLayerName.Value = cachedComponent.sortingLayerName;
            if (!sortingLayerId.IsNone) sortingLayerId.Value = cachedComponent.sortingLayerID;

            Finish();
        }
    }
}
