Answer the question
In order to leave comments, you need to log in
Why doesn't Unity attach a gameobject in the custom inspector field?
In the class file for which the editor script is written, a two-dimensional array of gameobjects is declared:
public GameObject[][] blocks;
The script for the editor itself
using GameLayer.GameManagers;
using UnityEditor;
using UnityEngine;
namespace Editor
{
[CustomEditor(typeof(LevelGameManager))]
public class LevelGameManagerEditor : UnityEditor.Editor
{
private int rows, columns;
public override void OnInspectorGUI()
{
DrawDefaultInspector();
EditorGUILayout.Space(30);
LevelGameManager myTarget = target as LevelGameManager;
EditorGUILayout.LabelField("Blocks");
rows = EditorGUILayout.IntField("Rows count", rows);
columns = EditorGUILayout.IntField("Columns count", columns);
myTarget.blocks = new GameObject[rows][];
for (int i = 0; i < rows; i++)
{
EditorGUILayout.LabelField($"Row {i + 1}");
myTarget.blocks[i] = new GameObject[columns];
for(int j = 0; j < columns; j++)
{
myTarget.blocks[i][j] = (GameObject) EditorGUILayout.ObjectField($"Column {j + 1}", myTarget.blocks[i][j], typeof(GameObject), true);
}
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question