Customize arrays and classes in inspector window

var levels : Levels;

class Levels
{
	var areas : Areas[];
}

class Areas
{
	var map : mapType;
	var game : gameType;
	var rounds : EachRound[];
}

enum mapType { Park, Street, Graveyard, House }
enum gameType { Escape, Survival, Graverobber, Lockdown }

class EachRound
{
	var time : int;
	var enemiesToKill : int;
	var houseIntegrityMin : int;
	var bats : batType;
	var werewolves : werewolfType;
	var waves : int;
	var reward : int;
}

enum batType { None, Bats, PoisonBats, Bats_PoisonBats }
enum werewolfType { None, Werewolves, StrongWerewolves, Werewolves_StrongWerewolves }

The level parameters in my game are arranged in hierarchies of classes and arrays, as in the code above. I’d like to access these and tweak via the inspector window but currently this displays in the inspector in a bit of a confusing way, with a variety of “Element 0, Element 1, etc.” items. I want to put in a little effort to make it more readable and user friendly. Even just replacing those “Element” names with their true identities would be incredibly helpful. I’ve attached an image of how it looks now, and a mockup of how I’d ideally like it to appear.

I spent the last two days getting my head around custom editor scripting but it doesn’t seem like an easy task at all. From what I’ve learned, I can’t just simply make a few modifications to how the information is displayed, I’d need to re-structure reading and writing of arrays and classes and… it just seems like a huge task that is beyond my knowledge. Is there hopefully some other solution that I’ve missed to editing this data?

Current layout

alt text

Preferred custom layout

alt text

If you want it to look like on the picture, you need to re-arrange your script so it will look like you want.

But you can also make a custom inspector, where you might have little more freedom in how you want to display your data. But it might take some time and effort to make it readable and look good.

If you want to have a custom inspector, you need to create a editor class.
See more in the EditorGUILayout class

A Bare basic setp of the class would look something like this:

using UnityEditor;
using UnityEngine;
using System.Collections;

[CanEditMultipleObjects]
[CustomEditor (typeof(YourClass))]
public class CustomInspector : Editor {   
	
	public void OnEnable()    
	{        

	}
	
	public override void OnInspectorGUI()    
	{   
		// Do EditorGUILayout work here...

		SceneView.RepaintAll();
	}
}

Now you can add your own, custom inspector parameters as you would like them to be.
Here is a Answer link
where you can read more about exteding the editor:

Tutorials on extending the editor

Good luck!

After a little effort learning the Custom Editor this is the new result. Quite a dramatic difference from what I originally wanted after a little inspiration from Mike’s post. Code is beneath if it can help anyone out (not very well-commented but might be useful!)

alt text

import System.Collections.Generic;		// So I can use lists

@CustomEditor (LevelData)

class LevelData_CustomInspector extends Editor
{	
	var levelIndex = 0;
	var areaIndex = List.<int>();
	var roundIndex = List.<List.<int> >();

	function Awake()
	{
		// Reset
		//ResetValues();
		
		// Retrieve all inspector window selections
		levelIndex = EditorPrefs.GetInt("levelIndex", 0);		// Levels
		// Areas
		if ( !EditorPrefs.HasKey("areaIndex") )
			return;
		var areaArray : int[] = EditorPrefsX.GetIntArray ("areaIndex");
		for ( var i = 0; i < areaArray.Length; i++ )
		{ areaIndex.Add(areaArray*); }*
  •  // Rounds*
    
  •  i = 0;*
    
  •  while ( EditorPrefs.HasKey("roundIndex"+i) )*
    
  •  {*
    
  •  	var roundIndex_temp = List.<int>();*
    
  •  	var roundArray : int[] = EditorPrefsX.GetIntArray ("roundIndex"+i);*
    
  •  	for ( var j = 0; j < roundArray.Length; j++ )*
    
  •  		roundIndex_temp.Add(roundArray[j]);	*
    
  •  	roundIndex.Add(roundIndex_temp);*
    
  •  	i++;*
    
  •  }*
    
  • }*

  • function ResetValues()*

  • { // Resets all stored values*

  •  EditorPrefs.DeleteKey("levelIndex");*
    
  •  EditorPrefs.DeleteKey("areaIndex");*
    
  •  var i = 0;*
    
  •  while ( EditorPrefs.HasKey("roundIndex"+i) )*
    
  •  {*
    
  •  	EditorPrefs.DeleteKey("roundIndex"+i);*
    
  •  	i++;*
    
  •  }*
    
  •  Debug.Log("All stored values reset");*
    
  • }*

  • function OnDestroy()*

  • {*

  •  // Save all inspector window selections*
    
  •  EditorPrefs.SetInt("levelIndex", levelIndex);		// Levels*
    
  •  // Areas (check that areas exist)*
    
  •  if ( areaIndex.Count < 1 )*
    
  •  	return;*
    
  •  var areaArray : int[] = areaIndex.ToArray();*
    
  •  EditorPrefsX.SetIntArray ("areaIndex", areaArray);*
    
  •  // Rounds (check that rounds exist)*
    
  •  for ( var i = 0; i < roundIndex.Count; i++ )*
    
  •  {*
    

_ if ( roundIndex*.Count > 0 )_
_ var tempArray : int[] = roundIndex.ToArray();
else*
* tempArray[0] = 0;
EditorPrefsX.SetIntArray (“roundIndex”+i, tempArray);
}
}*_

* function OnInspectorGUI()*
* {*
* GUILayout.Space (20);*
* // Level select*
* GUILayout.BeginHorizontal();*
* var parsedLevels = new String[target.levels.Count];*
* for ( var i = 0; i < parsedLevels.Length; i++ )*
_ { parsedLevels = "Level " + (i+1).ToString(); }
* levelIndex = GUILayout.Toolbar ( levelIndex, parsedLevels, EditorStyles.toolbarButton );
GUILayout.Space (10);
if ( GUILayout.Button(“+”, EditorStyles.toolbarButton, GUILayout.Width(50)) )
{
if ( target.levels.Count < 8 )
{
target.levels.Add(target.Levels);
areaIndex.Add(0); // Also increase areaIndex array*

* roundIndex.Add( new List.() ); // Also increase roundIndex array 1st tier*
* }
else*

* Debug.Log(“Maximum number of levels is 8”);
}
if ( GUILayout.Button(“-”, EditorStyles.toolbarButton, GUILayout.Width(50)) && target.levels.Count > 0 )
{
target.levels.RemoveAt(target.levels.Count -1);
areaIndex.RemoveAt(areaIndex.Count -1); // Also decrease areaIndex array*

* roundIndex.RemoveAt(roundIndex.Count -1); // Also decrease roundIndex array*
* if ( levelIndex > target.levels.Count -1 )
levelIndex–; // Lower levelIndex if player had it selected upon deletion*

* if ( levelIndex < 0 )
levelIndex = 0;
}
GUILayout.EndHorizontal();*_

* GUILayout.Space (5);*
* // Area select*
* GUI.backgroundColor = Color(0.95,0.99,1,1);*
* if ( target.levels.Count < 1 || target.levels[levelIndex] == null )*
* return; // Quit if there are no levels yet*
* GUILayout.BeginHorizontal();*
* var parsedAreas = new String[target.levels[levelIndex].areas.Count];*
* for ( i = 0; i < parsedAreas.Length; i++ )*
_ { parsedAreas = "Area " + (i+1).ToString(); }
* areaIndex[levelIndex] = GUILayout.Toolbar (areaIndex[levelIndex], parsedAreas, EditorStyles.toolbarButton );
GUILayout.Space (10);
if ( GUILayout.Button(“+”, EditorStyles.toolbarButton, GUILayout.Width(50)) )
{
if ( target.levels[levelIndex].areas.Count < 10 )
{
target.levels[levelIndex].areas.Add(target.Areas);
roundIndex[levelIndex].Add(0); // Also increase roundIndex array 2nd tier*

* }
else*

* Debug.Log(“Maximum number of areas is 10”);
}
if ( GUILayout.Button(“-”, EditorStyles.toolbarButton, GUILayout.Width(50)) && target.levels[levelIndex].areas.Count > 0 )
{
target.levels[levelIndex].areas.RemoveAt(target.levels[levelIndex].areas.Count -1);
roundIndex[levelIndex].RemoveAt(roundIndex[levelIndex].Count -1); // Also decrease roundIndex array 2nd tier*

* if ( areaIndex[levelIndex] > target.levels[levelIndex].areas.Count -1 )
areaIndex[levelIndex] -= 1; // Lower areaIndex if player had it selected upon deletion*

* if ( areaIndex[levelIndex] < 0 )
areaIndex[levelIndex] = 0;
}
GUILayout.EndHorizontal();*_

* // Start Area Box*
* EditorGUILayout.BeginVertical(EditorStyles.textField);*
* GUILayout.Space (15);*
* // Area details*
* if ( target.levels[levelIndex].areas.Count < 1 || target.levels[levelIndex].areas[areaIndex[levelIndex]] == null )*
* return; // Quit if there’s no areas for this level yet *
* var currentArea = target.levels[levelIndex].areas[areaIndex[levelIndex]];*
* // Convert enum names to string*
* var mapString = System.Enum.GetNames(typeof(currentArea.map));*
* var gameString = System.Enum.GetNames(typeof(currentArea.game));*
* // Map select*
* GUILayout.BeginHorizontal();*
* GUI.backgroundColor = Color(1,0.9,0.25,0.75);*
* GUILayout.Label (“Map”, GUILayout.Width(70));*
* currentArea.map = GUILayout.Toolbar (currentArea.map, mapString, EditorStyles.toolbarButton);*
* GUILayout.EndHorizontal();*
* GUILayout.Space (10);*
* // Game select*
* GUILayout.BeginHorizontal();*
* GUI.backgroundColor = Color(0.75,1,0.9,1);*
* GUILayout.Label (“Game”, GUILayout.Width(70));*
* currentArea.game = GUILayout.Toolbar (currentArea.game, gameString, EditorStyles.toolbarButton);*
* GUILayout.EndHorizontal();*
* GUILayout.Space (10);*
* // Round count*
* GUILayout.BeginHorizontal();*
* GUI.backgroundColor = Color(0.99,0.95,1,1);*
* GUILayout.Label (“Rounds”, GUILayout.Width(70));*
* GUILayout.Label (target.levels[levelIndex].areas[areaIndex[levelIndex]].rounds.Count.ToString(), GUILayout.Width(40));*
* if ( GUILayout.Button(“+”, EditorStyles.toolbarButton, GUILayout.Width(30)) )*
* target.levels[levelIndex].areas[areaIndex[levelIndex]].rounds.Add(target.Rounds);*
* if ( GUILayout.Button(“-”, EditorStyles.toolbarButton, GUILayout.Width(30)) && target.levels[levelIndex].areas[areaIndex[levelIndex]].rounds.Count )*
* {*
* target.levels[levelIndex].areas[areaIndex[levelIndex]].rounds.RemoveAt(target.levels[levelIndex].areas[areaIndex[levelIndex]].rounds.Count -1);*
* if ( roundIndex[levelIndex][areaIndex[levelIndex]] > target.levels[levelIndex].areas[areaIndex[levelIndex]].rounds.Count -1 )*
* roundIndex[levelIndex][areaIndex[levelIndex]] -= 1; // Lower roundIndex if player had it selected upon deletion*
* if ( roundIndex[levelIndex][areaIndex[levelIndex]] < 0 )*
* roundIndex[levelIndex][areaIndex[levelIndex]] = 0;*
* }*
* GUILayout.EndHorizontal();*
* GUILayout.Space (10);*
* // End Area box*
* EditorGUILayout.EndVertical();*
* // Round dropdown*
* if ( target.levels[levelIndex].areas[areaIndex[levelIndex]].rounds.Count < 1 || target.levels[levelIndex].areas[areaIndex[levelIndex]].rounds[roundIndex[levelIndex][areaIndex[levelIndex]]] == null )*
* return; // Quit if there are no rounds yet*
* var parsedRounds = new String[target.levels[levelIndex].areas[areaIndex[levelIndex]].rounds.Count];*
* for ( i = 0; i < parsedRounds.Length; i++ )*
_ { parsedRounds = "Round " + (i+1).ToString(); }
* roundIndex[levelIndex][areaIndex[levelIndex]] = EditorGUILayout.Popup (roundIndex[levelIndex][areaIndex[levelIndex]], parsedRounds, EditorStyles.toolbarDropDown);*_

* // Round details*
* // if escape is selected, hide certain variables, and so on for each game type…*
* EditorGUILayout.BeginVertical(EditorStyles.textField);*
* GUILayout.Space (10);*
* GUI.backgroundColor = Color.white;*
* EditorGUIUtility.LookLikeInspector ();*
* var currentRound = target.levels[levelIndex].areas[areaIndex[levelIndex]].rounds[roundIndex[levelIndex][areaIndex[levelIndex]]];*
* currentRound.reward = EditorGUILayout.IntField (“Reward”, currentRound.reward);*
* currentRound.time = EditorGUILayout.IntField (“Time”, currentRound.time);*
* currentRound.enemiesToKill = EditorGUILayout.IntField (“Enemies to Kill”, currentRound.enemiesToKill);*
* currentRound.houseIntegrityMin = EditorGUILayout.IntSlider (“Minimum House Integrity %”, currentRound.houseIntegrityMin, 0, 100);*
* currentRound.waves = EditorGUILayout.IntField (“Waves of Enemies”, currentRound.waves);*
* // Enemy select*
* // Convert enum names to string*
* var werewolvesString = System.Enum.GetNames(typeof(currentRound.werewolves));*
* var batsString = System.Enum.GetNames(typeof(currentRound.bats));*
* GUILayout.BeginHorizontal();*
* GUI.backgroundColor = Color(1,0.9,0.75,1);*
* EditorGUILayout.LabelField (“Werewolves”);*
* currentRound.werewolves = EditorGUILayout.Popup (currentRound.werewolves, werewolvesString, EditorStyles.toolbarPopup);*
* GUILayout.EndHorizontal();*
* GUILayout.BeginHorizontal();*
* GUI.backgroundColor = Color(0.9,1,0.75,1);*
* EditorGUILayout.LabelField (“Bats”);*
* currentRound.bats = EditorGUILayout.Popup (currentRound.bats, batsString, EditorStyles.toolbarPopup);*
* GUILayout.EndHorizontal();*
* // Weapons*
* GUILayout.Space (5);*
* GUILayout.BeginHorizontal();*
* GUI.backgroundColor = Color(0.9,0.9,0.9,1);*
* GUILayout.Space(50);*
* currentRound.pistol = GUILayout.Toggle(currentRound.pistol, “Pistol”, EditorStyles.miniButton);*
* currentRound.shotgun = GUILayout.Toggle(currentRound.shotgun, “Shotgun”, EditorStyles.miniButton);*
* currentRound.rifle = GUILayout.Toggle(currentRound.rifle, “Rifle”, EditorStyles.miniButton);*
* currentRound.automatic = GUILayout.Toggle(currentRound.automatic, “Automatic”, EditorStyles.miniButton);*
* GUILayout.Space(50);*
* GUILayout.EndHorizontal();*

* GUILayout.Space (10);*
* EditorGUILayout.EndVertical();*
* }*
}