protected override void OnInspectorRuntimeGUI() { base.OnInspectorRuntimeGUI(); GUILayout.BeginHorizontal(); GUILayout.Label("Current State: " + _currentStateName); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("States: "); GUILayout.EndHorizontal(); foreach (KeyValuePair <string, Type> state in _stateInstances) { GUILayout.BeginHorizontal(); GUILayout.Space(20); GUILayout.Label(state.Key); GUILayout.FlexibleSpace(); GUI.enabled = _currentStateName != state.Key; if (GUILayout.Button("Switch", "Minibutton")) { Target.SwitchState(state.Value); _currentState = Target.GetType().GetField("_currentState", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(Target) as FiniteState; FiniteStateNameAttribute nameAttribute = _currentState.GetType().GetCustomAttribute <FiniteStateNameAttribute>(); _currentStateName = nameAttribute != null ? nameAttribute.Name : _currentState.GetType().Name; } GUI.enabled = true; GUILayout.EndHorizontal(); } }
protected override void OnRuntimeEnable() { base.OnRuntimeEnable(); Dictionary <Type, FiniteState> states = Target.GetType().GetField("_stateInstances", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(Target) as Dictionary <Type, FiniteState>; _stateInstances = new Dictionary <string, Type>(); foreach (KeyValuePair <Type, FiniteState> state in states) { FiniteStateNameAttribute attribute = state.Key.GetCustomAttribute <FiniteStateNameAttribute>(); _stateInstances.Add(attribute != null ? attribute.Name : state.Key.Name, state.Key); } _currentState = Target.GetType().GetField("_currentState", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(Target) as FiniteState; FiniteStateNameAttribute nameAttribute = _currentState.GetType().GetCustomAttribute <FiniteStateNameAttribute>(); _currentStateName = nameAttribute != null ? nameAttribute.Name : _currentState.GetType().Name; }