Ha, well, a number of things, here’s the editor at the moment:
using UnityEngine;
using UnityEditor;
using System.Collections;
using System;
[CustomEditor(typeof(citygenerator)), CanEditMultipleObjects]
public class CityGenEditor : Editor {
public void OnEnable(){
}
public override void OnInspectorGUI () {
serializedObject.Update();
GUIContent sizeLabel = new GUIContent("City Size:");
EditorList.Show (serializedObject.FindProperty("size"),sizeLabel,EditorListOption.IntSlider);
GUIContent scaleLabel = new GUIContent("City Scale:");
EditorList.Show (serializedObject.FindProperty("scale"),scaleLabel,EditorListOption.IntSlider);
GUIContent axesLabel = new GUIContent("Starting Axes:");
EditorList.Show (serializedObject.FindProperty("Axes"),axesLabel,EditorListOption.Prop);
serializedObject.ApplyModifiedProperties();
EditorGUILayout.Space() ;
GUIContent sbsarLabel = new GUIContent("Use .sbsar's:");
EditorList.Show (serializedObject.FindProperty("UseProceduralTextures"),sbsarLabel,EditorListOption.Prop);
GUIContent btextLabel = new GUIContent("Use one Texture:");
EditorList.Show (serializedObject.FindProperty("UseBaseTexturesOnly"),btextLabel,EditorListOption.Prop);
GUIContent collLabel = new GUIContent("Use Colliders:");
EditorList.Show (serializedObject.FindProperty("UseColliders"),collLabel ,EditorListOption.Prop);
serializedObject.ApplyModifiedProperties();
EditorGUILayout.Space() ;
GUIContent bmeshLabel = new GUIContent("Building Meshes");
EditorList.Show (serializedObject.FindProperty("BuildingMeshes"),serializedObject.FindProperty("BuildingSizes"),serializedObject.FindProperty("BuildingArrSize"),serializedObject.FindProperty("BuildingArrBool"),bmeshLabel ,EditorListOption.ParentList);
serializedObject.ApplyModifiedProperties();
}
}
public static class EditorList {
public static void Show (SerializedProperty list, GUIContent label, EditorListOption options) {
bool
asIntSlide = (options EditorListOption.IntSlider) != 0,
asProp = (options EditorListOption.Prop) != 0,
asList = (options EditorListOption.List) != 0;
if(asIntSlide){
EditorGUILayout.IntSlider(list,0,50,label);
} else if(asProp){
EditorGUILayout.PropertyField(list,label);
} else if(asList){
EditorGUILayout.PropertyField (list);
if(list.isExpanded){
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(list.FindPropertyRelative("Array.size"));
for(int i = 0;i < list.arraySize;i++){
EditorGUILayout.PropertyField (list.GetArrayElementAtIndex(i));
}
EditorGUI.indentLevel--;
}
}
}
public static void Show (SerializedProperty list, SerializedProperty child, SerializedProperty size, SerializedProperty foldout, GUIContent label, EditorListOption options) {
bool
asPList = (options EditorListOption.ParentList) != 0;
while (foldout.arraySize > list.arraySize) {
foldout.DeleteArrayElementAtIndex(foldout.arraySize - 1);
}
while(foldout.arraySize < list.arraySize) {
foldout.InsertArrayElementAtIndex(foldout.arraySize);
}
while (child.arraySize > list.arraySize) {
child.DeleteArrayElementAtIndex(child.arraySize - 1);
}
while(child.arraySize < list.arraySize) {
child.InsertArrayElementAtIndex(child.arraySize);
}
if(asPList){
EditorGUILayout.PropertyField (list);
if(list.isExpanded){
EditorGUI.indentLevel++;
for(int i = 0;i < list.arraySize;i++){
GUIContent intLabel = new GUIContent("Building " + i.ToString());
foldout.GetArrayElementAtIndex(i).boolValue = EditorGUILayout.Foldout(foldout.GetArrayElementAtIndex(i).boolValue, intLabel);
if(foldout.GetArrayElementAtIndex(i).boolValue){
EditorGUILayout.PropertyField (list.GetArrayElementAtIndex(i));
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PropertyField (child.GetArrayElementAtIndex(i));
DeleteButton (list,child,i);
EditorGUILayout.EndHorizontal();
}
}
AddButton(list);
EditorGUI.indentLevel--;
}
}
}
private static GUIContent
newEntry = new GUIContent("+", "Add a building"),
deleteEntry = new GUIContent("-", "Remove building");
private static GUILayoutOption miniButtonWidth = GUILayout.Width(20f);
private static void AddButton (SerializedProperty list) {
EditorGUILayout.BeginHorizontal();
if(GUILayout.Button(newEntry,EditorStyles.miniButton,miniButtonWidth)){
list.InsertArrayElementAtIndex(list.arraySize);
}
//GUILayout.Button(deleteEntry,EditorStyles.miniButton,miniButtonWidth);
EditorGUILayout.EndHorizontal();
}
private static void DeleteButton (SerializedProperty list, SerializedProperty child, int ind) {
if(GUILayout.Button(deleteEntry,EditorStyles.miniButton,miniButtonWidth)){
if (ind != list.arraySize - 1)
{
list.GetArrayElementAtIndex(ind).objectReferenceValue = list.GetArrayElementAtIndex(list.arraySize - 1).objectReferenceValue;
}
list.arraySize--;
if (ind != child.arraySize - 1)
{
child.GetArrayElementAtIndex(ind).objectReferenceValue = child.GetArrayElementAtIndex(child.arraySize - 1).objectReferenceValue;
}
child.arraySize--;
}
}
private static void DeleteButton (SerializedProperty list, int ind) {
if(GUILayout.Button(deleteEntry,EditorStyles.miniButton,miniButtonWidth)){
if (ind != list.arraySize - 1)
{
list.GetArrayElementAtIndex(ind).objectReferenceValue = list.GetArrayElementAtIndex(list.arraySize - 1).objectReferenceValue;
}
list.arraySize--;
}
}
}
[Flags]
public enum EditorListOption {
None = 0,
IntSlider = 1,
Prop = 2,
List = 4,
ParentList = 8,
Default = 0
}