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

using System.IO;
using UnityEditor;
using UnityEngine;

namespace InfinityCode.TreeTools.Editors
{
    public static class Utils
    {
        private static string _assetFolder;
        private static GUIStyle _centeredLabel;

        public static string assetFolder
        {
            get
            {
                if (string.IsNullOrEmpty(_assetFolder))
                {
                    string[] paths = Directory.GetFiles(Application.dataPath, "TreeTool.asmdef", SearchOption.AllDirectories);
                    if (paths.Length != 0)
                    {
                        FileInfo info = new FileInfo(paths[0]);
                        _assetFolder = info.Directory.Parent.Parent.FullName.Substring(Application.dataPath.Length - 6) + "/";
                    }
                    else
                    {
                        _assetFolder = "Assets/Plugins/Infinity Code/Tree Tool/";
                    }
                }

                return _assetFolder;
            }
        }

        public static GUIStyle centeredLabel
        {
            get
            {
                if (_centeredLabel == null)
                {
                    _centeredLabel = new GUIStyle(EditorStyles.label)
                    {
                        alignment = TextAnchor.MiddleCenter
                    };
                }

                return _centeredLabel;
            }
        }

        public static bool Is01(float a)
        {
            return a > 0 && a < 1;
        }
    }
}