using System; using System.Collections; using System.Collections.Generic; using UnityEditor; using UnityEngine; // a custom inspector that forces unity to use our reimplementation of property drawing logic, rather than their own // this attribute will make this match for anythig based on MononBahviour. [CustomEditor(typeof(MonoBehaviour), true)] public class GenericInspector : Editor { public override void OnInspectorGUI() { #if false // use unitys default inspector logic DrawDefaultInspector(); #else // use our reimplementation ReflectedDrawDefaultInspector(); #endif } // implemented in Editor.DoDrawDefaultInspector(...) private void ReflectedDrawDefaultInspector() { var obj = this.serializedObject; EditorGUI.BeginChangeCheck(); // obj.Update(); SerializedProperty iterator = obj.GetIterator(); bool enterChildren = true; // We *have* to enter children on the first loop. This returns all // the properties on the component. After that, we do not want children, because the property // drawer will handle drawing thoes while (iterator.NextVisible(enterChildren)) // go over each property { // inspectors start with a object link to the script file that implements the MonoBehaviour, // this makes sure that link is drawn disabled using (new EditorGUI.DisabledScope("m_Script" == iterator.propertyPath)) { // actually draw the property! // this method is actually implemented in EditorGUILayout.PropertyField(...) PropertyField(iterator, true); } enterChildren = false; } obj.ApplyModifiedProperties(); EditorGUI.EndChangeCheck(); // to make it clear that this is being drawn by our reimplementation, lets flag it with a lil watermark using (new EditorGUI.DisabledScope(true)) { GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label("LotteMakesStuff"); GUILayout.EndHorizontal(); } } public static bool PropertyField(SerializedProperty property, bool includeChildren, params GUILayoutOption[] options) { return PropertyField(property, null, includeChildren, options); } public static bool PropertyField(SerializedProperty property, GUIContent label, bool includeChildren, params GUILayoutOption[] options) { // get the property handler and then ask it to draw. return ScriptAttributeUtility.GetHandler(property).OnGUILayout(property, label, includeChildren, options); } }