///Shows the Generic Menu as a browser with CompleteContextMenu. public static void ShowAsBrowser(this GenericMenu menu, Vector2 pos, string title, System.Type keyType) { if (menu != null) { CompleteContextMenu.Show(menu, pos, title, keyType); } }
///Shows the Generic Menu as a browser with CompleteContextMenu. public static void ShowAsBrowser(this GenericMenu menu, string title, System.Type keyType) { if (menu != null) { CompleteContextMenu.Show(menu, Event.current.mousePosition, title, keyType); } }
//Generate the tree node structure out of the items static void GenerateTree() { loadProgress = 0; items = EditorUtils.GetMenuItems(boundMenu); leafNodes = new List <Node>(); for (var i = 0; i < items.Length; i++) { loadProgress = i / (float)items.Length; var item = items[i]; var itemPath = item.content.text; var parts = itemPath.Split('/'); Node current = rootNode; var path = string.Empty; for (var j = 0; j < parts.Length; j++) { var part = parts[j]; path += "/" + part; Node child = null; if (!current.children.TryGetValue(part, out child)) { child = new Node { name = part, parent = current }; child.fullPath = path; current.children[part] = child; if (part == parts.Last()) { child.item = item; leafNodes.Add(child); } } current = child; } } }
public void ToggleFavorite() { SetFavorite(!isFavorite); if (!isFavorite) { if (parent != null && !parent.HasAnyFavoriteChild()) { CompleteContextMenu.RemoveFavorite(parent.fullPath); } } }
//init public CompleteContextMenu(GenericMenu newMenu, string title, System.Type keyType) { current = this; this.title = title; currentKeyType = keyType; rootNode = new Node(); currentNode = rootNode; headerStyle = new GUIStyle("label"); headerStyle.alignment = TextAnchor.UpperCenter; hoveringIndex = -1; SetMenu(newMenu); }
void SetFavorite(bool fav) { if (fav == true) { if (!isFavorite) { CompleteContextMenu.AddFavorite(fullPath); } } if (fav == false) { if (isFavorite) { CompleteContextMenu.RemoveFavorite(fullPath); } } }
void SetFavorite(bool fav) { isFavorite = fav; if (fav == true) { CompleteContextMenu.AddFavorite(fullPath); foreach (var child in children.Values) { child.SetFavorite(fav); } } if (fav == false) { CompleteContextMenu.RemoveFavorite(fullPath); foreach (var child in children.Values) { child.SetFavorite(fav); } } }
//Shows a button that when clicked, pops a context menu with a list of tasks deriving the base type specified. When something is selected the callback is called //On top of that it also shows a search field for Tasks public static void TaskSelectionButton(ITaskSystem ownerSystem, Type baseType, Action <Task> callback) { Action <Type> TaskTypeSelected = (t) => { var newTask = Task.Create(t, ownerSystem); Undo.RecordObject(ownerSystem.baseObject, "New Task"); callback(newTask); }; Func <GenericMenu> GetMenu = () => { var menu = GetTypeSelectionMenu(baseType, TaskTypeSelected); if (Task.copiedTask != null && baseType.IsAssignableFrom(Task.copiedTask.GetType())) { menu.AddItem(new GUIContent(string.Format("Paste ({0})", Task.copiedTask.name)), false, () => { callback(Task.copiedTask.Duplicate(ownerSystem)); }); } return(menu); }; GUI.backgroundColor = lightBlue; GUILayout.BeginHorizontal(); if (GUILayout.Button("Add " + baseType.Name.SplitCamelCase())) { GetMenu().ShowAsContext(); Event.current.Use(); } if (EditorGUIUtility.isProSkin && GUILayout.Button("...", GUILayout.Width(22))) { CompleteContextMenu.Show(GetMenu(), Event.current.mousePosition, "Add Task"); Event.current.Use(); } GUILayout.EndHorizontal(); GUI.backgroundColor = Color.white; GUILayout.BeginHorizontal(); var search = EditorGUILayout.TextField(lastSearch, (GUIStyle)"ToolbarSeachTextField"); if (GUILayout.Button("", (GUIStyle)"ToolbarSeachCancelButton")) { search = string.Empty; GUIUtility.keyboardControl = 0; } GUILayout.EndHorizontal(); if (!string.IsNullOrEmpty(search)) { if (search != lastSearch) { searchResults = GetScriptInfosOfType(baseType); } GUILayout.BeginVertical("TextField"); foreach (var taskInfo in searchResults) { if (taskInfo.name.ToLower().Trim().Contains(search.ToLower().Trim())) { if (GUILayout.Button(taskInfo.name)) { search = string.Empty; GUIUtility.keyboardControl = 0; TaskTypeSelected(taskInfo.type); } } } GUILayout.EndVertical(); } lastSearch = search; }
public static void TaskSelectionButton(ITaskSystem ownerSystem, Type baseType, Action <Task> callback) { Action <Type> TaskTypeSelected = (t) => { var newTask = Task.Create(t, ownerSystem); Undo.RecordObject(ownerSystem.contextObject, "New Task"); callback(newTask); }; Func <GenericMenu> GetMenu = () => { var menu = GetTypeSelectionMenu(baseType, TaskTypeSelected); if (Task.copiedTask != null && baseType.IsAssignableFrom(Task.copiedTask.GetType())) { menu.AddSeparator("/"); menu.AddItem(new GUIContent(string.Format("Paste ({0})", Task.copiedTask.name)), false, () => { callback(Task.copiedTask.Duplicate(ownerSystem)); }); } return(menu); }; GUI.backgroundColor = lightBlue; var label = "Assign " + baseType.Name.SplitCamelCase(); if (GUILayout.Button(label)) { var menu = GetMenu(); if (NodeCanvas.Editor.NCPrefs.useBrowser) { CompleteContextMenu.Show(menu, Event.current.mousePosition, label, typeof(Task)); } else { menu.ShowAsContext(); } Event.current.Use(); } GUI.backgroundColor = Color.white; GUILayout.BeginHorizontal(); search = EditorGUILayout.TextField(search, (GUIStyle)"ToolbarSeachTextField"); if (GUILayout.Button("", (GUIStyle)"ToolbarSeachCancelButton")) { search = string.Empty; GUIUtility.keyboardControl = 0; } GUILayout.EndHorizontal(); if (!string.IsNullOrEmpty(search)) { GUILayout.BeginVertical("TextField"); foreach (var taskInfo in GetScriptInfosOfType(baseType)) { if (taskInfo.name.Replace(" ", "").ToUpper().Contains(search.Replace(" ", "").ToUpper())) { if (GUILayout.Button(taskInfo.name)) { search = string.Empty; GUIUtility.keyboardControl = 0; TaskTypeSelected(taskInfo.type); } } } GUILayout.EndVertical(); } }