I’m making a plugin-manager extension to the Unity Editor. I need an ObjectField to drag-and drop folders in, and so far this has worked
public override void OnInspectorGUI()
{
serializedObject.Update();
//...
if (Event.current.commandName == "ObjectSelectorUpdated")
{
currentObject = EditorGUIUtility.GetObjectPickerObject();
}
currentObject = EditorGUILayout.ObjectField("Object", currentObject, typeof(Object), true) as DefaultAsset;
//...
serializedObject.ApplyModifiedProperties();
}
Yet, I need this to be a re-sizable list of ObjectFields, and not just one.
Using
EditorGUILayout.PropertyField(folderProp, new GUIContent("Plugin 1"), true);
//"folderprop" is a serialized property of "Object[]".
gives me my re-sizable list in the inspector, but I don’t know how to retrieve what Object(s) were put into the editor because the method returns a bool and doesn’t trigger an Event with a command name! Aside from that, the documentation doesn’t give an example. Does anyone know how to use this?
I solved my problem. The object was actually going to the variable in the script my editor script was a type of (the variable the editor script was getting its serialized property from), not the editor script itself. I was able to get an instance of that script using GameObject.FindObjectOfType<MyScript>(); //or FindObjectsOfType. Mine only appears once. inside of my editor script and call a function inside of it that uses that value.