Beispiel #1
0
        void CreateUIElements()
        {
            var titleRow = new VisualElement()
            {
                style =
                {
                    flexDirection  = FlexDirection.Row,
                    flexShrink     =                0f,
                    justifyContent = Justify.SpaceBetween
                }
            };

            m_VisualElementContainer.Add(new Label("VisualElements Container"));


            var curveX           = AnimationCurve.Linear(0, 0, 1, 0);
            var popupFieldValues = new List <SomeClass>
            {
                new SomeClass("First Class Value"),
                new SomeClass("Second Value"),
                new SomeClass("Another Value"),
                new SomeClass("Another Value with a very lonnnnnnnnnnnnnnnnnnnnnnnnng text to make sure this is really overflowing the popup field.")
            };
            var maskFieldOptions = new List <string>(m_MaskFieldOptions);


            m_VisualElementContainer.Add(m_IntegerField  = new IntegerField());
            m_VisualElementContainer.Add(m_LongField     = new LongField());
            m_VisualElementContainer.Add(m_FloatField    = new FloatField());
            m_VisualElementContainer.Add(m_DoubleField   = new DoubleField());
            m_VisualElementContainer.Add(m_EnumField     = new EnumField(EnumValues.Two));
            m_VisualElementContainer.Add(m_TextField     = new TextField());
            m_VisualElementContainer.Add(m_PasswordField = new TextField()
            {
                isPasswordField = true, maskChar = '*'
            });
            m_VisualElementContainer.Add(m_Vector3Field      = new Vector3Field());
            m_VisualElementContainer.Add(m_Vector3IntField   = new Vector3IntField());
            m_VisualElementContainer.Add(m_Vector2Field      = new Vector2Field());
            m_VisualElementContainer.Add(m_ColorField        = new ColorField());
            m_VisualElementContainer.Add(m_ObjectFieldCamera = new ObjectField()
            {
                objectType = typeof(Camera)
            });
            m_VisualElementContainer.Add(m_ObjectFieldGameObject = new ObjectField()
            {
                objectType = typeof(GameObject)
            });
            m_VisualElementContainer.Add(m_CurveField = new CurveField()
            {
                value = curveX
            });
            m_VisualElementContainer.Add(m_CurveFieldMesh = new CurveField()
            {
                value = curveX, renderMode = CurveField.RenderMode.Mesh
            });
            m_VisualElementContainer.Add(m_PopupField        = new PopupField <SomeClass>(popupFieldValues, popupFieldValues[1]));
            m_VisualElementContainer.Add(m_RectField         = new RectField());
            m_VisualElementContainer.Add(m_BoundsField       = new BoundsField());
            m_VisualElementContainer.Add(m_ToggleField       = new Toggle());
            m_VisualElementContainer.Add(m_MaskField         = new MaskField(maskFieldOptions, 6));
            m_VisualElementContainer.Add(m_LayerField        = new LayerField());
            m_VisualElementContainer.Add(m_TagField          = new TagField());
            m_VisualElementContainer.Add(m_MinMaxSliderField = new MinMaxSlider(5, 10, 0, 125));
            m_VisualElementContainer.Add(m_Slider            = new Slider(2, 8));
            m_VisualElementContainer.Add(m_SliderInt         = new SliderInt(11, 23));

            var buttonRow = new VisualElement()
            {
                style =
                {
                    flexDirection = FlexDirection.Row,
                    flexShrink    =                0f,
                }
            };

            buttonRow.Add(new Button()
            {
                text = k_ButtonLeftTitle, style = { flexGrow = 1 }
            });
            buttonRow.Add(new Button()
            {
                text = k_ButtonRightTitle, style = { flexGrow = 1 }
            });
            m_VisualElementContainer.Add(buttonRow);

            m_VisualElementContainer.Add(new Button()
            {
                text = k_ButtonTopTitle
            });
            m_VisualElementContainer.Add(new Button()
            {
                text = k_ButtonBottomTitle
            });

            m_VisualElementContainer.Add(m_ColorField1        = new ColorField());
            m_VisualElementContainer.Add(m_LayerMaskField     = new LayerMaskField(0));
            m_VisualElementContainer.Add(m_MultiLineTextField = new TextField()
            {
                multiline = true
            });

            m_VisualElementContainer.Add(m_SliderProgressBar = new SliderInt());
            m_VisualElementContainer.Add(m_ProgressBar       = new ProgressBar());

            m_ProgressBar.title           = nameof(ProgressBar);
            m_SliderProgressBar.lowValue  = 0;
            m_SliderProgressBar.highValue = 100;

            m_SliderProgressBar.bindingPath = nameof(SliderProgressTestObject.exampleValue);
            m_ProgressBar.bindingPath       = nameof(SliderProgressTestObject.exampleValue);

            m_SliderProgressBar.Bind(SliderProgressTestSO);
            m_ProgressBar.Bind(SliderProgressTestSO);
            // The progress bar by itself does not contain any margin in IMGUI...
            // In this example, we are artifically adding the textfield margin to it. (see below, in the IMGUI section, ProgressBar())
            m_ProgressBar.style.marginBottom = 2f;

            m_VisualElementContainer.Add(m_GradientField = new GradientField());
            RefreshUIElements();
        }