Пример #1
0
        /// <summary>
        /// Builds the selection tree.
        /// </summary>
        protected override void BuildSelectionTree(OdinMenuTree tree)
        {
            tree.Config.UseCachedExpandedStates        = false;
            tree.DefaultMenuStyle.NotSelectedIconAlpha = 1f;
            if (types == null)
            {
                List <OdinMenuItem> items;
                if (cachedAllTypesMenuItems.TryGetValue(this.assemblyTypeFlags, out items))
                {
                    AddRecursive(tree, items, tree.MenuItems);
                }
                else
                {
                    var assemblyTypes = OrderTypes(AssemblyUtilities.GetTypes(this.assemblyTypeFlags).Where(x => char.IsLetter(x.Name.Trim()[0])));
                    foreach (var t in assemblyTypes)
                    {
                        var    niceName = t.GetNiceName();
                        string path     = this.GetTypeNamePath(t, niceName);
                        var    last     = tree.AddObjectAtPath(path, t).AddThumbnailIcons().Last();
                        last.SearchString = niceName == path ? path : niceName + "|" + path;
                    }

                    cachedAllTypesMenuItems[this.assemblyTypeFlags] = tree.MenuItems;
                }
            }
            else
            {
                foreach (var t in this.types)
                {
                    var    niceName = t.GetNiceName();
                    string path     = this.GetTypeNamePath(t, niceName);
                    var    last     = tree.AddObjectAtPath(path, t).Last();
                    last.SearchString = niceName == path ? path : niceName + "|" + path;

                    if (this.FlattenTree && t.Namespace != null)
                    {
                        last.OnDrawItem += x => GUI.Label(x.Rect.Padding(10, 0).AlignCenterY(16), t.Namespace, SirenixGUIStyles.RightAlignedGreyMiniLabel);
                    }
                }

                tree.EnumerateTree(x => x.Value != null, false).AddThumbnailIcons();
            }

            //tree.EnumerateTree().ForEach(i =>
            //{
            //    var t = i.Value as Type;
            //    if (t != null) { i.SearchString = t.GetNiceFullName(); }
            //});

            tree.Selection.SupportsMultiSelect = this.supportsMultiSelect;
            tree.Selection.SelectionChanged   += (t) =>
            {
                lastType = this.SelectionTree.Selection.Select(x => x.Value).OfType <Type>().LastOrDefault() ?? lastType;
            };
        }
Пример #2
0
        /// <summary>
        /// Builds the selection tree.
        /// </summary>
        protected override void BuildSelectionTree(OdinMenuTree tree)
        {
            tree.DefaultMenuStyle.NotSelectedIconAlpha = 1f;
            if (types == null)
            {
                List <OdinMenuItem> items;
                if (cachedAllTypesMenuItems.TryGetValue(this.assemblyTypeFlags, out items))
                {
                    AddRecursive(tree, items, tree.MenuItems);
                }
                else
                {
                    var assemblyTypes = OrderTypes(AssemblyUtilities.GetTypes(this.assemblyTypeFlags).Where(x => char.IsLetter(x.Name.Trim()[0])));
                    foreach (var t in assemblyTypes)
                    {
                        string path = string.IsNullOrEmpty(t.Namespace) ? t.GetNiceName() : t.Namespace + "/" + t.GetNiceName();
                        tree.AddObjectAtPath(path, t).AddThumbnailIcons();
                    }

                    cachedAllTypesMenuItems[this.assemblyTypeFlags] = tree.MenuItems;
                }
            }
            else
            {
                foreach (var t in this.types)
                {
                    string path = string.IsNullOrEmpty(t.Namespace) ? t.GetNiceName() : t.Namespace + "/" + t.GetNiceName();
                    tree.AddObjectAtPath(path, t);
                }

                tree.EnumerateTree(x => x.ObjectInstance != null, false).AddThumbnailIcons();
            }

            tree.EnumerateTree().ForEach(i =>
            {
                var t = i.ObjectInstance as Type;
                if (t != null)
                {
                    i.SearchString = t.GetNiceFullName();
                }
            });

            tree.Selection.SupportsMultiSelect = this.supportsMultiSelect;
            tree.Selection.SelectionChanged   += (t) =>
            {
                lastType = this.SelectionTree.Selection.Select(x => x.ObjectInstance).OfType <Type>().LastOrDefault() ?? lastType;
            };
        }
        /// <summary>
        /// Builds the selection tree.
        /// </summary>
        protected override void BuildSelectionTree(OdinMenuTree tree)
        {
            tree.Selection.SupportsMultiSelect = this.supportsMultiSelect;
            tree.DefaultMenuStyle = OdinMenuStyle.TreeViewStyle;
            this.getMenuItemName  = this.getMenuItemName ?? (x => x == null ? "" : x.ToString());

            if (this.FlattenedTree)
            {
                if (this.genericSelectorCollection != null)
                {
                    foreach (var item in this.genericSelectorCollection)
                    {
                        tree.MenuItems.Add(new OdinMenuItem(tree, item.GetNiceName(), item.Value));
                    }
                }
                else
                {
                    foreach (var item in this.collection)
                    {
                        tree.MenuItems.Add(new OdinMenuItem(tree, this.getMenuItemName(item), item));
                    }
                }
            }
            else
            {
                if (this.genericSelectorCollection != null)
                {
                    foreach (var item in this.genericSelectorCollection)
                    {
                        tree.AddObjectAtPath(item.GetNiceName(), item.Value);
                    }
                }
                else
                {
                    tree.AddRange(this.collection, this.getMenuItemName);
                }
            }

            if (this.CheckboxToggle)
            {
                tree.EnumerateTree().ForEach(DrawCheckboxMenuItems);
                tree.DefaultMenuStyle.TrianglePadding       -= 17;
                tree.DefaultMenuStyle.Offset                += 18;
                tree.DefaultMenuStyle.SelectedColorDarkSkin  = new Color(1, 1, 1, 0.05f);
                tree.DefaultMenuStyle.SelectedColorLightSkin = new Color(1, 1, 1, 0.05f);
                tree.DefaultMenuStyle.SelectedLabelStyle     = tree.DefaultMenuStyle.DefaultLabelStyle;
                tree.Config.ConfirmSelectionOnDoubleClick    = false;
            }
        }