Edit an object in UnityEditor EditorWindow

Hi All

If I have a class I have created with public members and I have my own EditorWindow. Can I create some GUI to edit the members on that class in the EditorWindow in a similar way to the GUI the editor generates for scripts attached to the selected GameObject automatically, or do I need to create the GUI manually for each property.

I can see PropertyField and ObjectField GUI elements, but it’s not entirely clear how these should work.

Thanks
H

Yes you can. Check out the docs for the SerializedProperty which has an example. I am sure you can use this in EditorWindow.OnGUI as well for your window.

Basically you create a SerializedObject from any object, then you can get the SerializedProperty you wish to obtain and use them in EditorGUI.PropertyField or EditorGUILayout.PropertyField.