public override void Init(VisualElement element, IUxmlAttributes bag, CreationContext cc)
            {
                base.Init(element, bag, cc);

                var field    = element as MinMaxSliderField;
                var maxValue = _minValue.GetValueFromBag(bag, cc);
                var minValue = _maxValue.GetValueFromBag(bag, cc);
                var min      = _minimum.GetValueFromBag(bag, cc);
                var max      = _maximum.GetValueFromBag(bag, cc);

                field.Setup(new Vector2(minValue, maxValue), min, max);
            }
Exemple #2
0
            public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
            {
                base.Init(ve, bag, cc);
                var fixedPaneIndex       = m_FixedPaneIndex.GetValueFromBag(bag, cc);
                var fixedPaneInitialSize = m_FixedPaneInitialSize.GetValueFromBag(bag, cc);
                var orientationStr       = m_Orientation.GetValueFromBag(bag, cc);
                var orientation          = orientationStr == "horizontal"
                    ? Orientation.Horizontal
                    : Orientation.Vertical;

                ((TwoPaneSplitView)ve).Init(fixedPaneIndex, fixedPaneInitialSize, orientation);
            }
Exemple #3
0
            public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
            {
                base.Init(ve, bag, cc);
                Foldout foldout = ve as Foldout;
                bool    flag    = foldout != null;

                if (flag)
                {
                    foldout.text = this.m_Text.GetValueFromBag(bag, cc);
                    foldout.SetValueWithoutNotify(this.m_Value.GetValueFromBag(bag, cc));
                }
            }
Exemple #4
0
            /// <summary>
            /// Initializes <see cref="Foldout"/> properties using values from the attribute bag.
            /// </summary>
            /// <param name="ve">The object to initialize.</param>
            /// <param name="bag">The attribute bag.</param>
            /// <param name="cc">The creation context; unused.</param>
            public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
            {
                base.Init(ve, bag, cc);

                Foldout f = ve as Foldout;

                if (f != null)
                {
                    f.text = m_Text.GetValueFromBag(bag, cc);
                    f.SetValueWithoutNotify(m_Value.GetValueFromBag(bag, cc));
                }
            }
            public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
            {
                base.Init(ve, bag, cc);
                int itemHeight = 0;

                if (m_ItemHeight.TryGetValueFromBag(bag, cc, ref itemHeight))
                {
                    ((ListView)ve).itemHeight = itemHeight;
                }

                ((ListView)ve).showBorder = m_ShowBorder.GetValueFromBag(bag, cc);
            }
Exemple #6
0
            public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
            {
                base.Init(ve, bag, cc);

                ScrollView scrollView = (ScrollView)ve;

                scrollView.SetScrollViewMode(m_ScrollViewMode.GetValueFromBag(bag, cc));
                scrollView.showHorizontal     = m_ShowHorizontal.GetValueFromBag(bag, cc);
                scrollView.showVertical       = m_ShowVertical.GetValueFromBag(bag, cc);
                scrollView.horizontalPageSize = m_HorizontalPageSize.GetValueFromBag(bag, cc);
                scrollView.verticalPageSize   = m_VerticalPageSize.GetValueFromBag(bag, cc);
            }
            public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
            {
                base.Init(ve, bag, cc);

                SliderInt slider = ((SliderInt)ve);

                slider.lowValue  = m_LowValue.GetValueFromBag(bag, cc);
                slider.highValue = m_HighValue.GetValueFromBag(bag, cc);
                slider.direction = m_Direction.GetValueFromBag(bag, cc);
                slider.pageSize  = m_PageSize.GetValueFromBag(bag, cc);
                slider.SetValueWithoutNotify(m_Value.GetValueFromBag(bag, cc));
            }
Exemple #8
0
            /// <summary>
            /// Initialize <see cref="Slider"/> properties using values from the attribute bag.
            /// </summary>
            /// <param name="ve">The object to initialize.</param>
            /// <param name="bag">The attribute bag.</param>
            /// <param name="cc">The creation context; unused.</param>
            public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
            {
                var f = (Slider)ve;

                f.lowValue       = m_LowValue.GetValueFromBag(bag, cc);
                f.highValue      = m_HighValue.GetValueFromBag(bag, cc);
                f.direction      = m_Direction.GetValueFromBag(bag, cc);
                f.pageSize       = m_PageSize.GetValueFromBag(bag, cc);
                f.showInputField = m_ShowInputField.GetValueFromBag(bag, cc);

                base.Init(ve, bag, cc);
            }
Exemple #9
0
            public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
            {
                base.Init(ve, bag, cc);
                var text         = m_Text.GetValueFromBag(bag, cc);
                var showUsed     = m_ShowUsed.GetValueFromBag(bag, cc);
                var total        = m_Total.GetValueFromBag(bag, cc);
                var showSelected = m_ShowSelected.GetValueFromBag(bag, cc);
                var used         = Mathf.Clamp(m_Used.GetValueFromBag(bag, cc), 0, total);
                var selected     = Mathf.Clamp(m_Selected.GetValueFromBag(bag, cc), 0, total);
                var color        = m_ColorClass.GetValueFromBag(bag, cc);

                ((MemoryUsageBreakdownElement)ve).Init(text, showUsed, (ulong)used, (ulong)total, showSelected, (ulong)selected, color);
            }
            public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
            {
                base.Init(ve, bag, cc);

                var lf  = (PlatformLevelSelector)ve;
                int val = 0;

                if (!m_Value.TryGetValueFromBag(bag, cc, ref val))
                {
                    val = GetChoices().Last();
                }
                lf.SetValueWithoutNotify(val);
            }
Exemple #11
0
            public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
            {
                base.Init(ve, bag, cc);

                var f       = (DropdownField)ve;
                var choices = ParseChoiceList(m_Choices.GetValueFromBag(bag, cc));

                if (choices != null)
                {
                    f.choices = choices;
                }
                f.index = m_Index.GetValueFromBag(bag, cc);
            }
            public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
            {
                base.Init(ve, bag, cc);
                int itemHeight = 0;

                if (m_ItemHeight.TryGetValueFromBag(bag, cc, ref itemHeight))
                {
                    ((TreeView)ve).itemHeight = itemHeight;
                }
                ((TreeView)ve).showBorder    = m_ShowBorder.GetValueFromBag(bag, cc);
                ((TreeView)ve).selectionType = m_SelectionType.GetValueFromBag(bag, cc);
                ((TreeView)ve).showAlternatingRowBackgrounds = m_ShowAlternatingRowBackgrounds.GetValueFromBag(bag, cc);
            }
#pragma warning restore 414

            public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
            {
                base.Init(ve, bag, cc);

                Enum resEnumValue;
                bool resIncludeObsoleteValues;

                if (EnumFieldHelpers.ExtractValue(bag, cc, out resEnumValue, out resIncludeObsoleteValues))
                {
                    EnumFlagsField enumField = (EnumFlagsField)ve;
                    enumField.Init(resEnumValue, resIncludeObsoleteValues);
                }
            }
            public override void Init(VisualElement element, IUxmlAttributes bag, CreationContext cc)
            {
                base.Init(element, bag, cc);

                var field   = element as PopupField <T>;
                var options = _options.GetValueFromBag(bag, cc).Split(',');
                var values  = _values.GetValueFromBag(bag, cc).Split(',');

                var optionsList = options.ToList();
                var valuesList  = field.ParseValues(values);

                field.SetValues(valuesList, optionsList);
            }
            /// <summary>
            /// Initialize <see cref="MinMaxSlider"/> properties using values from the attribute bag.
            /// </summary>
            /// <param name="ve">The element to initialize.</param>
            /// <param name="bag">The bag of attributes.</param>
            /// <param name="cc">Creation Context, unused.</param>
            public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
            {
                base.Init(ve, bag, cc);

                var slider = ((MinMaxSlider)ve);

                slider.lowLimit  = m_LowLimit.GetValueFromBag(bag, cc);
                slider.highLimit = m_HighLimit.GetValueFromBag(bag, cc);

                var value = new Vector2(m_MinValue.GetValueFromBag(bag, cc), m_MaxValue.GetValueFromBag(bag, cc));

                slider.value = value;
            }
        /// <summary>
        /// Retrieves the value of this attribute from the attribute bag. Returns it if it is found, otherwise return <see cref="defaultValue"/>.
        /// </summary>
        /// <param name="bag">The bag of attributes.</param>
        /// <param name="cc">The context in which the values are retrieved.</param>
        /// <returns>The initialized UXML object.</returns>
        public virtual T GetValueFromBag(IUxmlAttributes bag, CreationContext cc)
        {
            var uxmlObjects = cc.visualTreeAsset?.GetUxmlObjects <T>(bag, cc);

            if (uxmlObjects != null)
            {
                foreach (var child in uxmlObjects)
                {
                    return(child);
                }
            }

            return(defaultValue);
        }
Exemple #17
0
            public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
            {
                base.Init(ve, bag, cc);
                string propPath = m_PropertyPath.GetValueFromBag(bag, cc);

                if (!string.IsNullOrEmpty(propPath))
                {
                    var field = ve as IBindable;
                    if (field != null)
                    {
                        field.bindingPath = propPath;
                    }
                }
            }
            public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
            {
                base.Init(ve, bag, cc);
                var bar = ve as ProgressBar;

                bar.lowValue  = m_LowValue.GetValueFromBag(bag, cc);
                bar.highValue = m_HighValue.GetValueFromBag(bag, cc);
                var title = m_Title.GetValueFromBag(bag, cc);

                if (!string.IsNullOrEmpty(title))
                {
                    bar.title = title;
                }
            }
        internal bool TryGetValueFromBagAsString(IUxmlAttributes bag, CreationContext cc, out string value)
        {
            if (name == null)
            {
                if (obsoleteNames == null || obsoleteNames.Length == 0)
                {
                    Debug.LogError("Attribute description has no name.");
                    value = null;
                    return(false);
                }

                for (var i = 0; i < obsoleteNames.Length; i++)
                {
                    if (bag.TryGetAttributeValue(obsoleteNames[i], out value))
                    {
                        if (cc.visualTreeAsset != null)
                        {
                        }

                        return(true);
                    }
                }

                value = null;
                return(false);
            }

            if (!bag.TryGetAttributeValue(name, out value))
            {
                if (obsoleteNames != null)
                {
                    for (var i = 0; i < obsoleteNames.Length; i++)
                    {
                        if (bag.TryGetAttributeValue(obsoleteNames[i], out value))
                        {
                            if (cc.visualTreeAsset != null)
                            {
                            }

                            return(true);
                        }
                    }
                }

                value = null;
                return(false);
            }

            return(true);
        }
Exemple #20
0
            public override void Init(ref T obj, IUxmlAttributes bag, CreationContext cc)
            {
                base.Init(ref obj, bag, cc);

                var sortColumnDescriptions = m_SortColumnDescriptions.GetValueFromBag(bag, cc);

                if (sortColumnDescriptions != null)
                {
                    foreach (var d in sortColumnDescriptions)
                    {
                        obj.Add(d);
                    }
                }
            }
Exemple #21
0
            public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
            {
                base.Init(ve, bag, cc);
                ScrollView scrollView = (ScrollView)ve;

                scrollView.SetScrollViewMode(this.m_ScrollViewMode.GetValueFromBag(bag, cc));
                scrollView.showHorizontal         = this.m_ShowHorizontal.GetValueFromBag(bag, cc);
                scrollView.showVertical           = this.m_ShowVertical.GetValueFromBag(bag, cc);
                scrollView.horizontalPageSize     = this.m_HorizontalPageSize.GetValueFromBag(bag, cc);
                scrollView.verticalPageSize       = this.m_VerticalPageSize.GetValueFromBag(bag, cc);
                scrollView.scrollDecelerationRate = this.m_ScrollDecelerationRate.GetValueFromBag(bag, cc);
                scrollView.touchScrollBehavior    = this.m_TouchScrollBehavior.GetValueFromBag(bag, cc);
                scrollView.elasticity             = this.m_Elasticity.GetValueFromBag(bag, cc);
            }
            public override void Init(VisualElement _ve, IUxmlAttributes _bag, CreationContext _cc)
            {
                base.Init(_ve, _bag, _cc);

                ExecutableSensorField executableSensorField = (ExecutableSensorField)_ve;

                string valueFromBag = m_Value.GetValueFromBag(_bag, _cc);

                System.Type validType = executableSensorField.GetContentTypes().FirstOrDefault(_entry => _entry.Name == valueFromBag);

                if (validType != null)
                {
                    executableSensorField.SetValueWithoutNotify(validType);
                }
            }
Exemple #23
0
            public override void Init(VisualElement element, IUxmlAttributes bag, CreationContext cc)
            {
                base.Init(element, bag, cc);

                var field = element as MessageBox;

                field.Message = _message.GetValueFromBag(bag, cc);

                var messageType = _messageType.GetValueFromBag(bag, cc);

                if (!string.IsNullOrEmpty(messageType))
                {
                    field.Type = ParseValue(messageType);
                }
            }
Exemple #24
0
            public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
            {
                base.Init(ve, bag, cc);

                TextInputFieldBase <T> field = ((TextInputFieldBase <T>)ve);

                field.maxLength       = m_MaxLength.GetValueFromBag(bag);
                field.isPasswordField = m_Password.GetValueFromBag(bag);
                string maskCharacter = m_MaskCharacter.GetValueFromBag(bag);

                if (maskCharacter != null && maskCharacter.Length > 0)
                {
                    field.maskChar = maskCharacter[0];
                }
            }
Exemple #25
0
        protected T GetValueFromBag <T>(IUxmlAttributes bag, CreationContext cc, Func <string, T, T> converterFunc, T defaultValue)
        {
            if (converterFunc == null)
            {
                throw new ArgumentNullException(nameof(converterFunc));
            }

            string value;

            if (TryGetValueFromBagAsString(bag, cc, out value))
            {
                return(converterFunc(value, defaultValue));
            }

            return(defaultValue);
        }
Exemple #26
0
            public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
            {
                base.Init(ve, bag, cc);
                string valueFromBag = this.m_PropertyPath.GetValueFromBag(bag, cc);
                bool   flag         = !string.IsNullOrEmpty(valueFromBag);

                if (flag)
                {
                    IBindable bindable = ve as IBindable;
                    bool      flag2    = bindable != null;
                    if (flag2)
                    {
                        bindable.bindingPath = valueFromBag;
                    }
                }
            }
Exemple #27
0
            public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
            {
                base.Init(ve, bag, cc);
                TemplateContainer templateContainer = (TemplateContainer)ve;

                templateContainer.templateId = this.m_Template.GetValueFromBag(bag, cc);
                VisualTreeAsset expr_2D         = cc.visualTreeAsset;
                VisualTreeAsset visualTreeAsset = (expr_2D != null) ? expr_2D.ResolveTemplate(templateContainer.templateId) : null;
                bool            flag            = visualTreeAsset == null;

                if (flag)
                {
                    templateContainer.Add(new Label(string.Format("Unknown Template: '{0}'", templateContainer.templateId)));
                }
                else
                {
                    TemplateAsset expr_70 = bag as TemplateAsset;
                    List <TemplateAsset.AttributeOverride> list = (expr_70 != null) ? expr_70.attributeOverrides : null;
                    List <TemplateAsset.AttributeOverride> attributeOverrides = cc.attributeOverrides;
                    List <TemplateAsset.AttributeOverride> list2 = null;
                    bool flag2 = list != null || attributeOverrides != null;
                    if (flag2)
                    {
                        list2 = new List <TemplateAsset.AttributeOverride>();
                        bool flag3 = attributeOverrides != null;
                        if (flag3)
                        {
                            list2.AddRange(attributeOverrides);
                        }
                        bool flag4 = list != null;
                        if (flag4)
                        {
                            list2.AddRange(list);
                        }
                    }
                    visualTreeAsset.CloneTree(ve, cc.slotInsertionPoints, list2);
                }
                bool flag5 = visualTreeAsset == null;

                if (flag5)
                {
                    Debug.LogErrorFormat("Could not resolve template with name '{0}'", new object[]
                    {
                        templateContainer.templateId
                    });
                }
            }
            public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
            {
                base.Init(ve, bag, cc);

                var field = ((TextInputBaseField <TValueType>)ve);

                field.maxLength       = m_MaxLength.GetValueFromBag(bag, cc);
                field.isPasswordField = m_Password.GetValueFromBag(bag, cc);
                field.isReadOnly      = m_IsReadOnly.GetValueFromBag(bag, cc);
                string maskCharacter = m_MaskCharacter.GetValueFromBag(bag, cc);

                if (!string.IsNullOrEmpty(maskCharacter))
                {
                    field.maskChar = maskCharacter[0];
                }
                field.text = m_Text.GetValueFromBag(bag, cc);
            }
Exemple #29
0
            public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
            {
                base.Init(ve, bag, cc);
                Viewport viewport = (Viewport)ve;

                viewport._zoomSpeed    = _zoomSpeed.GetValueFromBag(bag, cc);
                viewport._minZoomValue = _minZoomValue.GetValueFromBag(bag, cc);
                viewport._maxZoomValue = _maxZoomValue.GetValueFromBag(bag, cc);

                if (viewport._minZoomValue > viewport._maxZoomValue)
                {
                    Debug.LogWarning($"{AssetDatabase.GetAssetPath(cc.visualTreeAsset)}: Viewports minZoom is bigger than maxZoom!", cc.visualTreeAsset);
                    viewport._minZoomValue = viewport._maxZoomValue;
                }

                viewport.UpdateZoom(0);
            }
Exemple #30
0
            /// <summary>
            /// Initialize <see cref="TextField"/> properties using values from the attribute bag.
            /// </summary>
            /// <param name="ve">The object to initialize.</param>
            /// <param name="bag">The attribute bag.</param>
            /// <param name="cc">The creation context; unused.</param>
            public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
            {
                TextField field = ((TextField)ve);

                field.multiline = m_Multiline.GetValueFromBag(bag, cc);
                base.Init(ve, bag, cc);

                // Re-defining the value to account for the "obsolete" text property.
                // We are doing it here because TextField binds the value to the text and this
                // is not the case in the base class.
                var value = string.Empty;

                if (k_Value.TryGetValueFromBag(bag, cc, ref value))
                {
                    field.SetValueWithoutNotify(value);
                }
            }