- Home /
Question by
SwiftRocket · Dec 22, 2014 at 11:21 AM ·
editorarraysextension
EditorWindow. Display array dropdown
I'm trying to make my own editor window, and i want to be able to display an array. (like this)
maybe some GUILayout or something???
string[] strings;
strings = EditorGUILayout.MagicalArrayInputFields(strings);
How to accomplish it? thanks in advance!
array.jpg
(6.5 kB)
Comment
Answer by AdamScura · Dec 22, 2014 at 12:56 PM
PropertyField will display arrays correctly. You have to set the parameter "showChildren" to true.
public class MyEditorWindow : EditorWindow
{
[MenuItem("Window/My Editor Window")]
public static void ShowWindow()
{
GetWindow<MyEditorWindow >();
}
public string[] Strings = { "Larry", "Curly", "Moe" };
void OnGUI()
{
// "target" can be any class derrived from ScriptableObject
// (could be EditorWindow, MonoBehaviour, etc)
ScriptableObject target = this;
SerializedObject so = new SerializedObject(target);
SerializedProperty stringsProperty = so.FindProperty("Strings");
EditorGUILayout.PropertyField(stringsProperty, true); // True means show children
so.ApplyModifiedProperties(); // Remember to apply modified properties
}
}
Is there a way to display an object which is not declared inside and not derived from the ScriptableObject?
Yes, you can declare an array within the EditorWindow class and create a serialized object for it just like you would create one for a serialized object.
public class SceneSearchTool : EditorWindow {
public string[] strings;
private SerializedObject so;
private SerializedProperty stringsProp;
public void OnGUI()
{
EditorGUILayout.PropertyField(stringsProp, true);
so.Apply$$anonymous$$odifiedProperties();
}
private void OnEnable()
{
so = new SerializedObject(this);
stringsProp= so.FindProperty("strings");
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613174546im_/https://answers.unity.com/themes/thub/images/avi.jpg)