Exemplo n.º 1
0
        static IGenericMenu PrepareMenu(DropdownMenu menu, EventBase triggerEvent)
        {
            menu.PrepareForDisplay(triggerEvent);

            var genericMenu = new GenericOSMenu();

            foreach (var item in menu.MenuItems())
            {
                var action = item as DropdownMenuAction;
                if (action != null)
                {
                    if ((action.status & DropdownMenuAction.Status.Hidden) == DropdownMenuAction.Status.Hidden ||
                        action.status == 0)
                    {
                        continue;
                    }


                    bool isChecked = (action.status & DropdownMenuAction.Status.Checked) == DropdownMenuAction.Status.Checked;

                    if ((action.status & DropdownMenuAction.Status.Disabled) == DropdownMenuAction.Status.Disabled)
                    {
                        genericMenu.AddDisabledItem(action.name, isChecked);
                    }
                    else
                    {
                        genericMenu.AddItem(action.name, isChecked, () =>
                        {
                            action.Execute();
                        });
                    }
                }
                else
                {
                    var separator = item as DropdownMenuSeparator;
                    if (separator != null)
                    {
                        genericMenu.AddSeparator(separator.subMenuPath);
                    }
                }
            }

            return(genericMenu);
        }
Exemplo n.º 2
0
        public MinMaxGradientField(MinMaxGradientPropertyDrawer.PropertyData propertyData, string label) : base(label, null)
        {
            if (propertyData != null)
            {
                m_ColorMin = new PropertyField(propertyData.colorMin, "");
                m_ColorMin.AddToClassList(colorFieldUssClass);
                m_ColorMax = new PropertyField(propertyData.colorMax, "");
                m_ColorMax.AddToClassList(colorFieldUssClass);
                m_GradientMin  = new PropertyField(propertyData.gradientMin, "");
                m_GradientMax  = new PropertyField(propertyData.gradientMax, "");
                m_ModeDropdown = new DropdownField
                {
                    choices = stringModes.ToList()
                };
                m_ModeDropdown.createMenuCallback = () =>
                {
                    var osMenu = new GenericOSMenu();

                    for (int i = 0; i < stringModes.Length; i++)
                    {
                        var option          = stringModes[i];
                        var isValueSelected = propertyData.mode.intValue == i;

                        osMenu.AddItem(option, isValueSelected, () =>
                        {
                            m_ModeDropdown.value = option;
                        });
                    }

                    return(osMenu);
                };
                m_ModeDropdown.formatSelectedValueCallback = (value) =>
                {
                    // Don't show label for this dropdown
                    return("");
                };

                m_ModeDropdown.index = propertyData.mode.intValue;
                m_ModeDropdown.AddToClassList(dropdownFieldUssClass);
                m_MixedValueTypeLabel = new Label("\u2014");
                m_MixedValueTypeLabel.AddToClassList(multipleValuesLabelUssClass);

                var dropdownInput = m_ModeDropdown.Q <VisualElement>(null, "unity-popup-field__input");
                dropdownInput.AddToClassList(dropdownInputUssClass);

                m_GradientsContainer = new VisualElement();
                m_GradientsContainer.AddToClassList(gradientContainerUssClass);
                m_GradientsContainer.Add(m_GradientMin);
                m_GradientsContainer.Add(m_GradientMax);

                visualInput.AddToClassList(visualInputUssClass);
                visualInput.Add(m_ColorMin);
                visualInput.Add(m_ColorMax);
                visualInput.Add(m_GradientsContainer);
                visualInput.Add(m_MixedValueTypeLabel);
                visualInput.Add(m_ModeDropdown);

                m_ModeDropdown.RegisterCallback <ChangeEvent <string> >(e =>
                {
                    var index = Array.IndexOf(stringModes, e.newValue);
                    var mode  = (MinMaxGradientState)index;

                    propertyData.mode.intValue = index;
                    propertyData.mode.serializedObject.ApplyModifiedProperties();
                    UpdateFieldsDisplay(propertyData.mode);
                });

                UpdateFieldsDisplay(propertyData.mode);
            }
        }