using System;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;

namespace Pursuit.Singletons.Prefabs
{
    public class DebugDrawer : SingletonPrefab<DebugDrawer>
    {
        private readonly List<Action> actionList = new();
        private int lastFrame = -1;

        private void OnDrawGizmos()
        {
            foreach (Action action in actionList) action.Invoke();
        }

        [Conditional("UNITY_EDITOR")]
        public void RequestAction(Action action)
        {
            if (Time.frameCount != lastFrame)
            {
                actionList.Clear();
                lastFrame = Time.frameCount;
            }

            actionList.Add(action);
        }
    }
}