using UnityEditor;
using UnityEngine;

namespace XRTool.Util
{
    [InitializeOnLoad]
    [CustomEditor(typeof(MultTextHelper))]
    public class MultTextHelperEditor : Editor
    {
        private SerializedProperty isClearOnNothing;
        //private SerializedProperty languageNum;
        private MultTextHelper textHelper;
        //private SerializedProperty languageIndex;
        //private int minNum, maxNum;
        private int languageIndex;
        private string languageNum;
        private void OnEnable()
        {
            isClearOnNothing = serializedObject.FindProperty("isClearOnNothing");
            //languageIndex = serializedObject.FindProperty("languageIndex");
            textHelper = target as MultTextHelper;
            languageNum = textHelper.LanguageNum.ToString();
            if (textHelper.Label)
            {
            }
            languageIndex = LanguageMgr.Instance.LanIndex;
            //textHelper.AutoGetComponent();
            //int.TryParse(languageNum, out num);
            if (LanguageMgr.Instance.CurLanguage == null)
            {
                LanguageMgr.Instance.SelectLanguage(0);
                UnityLog.LogError("当前语言为空");
            }
        }
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            EditorGUILayout.PropertyField(isClearOnNothing, new GUIContent("无编号时清除"));
            //EditorGUILayout.PropertyField(languageIndex, new GUIContent("中英文"));
            languageNum = EditorGUILayout.TextField("文字编号", languageNum);

            languageIndex = (int)EditorGUILayout.Slider("语言", languageIndex,
                0, LanguageMgr.Instance.LanguageCount);
            serializedObject.ApplyModifiedProperties();
            if (GUI.changed)
            {
                if (languageNum != textHelper.LanguageNum.ToString())
                {
                    //textHelper.languageNum = num.ToString();
                    textHelper.SetLanuageNum(languageNum);
                }
                if (languageIndex != LanguageMgr.Instance.LanIndex)
                {
                    LanguageMgr.Instance.SelectLanguage(languageIndex);
                }
            }
        }
    }
}