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

using InfinityCode.uPano.HotSpots;
using UnityEngine;

namespace HutongGames.PlayMaker.Actions.uPano.HotSpots
{
    [ActionCategory(uPanoCategories.HOTSPOTS)]
    [Tooltip("Sets pan and tilt for HotSpot")]
    public class SetPanTilt : FsmStateAction
    {
        [RequiredField]
        public FsmObject hotSpot;

        [RequiredField]
        public FsmFloat pan;

        [RequiredField]
        public FsmFloat tilt;

        public override void Reset()
        {
            hotSpot = null;
            pan = 0;
            tilt = 0;
        }

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

        private void DoEnter()
        {
            if (hotSpot.IsNone)
            {
                Debug.LogError("Requires reference to Hot Spot");
                return;
            }

            ObjectWrapper w = hotSpot.Value as ObjectWrapper;
            if (w == null || !(w.obj is HotSpot))
            {
                Debug.LogError("Requires reference to Hot Spot");
                return;
            }

            HotSpot hs = w.obj as HotSpot;
            hs.SetPanTilt(pan.Value, tilt.Value);
        }
    }
}