[Sorry for my bad english]
I’m total beginner at editor window scripting and I’m trying to make a two dimensional toggle array in my custom editor window. My problem: When I click a toggle button the true/false value does not change. Is that any sollution for this problem?
The width and height must remain changable.
Here’s my code:
using UnityEngine;
using UnityEditor;
using System.Collections;
public class LevelEditor : EditorWindow {
bool[,] fieldsArray = new bool[0,0];
int width = 1;
int height = 1;
int levelNumber = 1;
[MenuItem("Window/LevelEditor")]
public static void ShowWindow()
{
EditorWindow.GetWindow(typeof(LevelEditor));
}
void OnGUI()
{
GUILayout.Label ("LEVEL NUMBER", EditorStyles.boldLabel);
levelNumber = EditorGUILayout.IntField ("Level Number", levelNumber);
GUILayout.Label ("Array width/height", EditorStyles.boldLabel);
width = EditorGUILayout.IntField ("Width", width);
height = EditorGUILayout.IntField ("Width", height);
fieldsArray = new bool[width, height];
ChangeArrayWidthAndHeight ();
if (GUILayout.Button ("Apply")) {
// applies array to GameManager
}
}
void ChangeArrayWidthAndHeight()
{
for (int j=0; j<height; j++) {
EditorGUILayout.BeginHorizontal();
for (int i=0; i<width; i++) {
fieldsArray[i,j] = EditorGUILayout.Toggle(fieldsArray[i,j]);
}
EditorGUILayout.EndHorizontal();
}
}
}
![1]