So I’ve looked around a bit and I can’t really find what I’m looking for. I’m curious if anyone knows of a way to duplicate or a specific call that I have no found in order to get the object picker functionality but inside a custom editor window. I’ll elaborate.
I would like a list of certain asset files to display on the left side of my custom editor window. But when I specifically access these files through the asset database and loading them through there, it makes the editor window terribly slow. So I’m looking to scale down my efforts in some regards in order to just get a simple object picker window to display in the side menu for large amounts of data.
If you ask if you can display the asset selection GUI of the object picket / selector inside your editor window, then the answer is no. The object picker is itself an EditorWindow and a quite complex one. It has over 30 private methods to actually do it’s job ^^.
However you can display an ObjectField inside your custom window. This works the same as an object field in the inspector (well it’s actually the same thing ^^). So it let you drag and drop assets to the field or open the object picker. You can also restrict the object type. The EditorGUILayout version looks like this:
Note: the “label” is optional. yourObj is your actual object reference. You might need to cast the return type properly. You can specify any “type” that is derived from UnityEngine.Object as restriction. If you only want “GameObjects” you would pass typeof(GameObject). The last bool parameter specifies if the user can select scene objects. If you pass false you can only select asset.
edit
I just created a wrapper for the internal ObjectSelector editorwindow. You still can’t “embed” the window in your own, but instead of an object field you can now simply display a button. When the button is pressed it will open the object picker.
This will show a button (just like GUILayout.Button) with the caption “Pick Object”. When clicked it will open the object selector window.
ObjectPickerButton is implemented as generic method, so it returns the same type as the variable that you pass in, in this case “Mesh”.
Awesome. Thank you for the very detailed response with alternatives. I may need to look more into seeing how Unity itself creates the object selection window, but good to know that there isn't something that is just a method call away. The alternatives that you've provided are great as well. Thank you. :D
Awesome. Thank you for the very detailed response with alternatives. I may need to look more into seeing how Unity itself creates the object selection window, but good to know that there isn't something that is just a method call away. The alternatives that you've provided are great as well. Thank you. :D
– Nerull22