SettingComponentInspector.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //------------------------------------------------------------
  2. // Game Framework
  3. // Copyright © 2013-2021 loyalsoft. All rights reserved.
  4. // Homepage: http://www.game7000.com/
  5. // Feedback: http://www.game7000.com/
  6. //------------------------------------------------------------
  7. using UnityEditor;
  8. using UnityEngine;
  9. using UnityGameFramework.Runtime;
  10. namespace UnityGameFramework.Editor
  11. {
  12. [CustomEditor(typeof(SettingComponent))]
  13. internal sealed class SettingComponentInspector : GameFrameworkInspector
  14. {
  15. private HelperInfo<SettingHelperBase> m_SettingHelperInfo = new HelperInfo<SettingHelperBase>("Setting");
  16. public override void OnInspectorGUI()
  17. {
  18. base.OnInspectorGUI();
  19. SettingComponent t = (SettingComponent)target;
  20. EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode);
  21. {
  22. m_SettingHelperInfo.Draw();
  23. }
  24. EditorGUI.EndDisabledGroup();
  25. if (EditorApplication.isPlaying && IsPrefabInHierarchy(t.gameObject))
  26. {
  27. EditorGUILayout.LabelField("Setting Count", t.Count >= 0 ? t.Count.ToString() : "<Unknown>");
  28. if (t.Count > 0)
  29. {
  30. string[] settingNames = t.GetAllSettingNames();
  31. foreach (string settingName in settingNames)
  32. {
  33. EditorGUILayout.LabelField(settingName, t.GetString(settingName));
  34. }
  35. }
  36. }
  37. if (EditorApplication.isPlaying)
  38. {
  39. if (GUILayout.Button("Save Settings"))
  40. {
  41. t.Save();
  42. }
  43. if (GUILayout.Button("Remove All Settings"))
  44. {
  45. t.RemoveAllSettings();
  46. }
  47. }
  48. serializedObject.ApplyModifiedProperties();
  49. Repaint();
  50. }
  51. protected override void OnCompileComplete()
  52. {
  53. base.OnCompileComplete();
  54. RefreshTypeNames();
  55. }
  56. private void OnEnable()
  57. {
  58. m_SettingHelperInfo.Init(serializedObject);
  59. RefreshTypeNames();
  60. }
  61. private void RefreshTypeNames()
  62. {
  63. m_SettingHelperInfo.Refresh();
  64. serializedObject.ApplyModifiedProperties();
  65. }
  66. }
  67. }