4
\$\begingroup\$

Simply put, how do I make public List<bool[,]> appear in the inspector? Every 'bool[,]' is a solution to a puzzle in my game and I want to be able to view and edit them in the inspector.

\$\endgroup\$
3
\$\begingroup\$

You will need to create a custom property drawer.

You will also need to create a custom serializable class for your solution dataset. I may be wrong, but I don't think you will be able to assign a property drawer to a generic list type like you have.

https://unity3d.com/learn/tutorials/modules/intermediate/live-training-archive/property-drawers-custom-inspectors

http://catlikecoding.com/unity/tutorials/editor/custom-data/

The nice thing about the property drawers is that you can display the data how you want, it doesn't have to be in the typical list format that unity usually displays. You could make it a grid if you wanted.

|improve this answer|||||
\$\endgroup\$
1
\$\begingroup\$

Unity doesn't display 2D array in the inspector. For this we need to add our own Editor script to make it appear in the inspector and make it editable .

Fortunately there is already a tutorial available on how to achieve this functionality .

Link:- https://www.youtube.com/watch?v=uoHc-Lz9Lsc&feature=youtu.be

Download Link for the code :-

https://www.dropbox.com/s/8em24v1j749yl62/2DArray-In-Inspector-Scripts.zip?dl=0

|improve this answer|||||
\$\endgroup\$
1
\$\begingroup\$

enter image description here

using UnityEngine;

public class Script : MonoBehaviour
{
    public static int X, Y;
    [System.Serializable]
    public class Column
    {
        public bool[] rows = new bool[Y];
    }

    public Column[] columns = new Column[X];

}

using UnityEngine;
using UnityEditor;


[CustomEditor(typeof(Script))]
public class CustomScriptInscpector : Editor {

    Script targetScript;

    void OnEnable(){
        targetScript = target as Script;
    }

    public override void OnInspectorGUI()
    {

        Script.X = EditorGUILayout.IntField(Script.X);
        Script.Y = EditorGUILayout.IntField(Script.Y);

        EditorGUILayout.BeginHorizontal ();
        for (int y = 0; y < Script.Y; y++) {
            EditorGUILayout.BeginVertical ();
            for (int x = 0; x < Script.X; x++)
            {

                targetScript.columns [x].rows[y] = EditorGUILayout.Toggle (targetScript.columns [x].rows[y]);
            }
            EditorGUILayout.EndVertical ();

        }
        EditorGUILayout.EndHorizontal ();

    }
}

Useful link:

https://unitylist.com/p/fw5/2D-Array-Editor

|improve this answer|||||
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.