/*           INFINITY CODE           */
/*     https://infinity-code.com     */

using InfinityCode.uPano;
using InfinityCode.uPano.Plugins;
using UnityEngine;

namespace HutongGames.PlayMaker.Actions.uPano
{
    [ActionCategory(uPanoCategories.PANORAMA)]
    [Tooltip("Add plugins to the panorama")]
    public class AddPlugins : FsmPanoStateAction
    {
        [RequiredField]
        public FsmObject panorama;

        public FsmBool autoRotate = false;
        public FsmBool limits = false;

        public override void Reset()
        {
            panorama = null;
            autoRotate = false;
            limits = false;
        }

        public override void OnEnter()
        {
            DoEnter();
            Finish();
        }

        private void DoEnter()
        {
            if (panorama.IsNone)
            {
                Debug.LogError("Requires reference to a panorama or Pano Renderer");
                return;
            }

            Pano pano = GetPano(panorama);
            if (pano == null)
            {
                Debug.LogError("Panorama field should contain a reference to a panorama or Pano Renderer");
                return;
            }

            GameObject go = pano.gameObject;

            if (autoRotate.Value) go.AddComponent<AutoRotate>();
            if (limits.Value) go.AddComponent<Limits>();
        }
    }
}