Ejemplo n.º 1
0
        private static void Add(Type type)
        {
            string path = PopupMenuUtility.GetFullLabel(type, GlobalNameSpacePrefix);

            if (string.IsNullOrEmpty(path))
            {
                RegisterComponentHiddenInMenu(type);
                return;
            }

            if (path.StartsWith("UnityEngine/", StringComparison.Ordinal))
            {
                if (path.EndsWith("Effect", StringComparison.Ordinal))
                {
                    path = "Effects" + path.Substring(path.LastIndexOf('/'));
                }
                else if (path.EndsWith("Renderer", StringComparison.Ordinal))
                {
                    path = "Rendering" + path.Substring(path.LastIndexOf('/'));
                }
                else
                {
                    path = "Miscellaneous" + path.Substring(path.LastIndexOf('/'));
                }
            }

            path = StringUtils.SplitPascalCaseToWords(path);
            Add(type, path);
        }
Ejemplo n.º 2
0
 /// <inheritdoc />
 protected override void GenerateMenuItems(ref List <PopupMenuItem> rootItems, ref Dictionary <string, PopupMenuItem> groupsByLabel, ref Dictionary <string, PopupMenuItem> itemsByLabel)
 {
     for (int n = items.Length - 1; n >= 0; n--)
     {
         var item = items[n];
         PopupMenuUtility.BuildPopupMenuItemWithLabel(ref rootItems, ref groupsByLabel, ref itemsByLabel, n, null, item, "", null);
     }
 }
Ejemplo n.º 3
0
        public static void Open([NotNull] IInspector inspector, [NotNull] List <PopupMenuItem> rootItems, Rect unrollPosition, Action <PopupMenuItem> onMenuItemClicked, [CanBeNull] Action onClosed, GUIContent label, [CanBeNull] IDrawer subject)
        {
            int count         = rootItems.Count;
            var groupsByLabel = new Dictionary <string, PopupMenuItem>(count);
            var itemsByLabel  = new Dictionary <string, PopupMenuItem>(count);

            PopupMenuUtility.GenerateByLabelDictionaries(rootItems, groupsByLabel, itemsByLabel);
            Open(inspector, rootItems, groupsByLabel, itemsByLabel, null, false, unrollPosition, onMenuItemClicked, onClosed, label, subject);
        }
Ejemplo n.º 4
0
        protected virtual void GetTickedMenuItems(List <PopupMenuItem> rootItems, ref List <PopupMenuItem> results)
        {
            var find = PopupMenuUtility.FindMenuItemByIdentifyingObject(rootItems, Value);

            if (find != null)
            {
                results.Add(find);
            }
        }
Ejemplo n.º 5
0
        private void GenerateTypeSelectorMenuItems(ref List <PopupMenuItem> rootItems, ref Dictionary <string, PopupMenuItem> groupsByLabel, ref Dictionary <string, PopupMenuItem> itemsByLabel)
        {
            if (typeContext == null)
            {
                typeContext = PopupMenuUtility.GetTypeContext(memberInfo, parent);
            }

            PopupMenuUtility.BuildTypePopupMenuItemsForContext(ref rootItems, ref groupsByLabel, ref itemsByLabel, typeContext, true);
        }
Ejemplo n.º 6
0
        private static void Add(Type type)
        {
            string path = PopupMenuUtility.GetFullLabel(type, GlobalNameSpacePrefix);

            if (string.IsNullOrEmpty(path))
            {
                RegisterComponentHiddenInMenu(type);
                return;
            }
            path = StringUtils.SplitPascalCaseToWords(path);
            Add(type, path);
        }
Ejemplo n.º 7
0
        /// <inheritdoc />
        protected override void GetTickedMenuItems(List <PopupMenuItem> rootItems, ref List <PopupMenuItem> results)
        {
                        #if DEV_MODE
            Debug.Assert(results.Count == 0);
                        #endif

            if (hasFlagsAttribute)
            {
                var value        = Value;
                var defaultValue = (Enum)DefaultValue();

                if (value.Equals(defaultValue))
                {
                    if (!AddClearAllMenuItem())
                    {
                        FindMenuItemsForFlag(rootItems, Value, ref results, defaultValue);
                    }
                                        #if TICK_CLEAR_ALL_ITEM_IN_MENU
                    else
                    {
                        results.Add(rootItems[SelectNoneMenuItemIndex]);
                    }
                                        #endif
                    return;
                }

                var allFlags = Value.GetFlags();
                for (int n = allFlags.Count - 1; n >= 0; n--)
                {
                    int count = results.Count;

                    var flag = allFlags[n];

                    if (flag.Equals(defaultValue))
                    {
                        continue;
                    }

                    FindMenuItemsForFlag(rootItems, allFlags[n], ref results, defaultValue);
                }
            }
            else
            {
                var find = PopupMenuUtility.FindMenuItemByIdentifyingObject(rootItems, Value);
                if (find != null)
                {
                    results.Add(find);
                }
            }
        }
Ejemplo n.º 8
0
        /// <inheritdoc />
        protected override void GenerateMenuItems(ref List <PopupMenuItem> rootItems, ref Dictionary <string, PopupMenuItem> groupsByLabel, ref Dictionary <string, PopupMenuItem> itemsByLabel)
        {
            PopupMenuUtility.BuildPopupMenuItemsForEnumType(ref rootItems, ref groupsByLabel, ref itemsByLabel, typeContext);

            if (AddClearAllMenuItem())
            {
                // only add if menu doesn't already contain entry by name
                if (!itemsByLabel.ContainsKey(SelectNoneMenuItemLabel))
                {
                    var item = PopupMenuItem.Item(null as Type, SelectNoneMenuItemLabel, "0", null);
                    rootItems.Insert(0, item);
                    itemsByLabel.Add(SelectNoneMenuItemLabel, item);
                }
            }
        }
Ejemplo n.º 9
0
        private void OnCreateInstanceButtonClicked()
        {
            DrawGUI.Use(Event.current);

            var nonUnityObjectTypes = NonUnityObjectTypes;
            int count = nonUnityObjectTypes.Length;

            if (count <= 1)
            {
                if (count == 1)
                {
                    SetValueFromType(nonUnityObjectTypes[0]);
                }
                return;
            }

            if (!menuItemsGenerated || menuItemsGeneratedForType != Type)
            {
                generatedMenuItems.Clear();
                generatedGroupsByLabel.Clear();
                generatedItemsByLabel.Clear();
                for (int n = 0; n < count; n++)
                {
                    PopupMenuUtility.BuildPopupMenuItemForType(ref generatedMenuItems, ref generatedGroupsByLabel, ref generatedItemsByLabel, nonUnityObjectTypes[n]);
                }
                menuItemsGenerated        = true;
                menuItemsGeneratedForType = Type;
            }

            var inspector = InspectorUtility.ActiveInspector;

            PopupMenuManager.Open(inspector, generatedMenuItems, generatedGroupsByLabel, generatedItemsByLabel, ControlPosition, OnPopupMenuItemClicked, OnPopupMenuClosed, GUIContentPool.Create("Type"), this);

            if (!IsNull)
            {
                var selectItemOfType = Value.GetType();
                if (selectItemOfType != null)
                {
                    PopupMenuManager.SelectItem(PopupMenuUtility.GetFullLabel(selectItemOfType));
                }
            }
        }
Ejemplo n.º 10
0
 /// <inheritdoc />
 protected override void GenerateMenuItems(ref List <PopupMenuItem> rootItems, ref Dictionary <string, PopupMenuItem> groupsByLabel, ref Dictionary <string, PopupMenuItem> itemsByLabel)
 {
     PopupMenuUtility.BuildTypePopupMenuItemsForContext(ref rootItems, ref groupsByLabel, ref itemsByLabel, GetTypeContext(), true);
 }
Ejemplo n.º 11
0
 /// <inheritdoc />
 protected override Type GetTypeContext()
 {
     return(PopupMenuUtility.GetTypeContext(memberInfo, parent));
 }
        /// <inheritdoc />
        protected override void GenerateMenuItems(ref List <PopupMenuItem> rootItems, ref Dictionary <string, PopupMenuItem> groupsByLabel, ref Dictionary <string, PopupMenuItem> itemsByLabel)
        {
                        #if DEV_MODE || PROFILE_POWER_INSPECTOR
            Profiler.BeginSample("ConstraintedTypeDrawer.GenerateMenuItems");
                        #endif

            var types = TypeExtensions.GetAllTypesThreadSafe(true, false, false);

            if (typeCategoryConstraint.HasFlag(TypeConstraint.Struct))
            {
                types = types.Where((t) => t.IsValueType && t != typeof(Nullable <>));
            }
            else
            {
                if (typeCategoryConstraint.HasFlag(TypeConstraint.Class))
                {
                    types = types.Where((t) => !t.IsValueType);
                }

                if (typeCategoryConstraint.HasFlag(TypeConstraint.New))
                {
                    types = types.Where((t) => t.GetConstructor(Type.EmptyTypes) != null);
                }
            }

            switch (baseTypeConstraints.Length)
            {
            case 0:
                foreach (var type in types)
                {
                    PopupMenuUtility.BuildPopupMenuItemForTypeWithLabel(ref rootItems, ref groupsByLabel, ref itemsByLabel, type, TypeExtensions.GetPopupMenuLabel(type));
                }
                break;

            case 1:
                foreach (var type in types)
                {
                    if (baseTypeConstraints[0].IsAssignableFrom(type))
                    {
                        PopupMenuUtility.BuildPopupMenuItemForTypeWithLabel(ref rootItems, ref groupsByLabel, ref itemsByLabel, type, TypeExtensions.GetPopupMenuLabel(type));
                    }
                    break;
                }
                break;

            default:
                foreach (var type in types)
                {
                    bool assignable = true;
                    for (int n = baseTypeConstraints.Length - 1; n >= 0; n--)
                    {
                        if (!baseTypeConstraints[n].IsAssignableFrom(type))
                        {
                            assignable = false;
                            break;
                        }
                    }
                    if (assignable)
                    {
                        PopupMenuUtility.BuildPopupMenuItemForTypeWithLabel(ref rootItems, ref groupsByLabel, ref itemsByLabel, type, TypeExtensions.GetPopupMenuLabel(type));
                    }
                }
                break;
            }

            rootItems.Sort();
            for (int n = rootItems.Count - 1; n >= 0; n--)
            {
                rootItems[n].Sort();
            }

            var nullItem = PopupMenuItem.Item(null as Type, "None", "A null reference; one that does not refer to any object.", null);
            nullItem.Preview = null;
            rootItems.Insert(0, nullItem);
            itemsByLabel.Add(nullItem.label, nullItem);

                        #if DEV_MODE || PROFILE_POWER_INSPECTOR
            Profiler.EndSample();
                        #endif
        }
Ejemplo n.º 13
0
 /// <inheritdoc />
 protected override string GetPopupItemLabel(Type value)
 {
     return(PopupMenuUtility.GetFullLabel(value));
 }
Ejemplo n.º 14
0
        private static void SetupThreaded(object threadTaskId)
        {
                        #if DEV_MODE
            var timer = new ExecutionTimeLogger();
            timer.Start("MemberInfoBaseDrawerData.SetupThreaded");
            timer.StartInterval("Generate PopupMenuItems");
                        #endif

            var sb = new System.Text.StringBuilder();
            foreach (var type in TypeExtensions.AllVisibleAndUniqueTypes)
            {
                sb.Append(TypeExtensions.GetPopupMenuLabel(type, ""));
                sb.Append('/');
                string typePrefix = sb.ToString();
                sb.Length = 0;

                var fields = type.GetFields(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
                for (int f = fields.Length - 1; f >= 0; f--)
                {
                    var field = fields[f];
                    sb.Append(typePrefix);
                    sb.Append(field.Name);
                    string menuPath = sb.ToString();
                    sb.Length = 0;
                    PopupMenuUtility.BuildPopupMenuItemWithLabel(ref fieldRootItems, ref fieldGroupsByLabel, ref fieldItemsByLabel, field, menuPath, MenuItemValueType.Undefined);
                }

                var properties = type.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
                for (int p = properties.Length - 1; p >= 0; p--)
                {
                    var property = properties[p];
                    sb.Append(typePrefix);
                    StringUtils.ToString(property, sb);

                    string menuPath = sb.ToString();
                    sb.Length = 0;
                    PopupMenuUtility.BuildPopupMenuItemWithLabel(ref propertyRootItems, ref propertyGroupsByLabel, ref propertyItemsByLabel, property, menuPath, MenuItemValueType.Undefined);
                }

                var methods = type.GetMethods(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);

                for (int m = methods.Length - 1; m >= 0; m--)
                {
                    var method = methods[m];

                    sb.Append(typePrefix);
                    StringUtils.ToString(method, sb);
                    string menuPath = sb.ToString();
                    sb.Length = 0;

                    PopupMenuUtility.BuildPopupMenuItemWithLabel(ref methodRootItems, ref methodGroupsByLabel, ref methodItemsByLabel, method, menuPath, MenuItemValueType.Undefined);
                }
            }

                        #if DEV_MODE
            timer.FinishInterval();
            timer.StartInterval("allRootItems.AddRange(fieldRootItems)");
                        #endif

            allRootItems.AddRange(fieldRootItems);

                        #if DEV_MODE
            timer.FinishInterval();
            timer.StartInterval("AddRange(allRootItems, propertyRootItems)");
                        #endif

            PopupMenuUtility.AddRange(ref allRootItems, propertyRootItems);

                        #if DEV_MODE
            timer.FinishInterval();
            timer.StartInterval("AddRange(allRootItems, methodRootItems)");
                        #endif

            PopupMenuUtility.AddRange(ref allRootItems, methodRootItems);

                        #if DEV_MODE
            timer.FinishInterval();
            timer.StartInterval("AddRange(allGroupsByLabel, fieldGroupsByLabel)");
                        #endif

            PopupMenuUtility.AddRange(ref allGroupsByLabel, fieldGroupsByLabel);

                        #if DEV_MODE
            timer.FinishInterval();
            timer.StartInterval("AddRange(allGroupsByLabel, propertyGroupsByLabel)");
                        #endif

            PopupMenuUtility.AddRange(ref allGroupsByLabel, propertyGroupsByLabel);

                        #if DEV_MODE
            timer.FinishInterval();
            timer.StartInterval("AddRange(allGroupsByLabel, methodGroupsByLabel)");
                        #endif

            PopupMenuUtility.AddRange(ref allGroupsByLabel, methodGroupsByLabel);

                        #if DEV_MODE
            timer.FinishInterval();
            timer.StartInterval("AddRange(allItemsByLabel, fieldItemsByLabel)");
                        #endif

            PopupMenuUtility.AddRange(ref allItemsByLabel, fieldItemsByLabel);

                        #if DEV_MODE
            timer.FinishInterval();
            timer.StartInterval("AddRange(allItemsByLabel, propertyItemsByLabel)");
                        #endif

            PopupMenuUtility.AddRange(ref allItemsByLabel, propertyItemsByLabel);

                        #if DEV_MODE
            timer.FinishInterval();
            timer.StartInterval("AddRange(allItemsByLabel, methodItemsByLabel)");
                        #endif

            PopupMenuUtility.AddRange(ref allItemsByLabel, methodItemsByLabel);

                        #if DEV_MODE
            timer.FinishInterval();
            timer.FinishAndLogResults();
                        #endif

            setupDone = SetupPhase.Done;

            lock (threadLock)
            {
                var action = onSetupFinished;
                if (action != null)
                {
                    onSetupFinished = null;
                    action();
                }
            }
        }