- Home /
How to create elements array about all visible in GUI Editor?
Hi,
I need to create an array of all elements in GUI Editor (ie: Inspector and all elements, Hierarchy and all elements, Project and all elements, etc).
I need of this to cycle in array and find any element of GUIEditor I want and export in a text file for external elaborations.
It's possible? Please, sample code in c#.
Thanks
Answer by Immanuel-Scholz · Jul 06, 2015 at 10:58 AM
You cannot inspect the Editor - GUI directly, because there is nothing that could be inspected. The labels and everything is drawn "on the fly", thats why its also called "Immediate GUI".
What you can do, is to try to get to the same data source that the editor usually uses to draw its stuff.
For the Inspector, this would be the SerializedObject of the current selected objects. (You can enumerate its SerializedProperty using GetEnumerator()).
For the Project view, that are all assets in the directory of the current selected object (actually, its more complicated as you can select "folders only" which does not really appear in Unity's Selection.objects. But its good enough most of the time).
For the Hierarchy, that are all GameObjects and all their childs. You can iterate childs by calling
transform.childCount
andtransform.GetChild(i)
in a for-loop. Or you just doforeach (Transform child in transform)
(which you should not do in Update-loops during runtime or common called functions as it allocates memory. But in editor-code its ok, I guess..)
$$anonymous$$any thanks, and follow this way can I handle each object focused by mouse or keyboard?
Getting the object that is selected in Hierarchy or Project window is dead-simple: Selection.activeObject
(or Selection.objects
if you want to support multi-selection).
However, getting the property in the Inspector window, that currently has the focus is nearly impossible. You can get its ControlID via GUI.keyboardControl or GUI.hotControl. But unfortunately, there is no sane way to get to the actual SerializedProperty from an internal ControlID.
Ok, and about any custom data source installed from external assets? How to retrieve that too?
What do you mean by that? What exactly do you want to iterate or retrieve?
Basically, I need to make an asset and use it in edit mode for handle any field who user focus it with keyboard or mouse. About these fields I need to get the text name only. All except any object in scene. But if the user install a third part asset and this asset in edit mode create a cuatom inspector then my asset must handle any field into it too.
Your answer
Follow this Question
Related Questions
Initialising List array for use in a custom Editor 1 Answer
Distribute terrain in zones 3 Answers
How to tell if any textField has keyboard focus in editor? 2 Answers
Multiple Cars not working 1 Answer
How to posistion GUI elements? 1 Answer