123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- //------------------------------------------------------------
- // Game Framework
- // Copyright © 2013-2021 loyalsoft. All rights reserved.
- // Homepage: http://www.game7000.com/
- // Feedback: http://www.game7000.com/
- //------------------------------------------------------------
- using UnityEditor;
- using UnityEngine;
- using UnityGameFramework.Runtime;
- namespace UnityGameFramework.Editor
- {
- [CustomEditor(typeof(SettingComponent))]
- internal sealed class SettingComponentInspector : GameFrameworkInspector
- {
- private HelperInfo<SettingHelperBase> m_SettingHelperInfo = new HelperInfo<SettingHelperBase>("Setting");
- public override void OnInspectorGUI()
- {
- base.OnInspectorGUI();
- SettingComponent t = (SettingComponent)target;
- EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode);
- {
- m_SettingHelperInfo.Draw();
- }
- EditorGUI.EndDisabledGroup();
- if (EditorApplication.isPlaying && IsPrefabInHierarchy(t.gameObject))
- {
- EditorGUILayout.LabelField("Setting Count", t.Count >= 0 ? t.Count.ToString() : "<Unknown>");
- if (t.Count > 0)
- {
- string[] settingNames = t.GetAllSettingNames();
- foreach (string settingName in settingNames)
- {
- EditorGUILayout.LabelField(settingName, t.GetString(settingName));
- }
- }
- }
- if (EditorApplication.isPlaying)
- {
- if (GUILayout.Button("Save Settings"))
- {
- t.Save();
- }
- if (GUILayout.Button("Remove All Settings"))
- {
- t.RemoveAllSettings();
- }
- }
- serializedObject.ApplyModifiedProperties();
- Repaint();
- }
- protected override void OnCompileComplete()
- {
- base.OnCompileComplete();
- RefreshTypeNames();
- }
- private void OnEnable()
- {
- m_SettingHelperInfo.Init(serializedObject);
- RefreshTypeNames();
- }
- private void RefreshTypeNames()
- {
- m_SettingHelperInfo.Refresh();
- serializedObject.ApplyModifiedProperties();
- }
- }
- }
|