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

using InfinityCode.uPano;
using InfinityCode.uPano.Controls;
using UnityEngine;

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

        public FsmBool compass = false;
        public FsmBool gyro = false;
        public FsmBool joystick = false;
        public FsmBool keyboard = false;
        public FsmBool mouse = false;


        public override void Reset()
        {
            panorama = null;
            compass = false;
            gyro = false;
            joystick = false;
            keyboard = false;
            mouse = 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 (compass.Value) go.AddComponent<CompassControl>();
            if (gyro.Value) go.AddComponent<GyroControl>();
            if (joystick.Value) go.AddComponent<JoystickControl>();
            if (keyboard.Value) go.AddComponent<KeyboardControl>();
            if (mouse.Value) go.AddComponent<MouseControl>();
        }
    }
}