- Home /
Generic List In Custom Editor Window
Hi:
I am trying to make a custom editor window with a grneric list. the same as one in the inspector when you attach it on a gameobject.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[System.Serializable]
public class Tile
{
public GameObject tile; //the tile prefab
public Color tileColor; //the reffrence of color to instantiate prefab
}
public class LevelGenerator : EditorWindow
{
public List<Tile> tileList;
[MenuItem("Window/My Editor/Level Generator")]
public static void ShowWindow()
{
GetWindow<LevelGenerator>("Level Generator");
}
//window code
void OnGUI()
{
tileList = EditorGUILayout.List<Tile>("Tile", tileList); //Having trouble with this part!!!
}
}
I am thinking it has to do with "propertyfields" but having trouble implementing it.
Thanks: James
Answer by jimjames · Dec 09, 2019 at 04:33 AM
I got this to work with placing this part of code in the area where i wanted the list to show up in the editor.
//to show the list of tiles//
ScriptableObject target = this;
SerializedObject so = new SerializedObject(target);
SerializedProperty stringsProperty = so.FindProperty("tileList");
EditorGUILayout.PropertyField(stringsProperty, true);
so.ApplyModifiedProperties();
//end for the list of tiles
@jimjames Thanks for this as i am now able to see my list in the custom editor, the problem i am having is that the list is not editable from the editor, it is grayed out. Did you have this issue and do you have any solutions?
Answer by HyruleDefender · May 06 at 07:42 PM
I have been searching for a solution for this here in 2022
And I just replaced "tileList" with the name of myList Thank you, Thank you!
Hi, could you please show how you came to this? I can now view the list, but cannot assign anything to it in the editor window...
Sure, Id be happy to.
This is essentially what I have for the array of game objects (I tried to upload a screenshot of the tool, but Unity Answers is not letting me)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class MLET_Tool : EditorWindow
{
//model list
[SerializeField]
private List<GameObject> listModelGeo;
//UI visuals
public void OnGUI() // these should send information ON "spawn grid" for most, but "on change" for some (like rotation)
{
GUILayout.Label("Prefabs/Models", EditorStyles.boldLabel);
//to show the list of geo
ScriptableObject target = this;
SerializedObject so = new SerializedObject(target);
SerializedProperty stringsProperty = so.FindProperty("listModelGeo");
}
}