- Home /
Display List of Objects in Editor Window
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.
Any help or suggestions will be very appreciated.
Answer by Bunny83 · Nov 27, 2016 at 03:43 AM
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:
yourObj = EditorGUILayout.ObjectField("Label", yourObj, typeof(YourType), false);
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.
The button, unlike a normal button, does not return a boolean but instead the picked object. Example:
Mesh mesh;
// [ ... ]
mesh = ObjectSelectorWrapper.ObjectPickerButton(mesh, typeof(Mesh), false, "Pick Object");
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
Answer by kaliam · Nov 26, 2016 at 09:06 PM
Have you attempted modifying the layout of your unity program through the options in the upper right hand corner.
It's not overly what I'm trying to achieve with this. What I'm trying to do is just have an editor window that is completely self contained. It will display the list of all the objects that can be manipulated on the left, and the fields to change on the right inside of that editor window with custom functionality. Currently I have a number of windows that do this, but they really become unusable once the item count goes way up.
It has crossed my $$anonymous$$d whether this functionality is necessary or if I should be doing it via custom inspectors, a lot of my fear starts to come in with our designers really not knowing what they're doing in Unity, and it's much easier to give them a window then them potentially mess something up inside Unity itself. Does that make sense?
This is also a general question to see what can be done and achieved, beyond just my own personal wants for a window as I haven't come to a final conclusion on what would be best in the long run. I think that is a separate question.
Does this elaborate more on what I'm asking? If not please ask more questions so that I can clear up any questions that may still be lingering.
Your answer
Follow this Question
Related Questions
"Type mismatch" in Inspector for GameObject type in asset file 2 Answers
How are unity references serialized? (instanceID related) 1 Answer
ObjectField Get object type(Asset, Scene Object) 2 Answers
I don't know how to use AssetDatabase.GetTextMetaDataPathFromAssetPath() 0 Answers
How to move an asset to a newly created directory in the AssetDatabase ? 3 Answers