MultTextHelperEditor.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using UnityEditor;
  2. using UnityEngine;
  3. namespace XRTool.Util
  4. {
  5. [InitializeOnLoad]
  6. [CustomEditor(typeof(MultTextHelper))]
  7. public class MultTextHelperEditor : Editor
  8. {
  9. private SerializedProperty isClearOnNothing;
  10. //private SerializedProperty languageNum;
  11. private MultTextHelper textHelper;
  12. //private SerializedProperty languageIndex;
  13. private int num;
  14. private int minNum, maxNum;
  15. private void OnEnable()
  16. {
  17. isClearOnNothing = serializedObject.FindProperty("isClearOnNothing");
  18. //languageIndex = serializedObject.FindProperty("languageIndex");
  19. textHelper = target as MultTextHelper;
  20. textHelper.languageIndex = SystemSettingMgr.Instance.settings.Language;
  21. textHelper.AutoGetComponent();
  22. int.TryParse(textHelper.languageNum, out num);
  23. if (LanguageMgr.Instance.CurLanguage != null)
  24. {
  25. minNum = LanguageMgr.Instance.CurLanguage.GetMin();
  26. maxNum = LanguageMgr.Instance.CurLanguage.GetMax();
  27. }
  28. }
  29. public override void OnInspectorGUI()
  30. {
  31. base.OnInspectorGUI();
  32. EditorGUILayout.PropertyField(isClearOnNothing, new GUIContent("无编号时清除"));
  33. //EditorGUILayout.PropertyField(languageIndex, new GUIContent("中英文"));
  34. num = (int)EditorGUILayout.Slider("文字编号", num, minNum-1, maxNum);
  35. textHelper.languageIndex = (int)EditorGUILayout.Slider("语言", textHelper.languageIndex,
  36. 0, LanguageMgr.Instance.LanguageCount);
  37. serializedObject.ApplyModifiedProperties();
  38. if (GUI.changed)
  39. {
  40. if (textHelper.languageNum != num.ToString())
  41. {
  42. textHelper.languageNum = num.ToString();
  43. if (textHelper)
  44. {
  45. textHelper.SetLanuageNum(textHelper.languageNum);
  46. }
  47. }
  48. if (textHelper.languageIndex != SystemSettingMgr.Instance.settings.Language)
  49. {
  50. LanguageMgr.Instance.SelectLanguage(textHelper.languageIndex);
  51. }
  52. }
  53. }
  54. }
  55. }