Last active
October 1, 2016 05:00
-
-
Save adarapata/f37f2efb6882a1054135c53a1cac41f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
using System.Linq; | |
using UniRx; | |
[CustomEditor(typeof(ObserveTransition))] | |
public class ObserveTransitionInspector : Editor { | |
public override void OnInspectorGUI() | |
{ | |
serializedObject.Update(); | |
var transition = serializedObject.targetObject as ObserveTransition; | |
var behaviours = transition.state.behaviours | |
.Where(b => !b.Equals(transition)).ToList(); | |
if (behaviours.Count > 0) | |
{ | |
if(transition.target == null) { transition.target = behaviours.First(); } | |
int index = EditorGUILayout.Popup("BehaviourName", behaviours.FindIndex(b => transition.target.Equals(b)) , behaviours.Select(o => o.GetType().Name).ToArray()); | |
transition.target = behaviours[index]; | |
var methods = transition.target.GetType().GetMethods(); | |
var obs = methods.Where(m => m.ReturnType == typeof(IObservable<Unit>)).ToList(); | |
if (obs.Count > 0) | |
{ | |
int methodIndex = EditorGUILayout.Popup("ObservableMethod", obs.FindIndex(o => o.Name == transition.methodName) , obs.Select(o => o.Name).ToArray()); | |
if(methodIndex < 0) { methodIndex = 0; } | |
transition.methodName = obs[methodIndex].Name; | |
} | |
} | |
serializedObject.ApplyModifiedProperties(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment