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

using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;

namespace InfinityCode.TreeTools.Editors
{
    public static class ColorPicker
    {
        private static MethodInfo method;
        private static bool isMissed;

        public static void Show(Action<Color> colorChangedCallback, Color col, bool showAlpha = true, bool hdr = false)
        {
            if (isMissed) return;

            if (method == null)
            {
                Type type = typeof(EditorGUI).Assembly.GetType("UnityEditor.ColorPicker");
                method = type.GetMethod("Show", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new[] { typeof(Action<Color>), typeof(Color), typeof(bool), typeof(bool) }, null);
                if (method == null)
                {
                    isMissed = true;
                    return;
                }
            }

            method.Invoke(null, new object[] {colorChangedCallback, col, showAlpha, hdr});
        }
    }
}