protected virtual void OnPreviewGUI(ExecutableNode node) { GUIStyle style = new GUIStyle("IN BigTitle"); style.padding.top = 0; GUILayout.BeginVertical(style); GUILayout.BeginHorizontal(); GUILayout.Label(node.name, EditorStyles.boldLabel); GUILayout.FlexibleSpace(); GUIStyle labelStyle = new GUIStyle("label"); labelStyle.contentOffset = new Vector2(0, 5); if (!string.IsNullOrEmpty(node.GetHelpUrl()) && GUILayout.Button(FsmEditorStyles.helpIcon, labelStyle, GUILayout.Width(20))) { Application.OpenURL(node.GetHelpUrl()); } GUILayout.EndHorizontal(); GUILayout.Space(3f); GUILayout.Label(node.GetTooltip(), FsmEditorStyles.wrappedLabel); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); Node selectedNode = FsmEditor.SelectionCount > 0? FsmEditor.SelectedNodes [0]:null; if (GUILayout.Button(selectedNode != null? "Add to state" : "Select one state to add") && selectedNode != null) { OnAddNode(selectedNode, node.GetType()); NodeInspector.Dirty(); } GUILayout.EndHorizontal(); GUILayout.EndVertical(); if (PreferencesEditor.GetBool(Preference.ActionBrowserShowPreview, true)) { EditorGUI.BeginDisabledGroup(true); GUIDrawer.OnGUI(node); EditorGUI.EndDisabledGroup(); GUILayout.Space(5); } }
private List <FsmVariable> GetReferencedVariables(StateMachine fsm, string name) { List <FsmVariable> variables = new List <FsmVariable> (); ExecutableNode[] nodes = fsm.ExecutableNodesRecursive; for (int i = 0; i < nodes.Length; i++) { ExecutableNode mNode = nodes[i]; FieldInfo[] fields = mNode.GetType().GetPublicFields(); for (int k = 0; k < fields.Length; k++) { FieldInfo fieldInfo = fields[k]; if (typeof(FsmVariable).IsAssignableFrom(fieldInfo.FieldType)) { FsmVariable variable = (FsmVariable)fieldInfo.GetValue(mNode); if (variable != null && variable.IsShared && variable.Name == name) { variables.Add(variable); } } } } return(variables); }
public static GenericMenu ExecutableContextMenu(ExecutableNode executable, Node node) { GenericMenu menu = new GenericMenu(); if (executable == null) { return(menu); } menu.AddItem(new GUIContent("Enable"), executable.IsEnabled, delegate() { executable.IsEnabled = !executable.IsEnabled; }); menu.AddSeparator(""); menu.AddItem(new GUIContent("Find Script"), false, delegate() { MonoScript[] monoScriptArray = (MonoScript[])Resources.FindObjectsOfTypeAll(typeof(MonoScript)); Selection.activeObject = monoScriptArray.ToList().Find(x => x.GetClass() == executable.GetType()); }); menu.AddItem(new GUIContent("Edit Script"), false, delegate() { MonoScript[] monoScriptArray = (MonoScript[])Resources.FindObjectsOfTypeAll(typeof(MonoScript)); Selection.activeObject = monoScriptArray.ToList().Find(x => x.GetClass() == executable.GetType()); AssetDatabase.OpenAsset(Selection.activeObject); }); menu.AddSeparator(""); bool moveDown = false; int currentIndex = -1; if (executable.GetType().IsSubclassOf(typeof(StateAction))) { State state = node as State; currentIndex = Array.IndexOf(state.Actions, executable); moveDown = currentIndex + 1 < state.Actions.Length; } else { currentIndex = Array.IndexOf(FsmEditor.SelectedTransition.Conditions, executable); moveDown = currentIndex + 1 < FsmEditor.SelectedTransition.Conditions.Length; } if (currentIndex - 1 >= 0) { menu.AddItem(new GUIContent("Move Up"), false, delegate() { if (executable.GetType().IsSubclassOf(typeof(StateAction))) { State state = node as State; state.Actions = ArrayUtility.MoveItem(state.Actions, currentIndex, currentIndex - 1); } else { FsmEditor.SelectedTransition.Conditions = ArrayUtility.MoveItem(FsmEditor.SelectedTransition.Conditions, currentIndex, currentIndex - 1); } NodeInspector.Dirty(); }); } else { menu.AddDisabledItem(new GUIContent("Move Up")); } if (moveDown) { menu.AddItem(new GUIContent("Move Down"), false, delegate() { if (executable.GetType().IsSubclassOf(typeof(StateAction))) { State state = node as State; state.Actions = ArrayUtility.MoveItem(state.Actions, currentIndex, currentIndex + 1); } else { FsmEditor.SelectedTransition.Conditions = ArrayUtility.MoveItem(FsmEditor.SelectedTransition.Conditions, currentIndex, currentIndex + 1); } NodeInspector.Dirty(); }); } else { menu.AddDisabledItem(new GUIContent("Move Down")); } menu.AddSeparator(""); menu.AddItem(new GUIContent("Copy"), false, delegate() { executableCopy = executable; }); if (executableCopy != null) { menu.AddItem(new GUIContent("Paste After"), false, delegate() { ExecutableNode dest = FsmUtility.Copy(executableCopy); if (dest.GetType().IsSubclassOf(typeof(StateAction))) { State state = node as State; state.Actions = ArrayUtility.Insert <StateAction>(state.Actions, (StateAction)dest, currentIndex + 1); } else { FsmEditor.SelectedTransition.Conditions = ArrayUtility.Insert <Condition>(FsmEditor.SelectedTransition.Conditions, (Condition)dest, currentIndex + 1); } FsmEditorUtility.ParentChilds(node); NodeInspector.Dirty(); }); menu.AddItem(new GUIContent("Paste Before"), false, delegate() { ExecutableNode dest = FsmUtility.Copy(executableCopy); if (dest.GetType().IsSubclassOf(typeof(StateAction))) { State state = node as State; state.Actions = ArrayUtility.Insert <StateAction>(state.Actions, (StateAction)dest, currentIndex); } else { FsmEditor.SelectedTransition.Conditions = ArrayUtility.Insert <Condition>(FsmEditor.SelectedTransition.Conditions, (Condition)dest, currentIndex); } FsmEditorUtility.ParentChilds(node); NodeInspector.Dirty(); }); menu.AddItem(new GUIContent("Replace"), false, delegate() { ExecutableNode dest = FsmUtility.Copy(executableCopy); if (dest.GetType().IsSubclassOf(typeof(StateAction))) { State state = node as State; FsmEditorUtility.DestroyImmediate(state.Actions[currentIndex]); state.Actions = ArrayUtility.RemoveAt <StateAction>(state.Actions, currentIndex); state.Actions = ArrayUtility.Insert <StateAction>(state.Actions, (StateAction)dest, currentIndex); } else { FsmEditorUtility.DestroyImmediate(FsmEditor.SelectedTransition.Conditions[currentIndex]); FsmEditor.SelectedTransition.Conditions = ArrayUtility.RemoveAt <Condition>(FsmEditor.SelectedTransition.Conditions, currentIndex); FsmEditor.SelectedTransition.Conditions = ArrayUtility.Insert <Condition>(FsmEditor.SelectedTransition.Conditions, (Condition)dest, currentIndex); } FsmEditorUtility.ParentChilds(node); NodeInspector.Dirty(); }); } else { menu.AddDisabledItem(new GUIContent("Paste After")); menu.AddDisabledItem(new GUIContent("Paste Before")); menu.AddDisabledItem(new GUIContent("Replace")); } menu.AddSeparator(""); menu.AddItem(new GUIContent("Remove"), false, delegate() { if (executable.GetType().IsSubclassOf(typeof(StateAction))) { State state = node as State; state.Actions = ArrayUtility.Remove <StateAction> (state.Actions, (StateAction)executable); } else { FsmEditor.SelectedTransition.Conditions = ArrayUtility.Remove <Condition>(FsmEditor.SelectedTransition.Conditions, (Condition)executable); } FsmEditorUtility.DestroyImmediate(executable); NodeInspector.Dirty(); }); return(menu); }
public static bool NodeTitlebar(ExecutableNode executable, Node node) { int controlID = EditorGUIUtility.GetControlID(FocusType.Passive); GUIContent content = new GUIContent(executable.name.Replace("/", "."), executable.GetType().GetTooltip()); Rect position = GUILayoutUtility.GetRect(GUIContent.none, FsmEditorStyles.inspectorTitle); Rect rect = new Rect(position.x + (float)FsmEditorStyles.inspectorTitle.padding.left, position.y + (float)FsmEditorStyles.inspectorTitle.padding.top, 16f, 16f); Rect rect1 = new Rect(position.xMax - (float)FsmEditorStyles.inspectorTitle.padding.right - 2f - 16f, rect.y, 16f, 16f); Rect rect4 = rect1; rect4.x = rect4.x - 18f; Rect rect2 = new Rect(position.x + 2f + 2f + 16f * 2, rect.y, 100f, rect.height) { xMax = rect4.xMin - 2f }; Rect rect3 = new Rect(position.x + 16f, rect.y, 16f, 16f); executable.IsEnabled = GUI.Toggle(rect3, executable.IsEnabled, GUIContent.none); string url = executable.GetType().GetHelpUrl(); if (ErrorChecker.HasErrors(executable)) { Rect rect5 = rect4; rect5.y += 1.0f; if (!string.IsNullOrEmpty(url)) { rect5.x = rect5.x - 18f; rect2.xMax = rect5.x; } GUI.Label(rect5, FsmEditorStyles.errorIcon, FsmEditorStyles.inspectorTitleText); } if (GUI.Button(rect1, FsmEditorStyles.popupIcon, FsmEditorStyles.inspectorTitleText)) { ExecutableContextMenu(executable, node).ShowAsContext(); } if (!string.IsNullOrEmpty(url) && GUI.Button(rect4, FsmEditorStyles.helpIcon, FsmEditorStyles.inspectorTitleText)) { Application.OpenURL(url); } EventType eventType = Event.current.type; if (eventType != EventType.MouseDown) { if (eventType == EventType.Repaint) { FsmEditorStyles.inspectorTitle.Draw(position, GUIContent.none, controlID, executable.IsOpen); FsmEditorStyles.inspectorTitleText.Draw(rect2, content, controlID, executable.IsOpen); } } position.width = 15; bool flag = DoToggleForward(position, controlID, executable.IsOpen, GUIContent.none, GUIStyle.none); if (flag != executable.IsOpen) { executable.IsOpen = flag; } return(flag); }
private void OnGUI() { GUILayout.BeginHorizontal(); DoSearch(); DoSettings(); GUILayout.EndHorizontal(); GUILayout.Space(2.0f); scroll = GUILayout.BeginScrollView(scroll); foreach (KeyValuePair <string, List <Type> > kvp in sortedTypes) { bool foldout = EditorPrefs.GetBool(kvp.Key, false); if (string.IsNullOrEmpty(searchString)) { if (GUILayout.Button(kvp.Key, (foldout?(GUIStyle)"TE toolbarbutton" : EditorStyles.toolbarButton))) { foldout = !foldout; EditorPrefs.SetBool(kvp.Key, foldout); } } else { foldout = true; } if (foldout) { foreach (Type actionType in kvp.Value) { if (!string.IsNullOrEmpty(searchString) && !actionType.Name.ToLower().StartsWith(searchString.ToLower())) { continue; } Color color = GUI.contentColor; GUI.contentColor = (active != null && actionType == active.GetType() ? EditorStyles.foldout.focused.textColor : color); if (GUILayout.Button(string.IsNullOrEmpty(searchString)?actionType.Name:actionType.GetCategory() + "." + actionType.Name, "label", GUILayout.ExpandWidth(true))) { DestroyActive(); ExecutableNode node = (ExecutableNode)ScriptableObject.CreateInstance(actionType); node.hideFlags = HideFlags.HideAndDontSave; node.name = actionType.Name; active = node; if ((EditorApplication.timeSinceStartup - clickTime) < doubleClickTime) { if (FsmEditor.Active != null) { int selectedStatesCount = FsmEditor.SelectionCount; if (selectedStatesCount == 0) { EditorUtility.DisplayDialog("Could not add node " + active.GetType().Name + "!", "Select a state before adding nodes.", "Cancel"); } else if (selectedStatesCount == 1) { Node selectedNode = FsmEditor.SelectedNodes[0]; OnAddNode(selectedNode, active.GetType()); NodeInspector.Dirty(); } else { EditorUtility.DisplayDialog("Could not add node " + active.GetType().Name + "!", "Select only one state. Adding nodes to multiple states is not supported.", "Cancel"); } } } clickTime = EditorApplication.timeSinceStartup; } GUI.contentColor = color; } } } GUILayout.EndScrollView(); if (active != null) { OnPreviewGUI(active); } }