public override VisualElement CreatePropertyGUI(SerializedProperty property)
        {
            var container = new VisualElement();

            UnityEngine.Random.InitState(property.displayName.GetHashCode());
            container.style.backgroundColor = UnityEngine.Random.ColorHSV();

            { // Create drawer using C#
                var popup = new PopupWindow();
                container.Add(popup);
                popup.text = property.displayName + " - Using C#";
                popup.Add(new PropertyField(property.FindPropertyRelative("amount")));
                popup.Add(new PropertyField(property.FindPropertyRelative("unit")));
                popup.Add(new PropertyField(property.FindPropertyRelative("name"), "CustomLabel: Name"));
            }

            { // Create drawer using UXML
                var vsTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/Examples/Editor/Bindings/custom-drawer.uxml");
                var drawer = vsTree.CloneTree(property.propertyPath);
                drawer.Q <PopupWindow>().text = property.displayName + " - Using UXML";
                container.Add(drawer);
            }

            return(container);
        }
Esempio n. 2
0
        public void BindElements()
        {
            m_ModeField             = this.Q <EnumField>("ModeField");
            m_BonePopupContainer    = this.Q <VisualElement>("BoneEnumPopup");
            m_NormalizeToggle       = this.Q <Toggle>("NormalizeToggle");
            m_SizeField             = this.Q <IntegerField>("SizeField");
            m_HardnessField         = this.Q <IntegerField>("HardnessField");
            m_StepField             = this.Q <IntegerField>("StepField");
            m_AmountSlider          = this.Q <Slider>("AmountSlider");
            m_AmountField           = this.Q <FloatField>("AmountField");
            m_AmountField.isDelayed = true;
            m_WeightInspectorPanel  = this.Q <WeightInspectorIMGUIPanel>("WeightsInspector");
            m_PopupWindow           = this.Q <UnityEngine.UIElements.PopupWindow>();

            LinkSliderToIntegerField(this.Q <Slider>("HardnessSlider"), m_HardnessField);
            LinkSliderToIntegerField(this.Q <Slider>("StepSlider"), m_StepField);

            m_ModeField.RegisterValueChangedCallback((evt) =>
            {
                SetupMode();
            });

            m_AmountSlider.RegisterValueChangedCallback((evt) =>
            {
                if (!evt.Equals(m_AmountField.value))
                {
                    m_AmountField.value = (float)System.Math.Round((double)evt.newValue, 2);
                }
            });
            m_AmountField.RegisterValueChangedCallback((evt) =>
            {
                var newValue = Mathf.Clamp(evt.newValue, m_AmountSlider.lowValue, m_AmountSlider.highValue);

                if (focusController.focusedElement == m_AmountField && !newValue.Equals(m_AmountSlider.value))
                {
                    sliderStarted();
                    sliderChanged(newValue);
                    sliderEnded();
                    Focus();
                    m_AmountField.value  = 0f;
                    m_AmountSlider.value = 0f;
                }
            });

            m_WeightInspectorPanel.weightsChanged += () => weightsChanged();
        }
Esempio n. 3
0
        public void OnEnable()
        {
            var root = this.rootVisualElement;

            root.styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>("Assets/Examples/Editor/todolist.uss"));

            var toolbar = new Toolbar();

            root.Add(toolbar);

            var btn1 = new ToolbarButton {
                text = "Button"
            };

            toolbar.Add(btn1);

            var spc = new ToolbarSpacer();

            toolbar.Add(spc);

            var tgl = new ToolbarToggle {
                text = "Toggle"
            };

            toolbar.Add(tgl);

            var spc2 = new ToolbarSpacer()
            {
                name = "flexSpacer1", flex = true
            };

            toolbar.Add(spc2);

            var menu = new ToolbarMenu {
                text = "Menu"
            };

            menu.menu.AppendAction("Default is never shown", a => {}, a => DropdownMenuAction.Status.None);
            menu.menu.AppendAction("Normal menu", a => {}, a => DropdownMenuAction.Status.Normal);
            menu.menu.AppendAction("Hidden is never shown", a => {}, a => DropdownMenuAction.Status.Hidden);
            menu.menu.AppendAction("Checked menu", a => {}, a => DropdownMenuAction.Status.Checked);
            menu.menu.AppendAction("Disabled menu", a => {}, a => DropdownMenuAction.Status.Disabled);
            menu.menu.AppendAction("Disabled and checked menu", a => {}, a => DropdownMenuAction.Status.Disabled | DropdownMenuAction.Status.Checked);
            toolbar.Add(menu);

            var spc3 = new ToolbarSpacer()
            {
                name = "flexSpacer2", flex = true
            };

            toolbar.Add(spc3);

            var popup = new ToolbarMenu {
                text = "Popup", variant = ToolbarMenu.Variant.Popup
            };

            popup.menu.AppendAction("Popup", a => {}, a => DropdownMenuAction.Status.Normal);
            toolbar.Add(popup);

            var popupSearchField = new ToolbarPopupSearchField();

            popupSearchField.RegisterValueChangedCallback(OnSearchTextChanged);
            popupSearchField.menu.AppendAction(
                "Popup Search Field",
                a => m_popupSearchFieldOn = !m_popupSearchFieldOn,
                a => m_popupSearchFieldOn ?
                DropdownMenuAction.Status.Checked :
                DropdownMenuAction.Status.Normal);
            toolbar.Add(popupSearchField);
            var searchField = new ToolbarSearchField();

            searchField.RegisterValueChangedCallback(OnSearchTextChanged);
            toolbar.Add(searchField);

            var popupWindow = new PopupWindow();

            popupWindow.text = "New Task";
            root.Add(popupWindow);

            m_TextInput = new TextField()
            {
                name = "input", viewDataKey = "input", isDelayed = true
            };
            popupWindow.Add(m_TextInput);
            m_TextInput.RegisterCallback <ChangeEvent <string> >(AddTask);

            var button = new Button(AddTask)
            {
                text = "Save task"
            };

            popupWindow.Add(button);

            var box = new Box();

            m_TasksContainer = new ScrollView();
            m_TasksContainer.showHorizontal = false;
            box.Add(m_TasksContainer);

            root.Add(box);

            if (m_Tasks != null)
            {
                foreach (string task in m_Tasks)
                {
                    m_TasksContainer.Add(CreateTask(task));
                }
            }
        }
    private void OnEnable()
    {
        var root = rootVisualElement;

        rootVisualElement.styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(StyleSheetPath));

        var toolbar = new Toolbar();

        root.Add(toolbar);

        var button = new ToolbarButton {
            text = "Click Me!"
        };

        toolbar.Add(button);

        var spacer = new ToolbarSpacer();

        toolbar.Add(spacer);

        var toggle = new ToolbarToggle {
            text = "Toggle Me!"
        };

        toolbar.Add(toggle);

        var flexSpacer = new ToolbarSpacer {
            name = "flexSpacer", flex = true
        };

        toolbar.Add(flexSpacer);

        var toolbarMenu = new ToolbarMenu {
            text = "Menu Me!"
        };

        toolbarMenu.menu.AppendAction("Default is never shown", a => { }, a => DropdownMenuAction.Status.None);
        toolbarMenu.menu.AppendAction("Normal Menu", a => { }, a => DropdownMenuAction.Status.Normal);
        toolbarMenu.menu.AppendAction("Hidden is never shown", a => { }, a => DropdownMenuAction.Status.Hidden);
        toolbarMenu.menu.AppendAction("Checked menu", a => { }, a => DropdownMenuAction.Status.Checked);
        toolbarMenu.menu.AppendAction("Disabled menu", a => { }, a => DropdownMenuAction.Status.Disabled);
        toolbarMenu.menu.AppendAction("Disabled and checked menu", a => { }, a => DropdownMenuAction.Status.Disabled | DropdownMenuAction.Status.Checked);
        toolbar.Add(toolbarMenu);

        var anotherFlexSpacer = new ToolbarSpacer {
            name = "flexSpacer2", flex = true
        };

        toolbar.Add(anotherFlexSpacer);

        var popup = new ToolbarMenu
        {
            text    = "Pop-UP!",
            variant = ToolbarMenu.Variant.Popup
        };

        popup.menu.AppendAction("Popup", a => { }, a => DropdownMenuAction.Status.Normal);
        toolbar.Add(popup);

        var popupSearchField = new ToolbarPopupSearchField();

        popupSearchField.RegisterValueChangedCallback(OnSearchTextChanged);
        popupSearchField.menu.AppendAction(
            "Search Field that POPS UP",
            a => PopupSearchFieldOn = !PopupSearchFieldOn,
            a => PopupSearchFieldOn ?
            DropdownMenuAction.Status.Checked :
            DropdownMenuAction.Status.Normal
            );
        toolbar.Add(popupSearchField);

        var popupWindowContainer = new VisualElement();

        popupWindowContainer.AddToClassList("dat-task");
        var popupWindow = new PopupWindow();

        popupWindow.text = "POP ME UP SCOTTY";

        popupWindowContainer.Add(popupWindow);
        root.Add(popupWindowContainer);

        TextInput = new TextField
        {
            name        = "input",
            viewDataKey = "input",
            isDelayed   = true
        };
        popupWindow.Add(TextInput);
        TextInput.RegisterCallback <ChangeEvent <string> >(AddTask);
    }