private void SelectTransition(int index) { this.transition = transitions [index]; FsmEditor.SelectTransition(this.transition); this.ResetConditionList(); }
public void OnDisable() { FsmEditor.SelectTransition(null); }
public void ResetTransitionList() { SerializedObject obj = new SerializedObject(node); SerializedProperty elements = obj.FindProperty("transitions"); transitionList = new ReorderableObjectList(obj, elements); transitionList.drawHeaderCallback = delegate(Rect rect) { EditorGUI.LabelField(rect, "Transitions"); EditorGUI.LabelField(new Rect(rect.width - 25, rect.y, 50, 20), "Mute"); }; transitionList.onSelectCallback = delegate(int index) { if (node.Transitions.Length > 0) { FsmEditor.SelectTransition(this.node.Transitions[index]); this.ResetConditionList(); } }; transitionList.onRemoveCallback = delegate(ReorderableObjectList list) { Transition transition = node.Transitions[list.index]; node.Transitions = ArrayUtility.Remove(node.Transitions, transition); FsmEditorUtility.DestroyImmediate(transition); list.index = Mathf.Clamp(list.index - 1, 0, list.count - 1); ErrorChecker.CheckForErrors(); EditorUtility.SetDirty(node); }; transitionList.drawElementCallback = delegate(int index, bool selected) { Transition transition = node.Transitions [index]; if (selected) { GUIStyle selectBackground = new GUIStyle("MeTransitionSelectHead") { stretchHeight = false, }; selectBackground.overflow = new RectOffset(-1, -2, -2, 2); GUILayout.BeginVertical(selectBackground); } GUILayout.BeginHorizontal(); for (int i = 0; i < transition.Conditions.Length; i++) { Condition condition = transition.Conditions[i]; if (ErrorChecker.HasErrors(condition)) { GUILayout.Label(FsmEditorStyles.errorIcon); break; } } GUILayout.Label(transition.FromNode.Name + " -> " + transition.ToNode.Name, selected?EditorStyles.whiteLabel:EditorStyles.label); GUILayout.FlexibleSpace(); transition.Mute = GUILayout.Toggle(transition.Mute, GUIContent.none, GUILayout.Width(15)); GUILayout.Space(22f); GUILayout.EndHorizontal(); if (selected) { GUILayout.EndVertical(); } }; transitionList.onReorderCallback = delegate(ReorderableObjectList list) { FsmEditor.SelectTransition(this.node.Transitions[list.index]); this.ResetConditionList(); }; transitionList.onContextClick = delegate(int index) { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Remove"), false, delegate() { Transition transition = node.Transitions[index]; node.Transitions = ArrayUtility.Remove(node.Transitions, transition); FsmEditorUtility.DestroyImmediate(transition); transitionList.index = Mathf.Clamp((index == transitionList.index?index - 1:(index < transitionList.index?transitionList.index - 1:transitionList.index)), 0, node.Transitions.Length - 1); ErrorChecker.CheckForErrors(); EditorUtility.SetDirty(node); }); menu.ShowAsContext(); }; this.ResetConditionList(); this.host.Repaint(); if (FsmEditor.instance != null) { FsmEditor.instance.Repaint(); } }