private void ResetActionList() { SerializedObject obj = new SerializedObject(state); SerializedProperty elements = obj.FindProperty("actions"); actionList = new ReorderableObjectList(obj, elements); actionList.drawHeaderCallback = delegate(Rect rect) { EditorGUI.LabelField(rect, "Actions"); }; actionList.onAddCallback = delegate(ReorderableObjectList list) { FsmGUIUtility.SubclassMenu <StateAction> (delegate(Type type){ StateAction action = (StateAction)ScriptableObject.CreateInstance(type); action.name = type.GetCategory() + "." + type.Name; action.hideFlags = HideFlags.HideInHierarchy; state.Actions = ArrayUtility.Add <StateAction> (state.Actions, action); if (EditorUtility.IsPersistent(state)) { AssetDatabase.AddObjectToAsset(action, state); AssetDatabase.SaveAssets(); } list.index = list.count; EditorUtility.SetDirty(state); }); }; actionList.drawElementCallback = delegate(int index, bool selected) { StateAction action = state.Actions [index]; bool enabled = action.IsEnabled; if (selected) { GUIStyle selectBackground = new GUIStyle("MeTransitionSelectHead") { stretchHeight = false, }; selectBackground.overflow = new RectOffset(-1, -2, -2, 2); GUILayout.BeginVertical(selectBackground); } action.IsOpen = GUIDrawer.ObjectTitlebar(action, action.IsOpen, ref enabled, FsmGUIUtility.ExecutableContextMenu(action, state)); if (selected) { GUILayout.EndVertical(); } action.IsEnabled = enabled; if (action.IsOpen) { GUIDrawer.OnGUI(action); } }; actionList.onRemoveCallback = delegate(ReorderableObjectList list) { StateAction action = state.Actions[list.index]; state.Actions = ArrayUtility.Remove <StateAction> (state.Actions, action); FsmEditorUtility.DestroyImmediate(action); list.index = list.index - 1; ErrorChecker.CheckForErrors(); EditorUtility.SetDirty(state); }; actionList.onContextClick = delegate(int index) { FsmGUIUtility.ExecutableContextMenu(state.Actions [index], state).ShowAsContext(); }; actionList.onHeaderContextClick = delegate() { GenericMenu menu = new GenericMenu(); if (state.Actions.Length > 0) { menu.AddItem(new GUIContent("Copy"), false, delegate { copy = new List <StateAction>(state.Actions); copyState = state; }); } else { menu.AddDisabledItem(new GUIContent("Copy")); } if (copy == null) { copy = new List <StateAction>(); } copy.RemoveAll(x => x == null); if (copy.Count > 0) { menu.AddItem(new GUIContent("Paste After"), false, delegate() { for (int i = 0; i < copy.Count; i++) { ExecutableNode dest = FsmUtility.Copy(copy[i]); state.Actions = ArrayUtility.Add <StateAction>(state.Actions, (StateAction)dest); FsmEditorUtility.ParentChilds(state); EditorUtility.SetDirty(state); // NodeInspector.Dirty(); ErrorChecker.CheckForErrors(); } }); menu.AddItem(new GUIContent("Paste Before"), false, delegate() { for (int i = 0; i < copy.Count; i++) { ExecutableNode dest = FsmUtility.Copy(copy[i]); state.Actions = ArrayUtility.Insert <StateAction>(state.Actions, (StateAction)dest, 0); FsmEditorUtility.ParentChilds(state); EditorUtility.SetDirty(state); // NodeInspector.Dirty(); ErrorChecker.CheckForErrors(); } }); if (copyState != state) { menu.AddItem(new GUIContent("Replace"), false, delegate() { for (int i = 0; i < state.Actions.Length; i++) { FsmEditorUtility.DestroyImmediate(state.Actions[i]); } state.Actions = new StateAction[0]; ResetActionList(); for (int i = 0; i < copy.Count; i++) { ExecutableNode dest = FsmUtility.Copy(copy[i]); state.Actions = ArrayUtility.Add <StateAction>(state.Actions, (StateAction)dest); FsmEditorUtility.ParentChilds(state); EditorUtility.SetDirty(state); // NodeInspector.Dirty(); ErrorChecker.CheckForErrors(); } }); } else { menu.AddDisabledItem(new GUIContent("Replace")); } } else { menu.AddDisabledItem(new GUIContent("Paste After")); menu.AddDisabledItem(new GUIContent("Paste Before")); menu.AddDisabledItem(new GUIContent("Replace")); } menu.ShowAsContext(); }; this.host.Repaint(); if (FsmEditor.instance != null) { FsmEditor.instance.Repaint(); } }
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(); } }