soundvision/UnityProject/Assets/Editor/StateManagerEditor.cs

47 lines
1.6 KiB
C#
Raw Normal View History

using UnityEditor;
using UnityEngine;
namespace cylvester
{
[CustomEditor(typeof(StateManager))]
2019-11-01 10:41:06 +00:00
public class StateManagerEditor : Editor
{
2019-11-01 10:41:06 +00:00
private string[] titles_;
public override void OnInspectorGUI ()
{
var csvFileName = serializedObject.FindProperty("csvFileName");
var onStateChanged = serializedObject.FindProperty("onStateChanged");
var sceneSelection = serializedObject.FindProperty("sceneSelection");
serializedObject.Update();
EditorGUILayout.PropertyField(csvFileName);
EditorGUILayout.PropertyField(onStateChanged);
if (Application.isPlaying)
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Current State");
2019-11-01 10:41:06 +00:00
var states = ((IStateManager) target).States;
var newValue = EditorGUILayout.Popup(sceneSelection.intValue, GetTitles(states));
if (newValue != sceneSelection.intValue)
2019-11-01 10:41:06 +00:00
((IStateManager) target).SelectedState = newValue;
EditorGUILayout.EndHorizontal();
}
serializedObject.ApplyModifiedProperties();
}
2019-11-01 10:41:06 +00:00
private string[] GetTitles(State[] states)
{
if (titles_ != null)
return titles_;
titles_ = new string[states.Length];
for (var i = 0; i < states.Length; ++i)
titles_[i] = states[i].Title;
return titles_;
}
}
}