/// --------------------------------------------- /// Ultimate Character Controller /// Copyright (c) Opsive. All Rights Reserved. /// https://www.opsive.com /// --------------------------------------------- namespace Opsive.UltimateCharacterController.Editor.Inspectors { using Opsive.UltimateCharacterController.Editor.Inspectors.Utility; using System.Collections.Generic; using UnityEditor; using UnityEngine; /// /// Base class for all Ultimate Character Controller inspectors. /// public abstract class InspectorBase : UnityEditor.Editor { private Dictionary m_PropertyStringMap = new Dictionary(); /// /// Draws the custom inspector. /// public override void OnInspectorGUI() { // Show the script field. EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(PropertyFromName("m_Script")); if (EditorGUI.EndChangeCheck()) { InspectorUtility.RecordUndoDirtyObject(target, "Change Value"); serializedObject.ApplyModifiedProperties(); } } /// /// Uses a dictionary to lookup a property from a string key. /// /// The name of the property. /// The found SerializedProperty. public SerializedProperty PropertyFromName(string name) { return PropertyFromName(serializedObject, name); } /// /// Uses a dictionary to lookup a property from a string key. /// /// The object which contains the property. /// The name of the property. /// The found SerializedProperty. public SerializedProperty PropertyFromName(SerializedObject serializedObject, string name) { SerializedProperty property = null; if (m_PropertyStringMap.TryGetValue(name, out property)) { return property; } property = serializedObject.FindProperty(name); if (property == null) { Debug.LogError("Unable to find property " + name); return null; } m_PropertyStringMap.Add(name, property); return property; } /// /// Shortcut for drawing a foldout on the current target. /// /// The name of the foldout. /// True if the foldout is expanded. protected bool Foldout(string name) { return Foldout(name, true, string.Empty); } /// /// Shortcut for drawing a foldout on the current target. /// /// The name of the foldout. /// The default value if the foldout is expanded. /// True if the foldout is expanded. protected bool Foldout(string name, bool defaultExpanded) { return Foldout(name, defaultExpanded, string.Empty); } /// /// Shortcut for drawing a foldout on the current target. /// /// The name of the foldout. /// A string that can be used to help identify the foldout key. /// True if the foldout is expanded. protected bool Foldout(string name, string identifyingString) { return Foldout(name, true, identifyingString); } /// /// Shortcut for drawing a foldout on the current target. /// /// The name of the foldout. /// The default value if the foldout is expanded. /// A string that can be used to help identify the foldout key. /// True if the foldout is expanded. protected bool Foldout(string name, bool defaultExpanded, string identifyingString) { return InspectorUtility.Foldout(target, new GUIContent(name), defaultExpanded, identifyingString); } } }