private void Setup(SelectionState state, SelectionTree tree) { CreateTrees(tree); SetState(state); RebuildSearch(); wantsMouseMove = true; }
public static void Show(int id, Rect position, SelectionState state, SelectionTree tree) { if (_instance != null) { _instance.Close(); } _selectionId = id; _selectionMade = false; _selectionState = state; _instance = CreateInstance <SelectionPopup>(); _instance.Setup(state, tree); _instance.ShowAsDropDown(position, new Vector2(Mathf.Max(_minimumWidth, position.width), _windowHeight)); _instance.position = new Rect(GUIUtility.GUIToScreenPoint(new Vector2(position.x, position.yMax)), position.size); }
private void CreateTrees(SelectionTree tree) { for (var t = 0; t < tree.Labels.Count; t++) { var items = tree.Items[t]; var label = tree.Labels[t]; var root = TreeItem.Branch(string.Empty, label, null); var rootPath = label.text + "/"; var leaves = new List <TreeItem>(); for (var index = 0; index < items.Length; index++) { var node = items[index]; var fullPath = rootPath + node.text; var submenus = fullPath.Split('/'); var path = rootPath; var child = root; for (var i = 1; i < submenus.Length - 1; i++) { var menu = submenus[i]; path += menu + "/"; var previousChild = child; child = GetChild(child, path); if (child == null) { child = TreeItem.Branch(path, new GUIContent(menu, _folderIcon.Content.image), previousChild); } } leaves.Add(TreeItem.Leaf(index, path, new GUIContent(submenus.Last(), node.image ?? _defaultTypeIcon.Content.image), child)); } _roots.Add(root); _searchList.Add(leaves); } }
public static SelectionState Draw(Rect position, GUIContent label, SelectionState state, SelectionTree tree) { return(Draw(position, label, GUI.skin.button, state, tree)); }
public static SelectionState Draw(Rect position, GUIContent label, GUIStyle style, SelectionState state, SelectionTree tree) { var id = GUIUtility.GetControlID(FocusType.Passive); if (GUI.Button(position, label, style)) { Show(id, position, state, tree); } if (HasSelection(id)) { GUI.changed = true; return(TakeSelection()); } return(state); }