﻿using System;
using UnityEditor;
using UnityEngine;

namespace UGCTools.Editor
{
    public static class Styles
    {
        public static Color tabViewBackGroundColor = new Color(0.24f, 0.49f, 0.91f);
        public static Color normalBackGroundColor = new Color(0.76f, 0.76f, 0.76f);
        public static Color headColor = new Color(0.24f, 0.49f, 0.91f);

        public static GUIStyle logoFont;
        public static GUIStyle head1Font;
        public static GUIStyle versionFont;

        public static GUIStyle tabViewboxStyle;

        public static GUIStyle selectedTabView;
        public static GUIStyle unSelectedTabView;

        public static GUIStyle buttonLeft;
        public static GUIStyle buttonMid;
        public static GUIStyle buttonRight;

        public const int kSubMeshButtonWitdh = 30;
        public static string[] subMeshLabels = new string[32];

        public static Color foldoutTintColor;

        static Styles()
        {
            logoFont = new GUIStyle(EditorStyles.label);
            logoFont.alignment = TextAnchor.MiddleCenter;
            logoFont.fontSize = 64;

            head1Font = new GUIStyle(EditorStyles.label);
            head1Font.alignment = TextAnchor.MiddleLeft;
            head1Font.fontStyle = FontStyle.Bold;
            head1Font.fontSize = 18;

            versionFont = new GUIStyle(EditorStyles.label);
            versionFont.alignment = TextAnchor.UpperRight;
            versionFont.fontSize = 18;


            buttonLeft = GUI.skin.GetStyle("buttonLeft");
            buttonMid = GUI.skin.GetStyle("buttonMid");
            buttonRight = GUI.skin.GetStyle("buttonRight");

            tabViewboxStyle = new GUIStyle(EditorStyles.helpBox);

            selectedTabView = new GUIStyle(EditorStyles.toolbarButton);
            selectedTabView.normal.textColor = Color.white;
            selectedTabView.normal.background = MakeTex(2, 2, tabViewBackGroundColor);

            unSelectedTabView = new GUIStyle(EditorStyles.toolbarButton);
            unSelectedTabView.normal.textColor = Color.gray;
            selectedTabView.normal.background = MakeTex(2, 2, normalBackGroundColor);

            for (int i = 0; i < 32; i++)
                subMeshLabels[i] = "#" + i.ToString();

            foldoutTintColor = EditorGUIUtility.isProSkin
                ? new Color(1f, 1f, 1f, 0.05f) : new Color(0f, 0f, 0f, 0.05f);
        }

        // 创建一个纯色纹理
        private static Texture2D MakeTex(int width, int height, Color col)
        {
            Color[] pix = new Color[width * height];
            for (int i = 0; i < pix.Length; i++)
            {
                pix[i] = col;
            }
            Texture2D result = new Texture2D(width, height);
            result.SetPixels(pix);
            result.Apply();
            return result;
        }
    }
}