Skip to content

Instantly share code, notes, and snippets.

@AndrewCarvalho
Created March 22, 2020 02:44
Show Gist options
  • Save AndrewCarvalho/b21aefe074f0bb95be57a3cd0fde9563 to your computer and use it in GitHub Desktop.
Save AndrewCarvalho/b21aefe074f0bb95be57a3cd0fde9563 to your computer and use it in GitHub Desktop.
Unity MonoBehaviour UIElements Inspector Implementation
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