- Home /
Question by
AlcoleponeHome · Sep 19, 2020 at 10:46 AM ·
guiinspectoruser interface
Adding Custom Inspector to Sub Class Arrays
I want to add Bars to illustrate the data in array of Sub-Classes. The custom Inspector doesnt need to set the data, i can already do that fine.... I want to add a bar as shown below within each sub wave.
My script starts like this...
public class WaveSpawner : MonoBehaviour
{
public int enemyCount;
public enum SpawnState { SPAWNING, WAITING, COUNTING };
public enum PolarityState { SINGLE, ALTERNATE};
public enum SpawnType { TRIGGERPOS, RADIAL };
public GameObject playerPath;
[System.Serializable]
public class Wave
{
[HideInInspector]
public string name = "wave";
[Space(10)]
public SubWave[] subwaves;
}
[System.Serializable]
public class SubWave
{
public string name;
public GameObject[] enemyType1;
public int count;
[Range(0.0F, 60.0F)]
public float rate;
public PolarityState wavePolarityState;
public bool facingPlayer;
public bool wavepolarity;
public SpawnType spawnTypeState;
public float range = 10.0f;
public float delay = 0.0f;
}
private bool polarity;
GameObject dangerzone;
private bool canSpawn;
public Wave[] waves;
my custom inspector looks like this currently...
using UnityEditor;
using UnityEngine;
using System.Collections;
[CustomEditor(typeof(WaveSpawner))]
[CanEditMultipleObjects]
public class WavEditor1 : Editor {
SerializedProperty damageProp;
SerializedProperty armorProp;
SerializedProperty gunProp;
void OnEnable()
{
damageProp = serializedObject.FindProperty("enemyCount");
}
public override void OnInspectorGUI()
{
if (!damageProp.hasMultipleDifferentValues)
ProgressBar(damageProp.intValue / 100.0f, "enemyCount");
base.OnInspectorGUI();
}
void ProgressBar(float value, string label)
{
Rect rect = GUILayoutUtility.GetRect(18, 18, "TextField");
EditorGUI.ProgressBar(rect, value, label);
EditorGUILayout.Space();
}
}
[CustomEditor(typeof(WaveSpawner.SubWave))]
public class SubWAve : Editor{
SerializedProperty count;
void OnEnable()
{
// Setup the SerializedProperties.
count = serializedObject.FindProperty("rate");
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
if (!count.hasMultipleDifferentValues)
ProgressBar(count.intValue, "Count");
}
void ProgressBar(float value, string label)
{
Rect rect = GUILayoutUtility.GetRect(18, 18, "TextField");
EditorGUI.ProgressBar(rect, value, label);
EditorGUILayout.Space();
}
}
bar.png
(17.1 kB)
Comment