コード例 #1
0
        public static IInspectorToolbarItem[] GetItemsForToolbar([NotNull] IInspector inspector, [NotNull] IInspectorToolbar toolbar)
        {
            if (toolbarItemsByToolbarType == null)
            {
                BuildDictionaries();
            }

            Type[] itemTypes;
            if (!toolbarItemsByToolbarType.TryGetValue(toolbar.GetType(), out itemTypes))
            {
                return(ArrayPool <IInspectorToolbarItem> .ZeroSizeArray);
            }

            int count = itemTypes.Length;

            IInspectorToolbarItem[] items = new IInspectorToolbarItem[count];
            for (int n = count - 1; n >= 0; n--)
            {
                var itemType  = itemTypes[n];
                var item      = (IInspectorToolbarItem)itemType.CreateInstance();
                var alignment = ((ToolbarItemForAttribute)itemType.GetCustomAttributes(typeof(ToolbarItemForAttribute), false)[0]).alignment;
                item.Setup(inspector, toolbar, alignment);
                items[n] = item;
            }

            return(items);
        }
コード例 #2
0
        public void SetSelectedItem(IInspectorToolbarItem item, ReasonSelectionChanged reason)
        {
                        #if DEV_MODE && DEBUG_SET_SELECTED_ITEM
            Debug.Log(StringUtils.ToColorizedString("SetSelectedItem(", item, "), was: ", SelectedItem));
                        #endif

                        #if DEV_MODE && PI_ASSERTATIONS
            if (item != null && inspector.Manager.SelectedInspectorPart != InspectorPart.Toolbar)
            {
                Debug.LogError(GetType().Name + ".SetSelectedItem(" + item.GetType().Name + ") called but SelectedInspectorPart was " + inspector.Manager.SelectedInspectorPart);
            }
                        #endif

            if (item == null)
            {
                if (selectedItemIndex != -1)
                {
                    items[selectedItemIndex].OnDeselected(reason);
                    selectedItemIndex = -1;
                }
                return;
            }

            int setIndex = Array.IndexOf(items, item);

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(setIndex != -1);
                        #endif

            if (selectedItemIndex != setIndex)
            {
                if (selectedItemIndex != -1)
                {
                    items[selectedItemIndex].OnDeselected(reason);
                }
                selectedItemIndex = setIndex;

                var select = items[setIndex];

                var documentationUrl = select.DocumentationPageUrl;
                if (documentationUrl.Length > 0)
                {
                    PowerInspectorDocumentation.ShowFeatureIfWindowOpen(documentationUrl);
                }

                select.OnSelected(reason);
            }
        }