﻿using OnlineMaps;
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(OnlineMapsCategories.MARKERS)]
    [Tooltip("Get the count of 2D markers.")]
    public class Get3DMarkersCount : FsmStateAction
    {
        [UIHint(UIHint.Variable)]
        [Tooltip("Count of 3D markers.")]
        public FsmInt storeMarkersCount;

        public override void Reset()
        {
            storeMarkersCount = null;
        }

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

        private void DoEnter()
        {
            if (!Map.instance)
            {
                Debug.LogError("Online Maps not found.");
                return;
            }

            if (!ControlBase3D.instance)
            {
                Debug.LogError("OnlineMapsControlBase3D not found.");
                return;
            }

            storeMarkersCount.Value = ControlBase3D.instance.marker3DManager.count;
        }
    }
}