Created
March 22, 2020 02:44
-
-
Save AndrewCarvalho/b21aefe074f0bb95be57a3cd0fde9563 to your computer and use it in GitHub Desktop.
Unity MonoBehaviour UIElements Inspector Implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
using UnityEditor.UIElements; | |
using UnityEngine; | |
using UnityEngine.UIElements; | |
[CustomEditor(typeof(MonoBehaviour), true, isFallback = true)] | |
public class MonoBehaviourDrawer : Editor | |
{ | |
public override void OnInspectorGUI() | |
{ | |
base.OnInspectorGUI(); | |
} | |
public override VisualElement CreateInspectorGUI() | |
{ | |
VisualElement root = new VisualElement(); | |
SerializedProperty foo = serializedObject.GetIterator(); | |
foo.Next(true); // Hide flags | |
foo.NextVisible(false); // script reference | |
PropertyField scriptField = new PropertyField(foo); | |
scriptField.SetEnabled(false); | |
root.Add(scriptField); | |
root.name = foo.objectReferenceValue.name + "Inspector"; | |
while ( foo.NextVisible(false) ) | |
{ | |
root.Add(new PropertyField(foo)); | |
} | |
return root; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment