void BuildEnumKeywordField(PropertySheet propertySheet, ShaderKeyword keyword)
        {
            // Clamp value between entry list
            int value = Mathf.Clamp(keyword.value, 0, keyword.entries.Count - 1);

            // Default field
            var field = new PopupField <string>(keyword.entries.Select(x => x.displayName).ToList(), value);

            field.RegisterValueChangedCallback(evt =>
            {
                this._preChangeValueCallback("Change Keyword Value");
                keyword.value = field.index;
                this._postChangeValueCallback(false, ModificationScope.Graph);
            });

            AddPropertyRowToSheet(propertySheet, field, "Default");

            // Entries
            var container = new IMGUIContainer(() => OnKeywordGUIHandler())
            {
                name = "ListContainer"
            };

            AddPropertyRowToSheet(propertySheet, container, "Entries");
            container.SetEnabled(!keyword.isBuiltIn);
        }
        void OnGUIHandler()
        {
            var value = (Toggle)m_PropertyInfo.GetValue(m_Node, null);

            using (var changeCheckScope = new EditorGUI.ChangeCheckScope())
            {
                m_Container.SetEnabled(value.isEnabled);

                bool isOn = EditorGUILayout.Toggle(m_Label, value.isOn);
                value = new Toggle(isOn, value.isEnabled);
                if (changeCheckScope.changed)
                {
                    m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
                    m_PropertyInfo.SetValue(m_Node, value, null);
                }
            }
        }
示例#3
0
        public RecorderItem(RecorderControllerSettings prefs, RecorderSettings recorderSettings, string iconName)
        {
            settings = recorderSettings;

            if (settings != null)
            {
                editor = Editor.CreateEditor(settings);
            }

            UIElementHelper.SetFlex(this, 1.0f);
            style.flexDirection = FlexDirection.Row;

            m_Toggle = new Toggle();

#if UNITY_2019_1_OR_NEWER
            m_Toggle.RegisterValueChangedCallback(evt =>
#elif UNITY_2018_3_OR_NEWER
            m_Toggle.OnValueChanged(evt =>
#else
            m_Toggle.OnToggle(() =>
#endif
            {
                SetItemEnabled(prefs, UIElementHelper.GetToggleValue(m_Toggle));
            });

            Add(m_Toggle);

            m_RecorderIcon = LoadIcon(iconName);

            if (m_RecorderIcon == null)
            {
                m_RecorderIcon = LoadIcon("customrecorder_16");
            }

            UpdateState(false);

            var iconContainer = new IMGUIContainer(() => // UIElement Image doesn't support tint yet. Use IMGUI instead.
            {
                var r   = EditorGUILayout.GetControlRect();
                r.width = r.height = Mathf.Max(r.width, r.height);

                var c = GUI.color;

                var newColor = Color.white;

                if (m_Disabled)
                {
                    newColor.a = 0.5f;
                }
                else
                {
                    if (!m_Selected)
                    {
                        newColor.a = 0.8f;
                    }
                }

                GUI.color = newColor;

                GUI.DrawTexture(r, m_Icon);

                GUI.color = c;
            });

            iconContainer.AddToClassList("RecorderItemIcon");

            iconContainer.SetEnabled(false);

            Add(iconContainer);

            m_EditableLabel = new EditableLabel {
                text = settings.name
            };
            m_EditableLabel.OnValueChanged(newValue =>
            {
                settings.name = newValue;
                prefs.Save();
            });
            Add(m_EditableLabel);

            var recorderEnabled = settings.enabled;
            UIElementHelper.SetToggleValue(m_Toggle, recorderEnabled);

            SetItemEnabled(prefs, recorderEnabled);
        }
示例#4
0
    private void RenderCatalogsPanel()
    {
        VisualElement body = rootVisualElement.Q <VisualElement>("body");

        body.Clear();
        catalogsVisualTree.CloneTree(body);

        ListView listView = body.Q <ListView>("CatalogsList");

        List <BaseCatalog> catalogs = new List <BaseCatalog>(MarketManager.catalogs);

        catalogs.Sort(NameComparer);
        for (int i = 0; i < catalogs.Count; i++)
        {
            Button button = new Button {
                text = catalogs[i].name
            };
            int index = i;
            button.clicked += () => OnCatalogSelected(catalogs[index]);

            button.AddManipulator(
                new ContextualMenuManipulator(
                    x =>
                    AddContextMenuOptions(
                        x.menu,
                        new []
            {
                new Tuple <string, Action>("ChangeID", () => ChangeCatalogName(catalogs[index])),
                new Tuple <string, Action>("Delete", () => DestroyCatalog(catalogs[index])),
            })));
            listView.Add(button);
        }

        Button newCatalogButton = new Button {
            text = "+"
        };

        newCatalogButton.clicked        += CreateNewCatalogRequest;
        newCatalogButton.style.width     = 25;
        newCatalogButton.style.height    = 25;
        newCatalogButton.style.alignSelf = new StyleEnum <Align>(Align.Center);
        listView.Add(newCatalogButton);

        ListView catalogContent = body.Q <ListView>("LeftContent");

        catalogContent.style.flexGrow = 1;
        catalogContent.contentContainer.style.flexDirection = new StyleEnum <FlexDirection>(FlexDirection.Row);
        catalogContent.contentContainer.style.flexWrap      = new StyleEnum <Wrap>(Wrap.Wrap);

        Label label = body.Q <Label>("CurrentCatalogLabel");

        if (_selectedCatalog != null)
        {
            label.text = _selectedCatalog.name;
            List <BaseProduct> baseProducts = new List <BaseProduct>(_selectedCatalog.Products);
            baseProducts.Sort(NameComparer);
            for (int i = 0; i < baseProducts.Count; i++)
            {
                int           localIndex    = i;
                VisualElement prodSelection = CreateProductSelectionButton(
                    baseProducts[i],
                    baseProduct => RemoveFrom(baseProduct, _selectedCatalog),
                    new []
                {
                    new Tuple <string, Action>("Preview", () => PreviewProduct(baseProducts[localIndex])),
                    new Tuple <string, Action>("Edit", () => GoToProductEdit(baseProducts[localIndex])),
                    new Tuple <string, Action>("Delete", () => DestroyProduct(baseProducts[localIndex]))
                });
                catalogContent.Add(prodSelection);
            }
        }
        else
        {
            label.text = "-";
        }

        #region SelectionList

        GetProductNamesAndTypes(out List <Type> types, out List <string> names);
        ListView typeSelectionList = body.Q <ListView>("TypesList");

        Button allButton = new Button {
            text = "Select All"
        };
        allButton.style.width = 70;
        allButton.clicked    += () => OnAllCategorySelected(selectedProductCategories, names);

        FillListWithToggle(names, "Product", selectedProductCategories, typeSelectionList, OnProductTypeSelected);
        typeSelectionList.contentContainer.Insert(0, allButton);
        typeSelectionList.Insert(0, allButton);

        #endregion

        #region Preview
        if (_selectedPreviewProduct != null)
        {
            VisualElement selectionRender = body.Q <VisualElement>("Right");

            selectionRender.style.paddingLeft   = 5;
            selectionRender.style.paddingRight  = 5;
            selectionRender.style.paddingTop    = 5;
            selectionRender.style.paddingBottom = 5;

            Button closeButton = new Button()
            {
                text = "X"
            };
            closeButton.clicked += () =>
            {
                _selectedPreviewProduct = null;
                Render();
            };
            closeButton.style.width  = 20;
            closeButton.style.height = 20;

            scriptableObjectEdit_View.CloneTree(selectionRender);
            Image          icon     = new Image();
            IMGUIContainer soRender = selectionRender.Q <IMGUIContainer>("Render");
            icon.style.alignSelf       = new StyleEnum <Align>(Align.Center);
            icon.style.height          = 100;
            icon.style.width           = 100;
            icon.style.backgroundColor = new Color(.25f, .25f, .25f);
            icon.style.marginTop       = 10;
            icon.style.marginBottom    = 10;

            selectionRender.Insert(0, icon);
            selectionRender.Insert(0, closeButton);

            if (_selectedPreviewProduct != null)
            {
                Editor editor = Editor.CreateEditor(_selectedPreviewProduct);
                soRender.onGUIHandler = () => editor.OnInspectorGUI();
                if (_selectedPreviewProduct.Icon != null)
                {
                    icon.image = _selectedPreviewProduct.Icon.texture;
                }
            }

            VisualElement buttons = body.Q <VisualElement>("Buttons");
            if (buttons != null)
            {
                buttons.style.opacity = 0;
                buttons.SetEnabled(false);
            }
            soRender.SetEnabled(false);
        }
        #endregion

        #region Add Selection
        VisualElement lowerContent = body.Q <VisualElement>("LowerContent");
        lowerContent.contentContainer.style.flexDirection = new StyleEnum <FlexDirection>(FlexDirection.Row);
        lowerContent.contentContainer.style.flexWrap      = new StyleEnum <Wrap>(Wrap.Wrap);

        HashSet <BaseProduct> products = new HashSet <BaseProduct>();
        Dictionary <string, List <BaseProduct> > productsByClass = MarketManager.GetProductsByClass();

        if (_selectedCatalog == null)
        {
            return;
        }

        foreach (KeyValuePair <string, List <BaseProduct> > keyValuePair in productsByClass)
        {
            if (!selectedProductCategories.Contains(keyValuePair.Key))
            {
                continue;
            }
            for (int i = 0; i < keyValuePair.Value.Count; i++)
            {
                if (!_selectedCatalog.Products.Contains(keyValuePair.Value[i]))
                {
                    products.Add(keyValuePair.Value[i]);
                }
            }
        }

        foreach (BaseProduct itemProduct in products)
        {
            lowerContent.Add(
                CreateProductSelectionButton(
                    itemProduct,
                    baseProduct => AddTo(itemProduct, _selectedCatalog),
                    new []
            {
                new Tuple <string, Action>("Preview", () => PreviewProduct(itemProduct)),
                new Tuple <string, Action>("Edit", () => GoToProductEdit(itemProduct)),
                new Tuple <string, Action>("Delete", () => DestroyProduct(itemProduct))
            }));
        }

        #endregion
    }
示例#5
0
        private void InitMainPage()
        {
            _setupBar = new VisualElement
            {
                style =
                {
                    marginTop       =                 6, marginBottom = 6, marginRight = 6, marginLeft = 6,
                    flexDirection   = FlexDirection.Row,
                    backgroundColor = new Color(0, 0, 0, 0.3f)
                }
            };

            var setupProperty = new IMGUIContainer(() =>
            {
                _setupReferenceSP.serializedObject.Update();
                EditorGUILayout.PropertyField(_setupReferenceSP);
                _setupReferenceSP.serializedObject.ApplyModifiedProperties();
            })                     //new PropertyField(_setupReferenceSP)
            {
                style =
                {
                    flexGrow    =            1,
                    alignSelf   = Align.Center,
                    marginLeft  =            7,
                    marginRight = 7
                }
            };

            var button = new Button
            {
                text  = "->",
                style =
                {
                    flexGrow       = 0.1f,
                    marginLeft     =    0,marginBottom     = 1.2f, marginTop        = 4, marginRight       = 4,
                    paddingTop     =    2,paddingBottom    =    4, paddingLeft      = 0, paddingRight      = 0,
                    borderTopWidth =    0,borderLeftWidth  =    0, borderRightWidth = 0, borderBottomWidth = 0
                }
            };

            button.clickable.clicked += () =>
            {
                if (setupProperty.enabledSelf)
                {
                    _setup = _settings.SetupReference.editorAsset as Setup;

                    if (_setup == null)
                    {
                        return;
                    }

                    button.text = SETUP_CLOSE_BUTTON_NAME;

                    setupProperty.SetEnabled(false);

                    IsSetupEnable = true;
                }
                else
                {
                    button.text = SETUP_OPEN_BUTTON_NAME;

                    setupProperty.SetEnabled(true);

                    IsSetupEnable = false;
                }
            };
            _setupBar.Add(setupProperty);
            _setupBar.Add(button);
        }