Esempio n. 1
0
        public static VisualElement GetElementOfColorField(Color startValue, string fieldName, Action <object> setValue, Action <object> getValue)
        {
            ColorField field = new ColorField(fieldName);

            field.SetValueWithoutNotify(startValue);
            field.RegisterValueChangedCallback(s => setValue.Invoke(s.newValue));
            getValue += o => field.SetValueWithoutNotify((Color)o);
            return(field);
        }
        public void Refresh()
        {
            // HACK until fix goes in:
            SetDelayOnSizeFieldsEnabled(false);

            m_CanvasWidth.SetValueWithoutNotify(settings.CanvasWidth);
            m_CanvasHeight.SetValueWithoutNotify(settings.CanvasHeight);

            SetDelayOnSizeFieldsEnabled(true);

            m_BackgroundOptionsFoldout.SetCheckboxValueWithoutNotify(settings.EnableCanvasBackground);

            m_ColorOpacityField.SetValueWithoutNotify(settings.ColorModeBackgroundOpacity);
            m_ImageOpacityField.SetValueWithoutNotify(settings.ImageModeCanvasBackgroundOpacity);
            m_CameraOpacityField.SetValueWithoutNotify(settings.CameraModeCanvasBackgroundOpacity);

            m_BackgroundMode.SetValueWithoutNotify(settings.CanvasBackgroundMode.ToString());
            m_ColorField.SetValueWithoutNotify(settings.CanvasBackgroundColor);

            var scaleModeStr = settings.CanvasBackgroundImageScaleMode.ToString();

            scaleModeStr = BuilderNameUtilities.ConvertCamelToDash(scaleModeStr);
            m_ImageField.SetValueWithoutNotify(settings.CanvasBackgroundImage);
            m_ImageScaleModeField.SetValueWithoutNotify(scaleModeStr);

            m_CameraField.SetValueWithoutNotify(FindCameraByName());
            m_EditorExtensionsModeToggle?.SetValueWithoutNotify(m_Document.fileSettings.editorExtensionMode);

            ApplyBackgroundOptions();
            RefreshMatchGameViewToggle();
        }
Esempio n. 3
0
 void RefreshSubFields()
 {
     m_OffsetXField.SetValueWithoutNotify(value.offsetX.ToString());
     m_OffsetYField.SetValueWithoutNotify(value.offsetY.ToString());
     m_BlurRadiusField.SetValueWithoutNotify(value.blurRadius.ToString());
     m_ColorField.SetValueWithoutNotify(value.color);
 }
        public void Refresh()
        {
            // HACK until fix goes in:
            m_CanvasWidth.isDelayed  = false;
            m_CanvasHeight.isDelayed = false;

            m_CanvasWidth.SetValueWithoutNotify(settings.CanvasWidth);
            m_CanvasHeight.SetValueWithoutNotify(settings.CanvasHeight);

            m_CanvasWidth.isDelayed  = true;
            m_CanvasHeight.isDelayed = true;

            m_OpacityField.SetValueWithoutNotify(settings.CanvasBackgroundOpacity);
            m_BackgroundMode.SetValueWithoutNotify(settings.CanvasBackgroundMode.ToString());

            m_ColorField.SetValueWithoutNotify(settings.CanvasBackgroundColor);

            var scaleModeStr = settings.CanvasBackgroundImageScaleMode.ToString();

            scaleModeStr = BuilderNameUtilities.ConvertCamelToDash(scaleModeStr);
            m_ImageField.SetValueWithoutNotify(settings.CanvasBackgroundImage);
            m_ImageScaleModeField.SetValueWithoutNotify(scaleModeStr);

            m_CameraField.SetValueWithoutNotify(FindCameraByName());

            ApplyBackgroundOptions();
        }
        public static void RenderColorProperty(VisualElement container, string name, object value,
                                               Action <object> setter)
        {
            var field = new ColorField(name);

            field.SetValueWithoutNotify((Color)value);
            field.MarkDirtyRepaint();
            field.RegisterValueChangedCallback(evt => setter(evt.newValue));
            container.Add(field);
        }
Esempio n. 6
0
        public void Bind(Environment environment)
        {
            this.environment = environment;
            if (environment == null || environment.Equals(null))
            {
                return;
            }

            if (latlong != null && !latlong.Equals(null))
            {
                latlong.image = GetLatLongThumbnailTexture();
            }
            skyCubemapField.SetValueWithoutNotify(environment.sky.cubemap);
            skyRotationOffset.SetValueWithoutNotify(environment.sky.rotation);
            skyExposureField.SetValueWithoutNotify(environment.sky.exposure);
            shadowCubemapField.SetValueWithoutNotify(environment.shadow.cubemap);
            sunPosition.SetValueWithoutNotify(new Vector2(environment.shadow.sunLongitude, environment.shadow.sunLatitude));
            shadowColor.SetValueWithoutNotify(environment.shadow.color);
            environmentName.SetValueWithoutNotify(environment.name);
        }
Esempio n. 7
0
        public void UpdateFromChildField(string bindingPath, Color newValue)
        {
            while (fieldValues.Count != bindingPathArray.Length)
            {
                fieldValues.Add(new Color());
            }

            var fieldIndex = Array.IndexOf(bindingPathArray, bindingPath);

            fieldValues[fieldIndex] = newValue;

            var value = GetCommonValueFromChildFields();

            m_ColorField.SetValueWithoutNotify(value);

            if (isMixed)
            {
                m_MixedValueLine.style.display = DisplayStyle.Flex;
            }
            else
            {
                m_MixedValueLine.style.display = DisplayStyle.None;
            }
        }
        public void RefreshPropertyValue(object val, int specificity)
        {
            if (val is StyleFloat)
            {
                var        style = (StyleFloat)val;
                FloatField field = GetOrCreateField <FloatField, float>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(style.value);
                }
            }
            else if (val is StyleInt)
            {
                var          style = (StyleInt)val;
                IntegerField field = GetOrCreateField <IntegerField, int>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(style.value);
                }
            }
            else if (val is StyleLength)
            {
                var style = (StyleLength)val;
                StyleLengthField field = GetOrCreateField <StyleLengthField, StyleLength>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(style);
                }
            }
            else if (val is StyleColor)
            {
                var        style = (StyleColor)val;
                ColorField field = GetOrCreateField <ColorField, Color>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(style.value);
                }
            }
            else if (val is StyleFont)
            {
                var         style = (StyleFont)val;
                ObjectField field = GetOrCreateObjectField <Font>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(style.value);
                }
            }
            else if (val is StyleBackground)
            {
                var         background = ((StyleBackground)val).value;
                ObjectField field;
                if (background.vectorImage != null)
                {
                    field = GetOrCreateObjectField <VectorImage>();
                }
                else
                {
                    field = GetOrCreateObjectField <Texture2D>();
                }
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(background.vectorImage != null ? (UnityEngine.Object)background.vectorImage : (UnityEngine.Object)background.texture);
                }
            }
            else if (val is StyleCursor)
            {
                // Recreate the cursor fields every time since StyleCursor
                // can be made of different fields (based on the value)
                Clear();

                StyleCursor style = (StyleCursor)val;
                if (style.value.texture != null)
                {
                    var uiTextureField = new ObjectField(m_PropertyName)
                    {
                        value = style.value.texture
                    };
                    uiTextureField.RegisterValueChangedCallback(e =>
                    {
                        StyleCursor styleCursor = (StyleCursor)StyleDebug.GetComputedStyleValue(m_SelectedElement.computedStyle, m_PropertyInfo.id);
                        var currentCursor       = styleCursor.value;
                        currentCursor.texture   = e.newValue as Texture2D;
                        SetPropertyValue(new StyleCursor(currentCursor));
                    });
                    Add(uiTextureField);

                    var uiHotspotField = new Vector2Field("hotspot")
                    {
                        value = style.value.hotspot
                    };
                    uiHotspotField.RegisterValueChangedCallback(e =>
                    {
                        StyleCursor styleCursor = (StyleCursor)StyleDebug.GetComputedStyleValue(m_SelectedElement.computedStyle, m_PropertyInfo.id);
                        var currentCursor       = styleCursor.value;
                        currentCursor.hotspot   = e.newValue;
                        SetPropertyValue(new StyleCursor(currentCursor));
                    });
                    Add(uiHotspotField);
                }
                else
                {
                    int mouseId = style.value.defaultCursorId;
                    var uiField = new EnumField(m_PropertyName, (MouseCursor)mouseId);
                    uiField.RegisterValueChangedCallback(e =>
                    {
                        int cursorId = Convert.ToInt32(e.newValue);
                        var cursor   = new Cursor()
                        {
                            defaultCursorId = cursorId
                        };
                        SetPropertyValue(new StyleCursor(cursor));
                    });
                    Add(uiField);
                }
                Add(m_SpecificityLabel);
                SetSpecificity(specificity);
            }
            else
            {
                // StyleEnum<T>
                var       type      = val.GetType();
                var       propInfo  = type.GetProperty("value");
                Enum      enumValue = propInfo.GetValue(val, null) as Enum;
                EnumField field     = GetOrCreateEnumField(enumValue);
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(enumValue);
                }
            }

            SetSpecificity(specificity);
        }
        public void RefreshPropertyValue(object val, int specificity)
        {
            if (val is float floatValue)
            {
                FloatField field = GetOrCreateField <FloatField, float>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(floatValue);
                }
            }
            else if (val is int intValue)
            {
                IntegerField field = GetOrCreateField <IntegerField, int>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(intValue);
                }
            }
            else if (val is Length lengthValue)
            {
                StyleLengthField field = GetOrCreateField <StyleLengthField, StyleLength>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(new StyleLength(lengthValue));
                }
            }
            else if (val is Color colorValue)
            {
                ColorField field = GetOrCreateField <ColorField, Color>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(colorValue);
                }
            }
            // Note: val may be null in case of reference type like "Font"
            else if (m_PropertyInfo.type == typeof(StyleFont))
            {
                ObjectField field;
                field = GetOrCreateObjectField <Font>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(val as Font);
                }
            }
            else if (val is FontDefinition fontDefinition)
            {
                ObjectField field;
                if (fontDefinition.fontAsset != null)
                {
                    if (childCount == 0)
                    {
                        field = GetObjectFieldOfTypeFontAsset();
                        SetField(field);
                    }
                    else
                    {
                        field = (ObjectField)ElementAt(0);
                    }
                }
                else
                {
                    field = GetOrCreateObjectField <Font>();
                }

                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(fontDefinition.fontAsset != null ? fontDefinition.fontAsset : fontDefinition.font);
                }
            }
            else if (val is Background bgValue)
            {
                ObjectField field;
                if (bgValue.vectorImage != null)
                {
                    field = GetOrCreateObjectField <VectorImage>();
                }
                else if (bgValue.sprite != null)
                {
                    field = GetOrCreateObjectField <Sprite>();
                }
                else if (bgValue.renderTexture != null)
                {
                    field = GetOrCreateObjectField <RenderTexture>();
                }
                else
                {
                    field = GetOrCreateObjectField <Texture2D>();
                }
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(
                        bgValue.vectorImage != null ? (UnityEngine.Object)bgValue.vectorImage :
                        (bgValue.sprite != null ? (UnityEngine.Object)bgValue.sprite :
                         (bgValue.renderTexture != null ? (UnityEngine.Object)bgValue.renderTexture :
                          (UnityEngine.Object)bgValue.texture)));
                }
            }
            else if (val is Cursor cursorValue)
            {
                // Recreate the cursor fields every time since StyleCursor
                // can be made of different fields (based on the value)
                Clear();

                if (cursorValue.texture != null)
                {
                    var uiTextureField = new ObjectField(m_PropertyName)
                    {
                        value = cursorValue.texture
                    };
                    uiTextureField.RegisterValueChangedCallback(e =>
                    {
                        var currentCursor     = (Cursor)StyleDebug.GetComputedStyleActualValue(m_SelectedElement.computedStyle, m_PropertyInfo.id);
                        currentCursor.texture = e.newValue as Texture2D;
                        SetPropertyValue(new StyleCursor(currentCursor));
                    });
                    Add(uiTextureField);

                    var uiHotspotField = new Vector2Field("hotspot")
                    {
                        value = cursorValue.hotspot
                    };
                    uiHotspotField.RegisterValueChangedCallback(e =>
                    {
                        var currentCursor     = (Cursor)StyleDebug.GetComputedStyleActualValue(m_SelectedElement.computedStyle, m_PropertyInfo.id);
                        currentCursor.hotspot = e.newValue;
                        SetPropertyValue(new StyleCursor(currentCursor));
                    });
                    Add(uiHotspotField);
                }
                else
                {
                    int mouseId = cursorValue.defaultCursorId;
                    var uiField = new EnumField(m_PropertyName, (MouseCursor)mouseId);
                    uiField.RegisterValueChangedCallback(e =>
                    {
                        int cursorId = Convert.ToInt32(e.newValue);
                        var cursor   = new Cursor()
                        {
                            defaultCursorId = cursorId
                        };
                        SetPropertyValue(new StyleCursor(cursor));
                    });
                    Add(uiField);
                }
                Add(m_SpecificityLabel);
                SetSpecificity(specificity);
            }
            else if (val is TextShadow textShadow)
            {
                ColorField colorFieldfield = GetOrCreateFields <ColorField, Color>(m_PropertyName, 0);
                if (!IsFocused(colorFieldfield))
                {
                    colorFieldfield.SetValueWithoutNotify(textShadow.color);
                }

                Vector2Field vector2Field = GetOrCreateFields <Vector2Field, Vector2>("offset", 1);
                if (!IsFocused(vector2Field))
                {
                    vector2Field.SetValueWithoutNotify(textShadow.offset);
                }

                FloatField floatField = GetOrCreateFields <FloatField, float>("blur", 2);
                if (!IsFocused(floatField))
                {
                    floatField.SetValueWithoutNotify(textShadow.blurRadius);
                }

                if (childCount == 3)
                {
                    Add(m_SpecificityLabel);
                }
            }
            else
            {
                // Enum
                Debug.Assert(val is Enum, "Expected Enum value");
                Enum      enumValue = (Enum)val;
                EnumField field     = GetOrCreateEnumField(enumValue);
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(enumValue);
                }
            }

            SetSpecificity(specificity);
        }
Esempio n. 10
0
        public void RefreshPropertyValue(object val, int specificity)
        {
            if (val is float floatValue)
            {
                FloatField field = GetOrCreateField <FloatField, float>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(floatValue);
                }
            }
            else if (val is int intValue)
            {
                IntegerField field = GetOrCreateField <IntegerField, int>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(intValue);
                }
            }
            else if (val is Length lengthValue)
            {
                StyleLengthField field = GetOrCreateField <StyleLengthField, StyleLength>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(new StyleLength(lengthValue));
                }
            }
            else if (val is Color colorValue)
            {
                ColorField field = GetOrCreateField <ColorField, Color>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(colorValue);
                }
            }
            // Note: val may be null in case of reference type like "Font"
            else if (m_PropertyInfo.type == typeof(StyleFont))
            {
                ObjectField field;
                field = GetOrCreateObjectField <Font>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(val as Font);
                }
            }
            else if (val is FontDefinition fontDefinition)
            {
                ObjectField field;
                if (fontDefinition.fontAsset != null)
                {
                    if (childCount == 0)
                    {
                        var o = new ObjectField();
                        o.objectType = typeof(FontAsset);
                        field        = o;

                        SetField(field);
                    }
                    else
                    {
                        field = (ObjectField)ElementAt(0);
                    }
                }
                else
                {
                    field = GetOrCreateObjectField <Font>();
                }

                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(fontDefinition.fontAsset != null ? (UnityEngine.Object)fontDefinition.fontAsset : (UnityEngine.Object)fontDefinition.font);
                }
            }
            else if (val is Background bgValue)
            {
                ObjectField field;
                if (bgValue.vectorImage != null)
                {
                    field = GetOrCreateObjectField <VectorImage>();
                }
                else if (bgValue.sprite != null)
                {
                    field = GetOrCreateObjectField <Sprite>();
                }
                else if (bgValue.renderTexture != null)
                {
                    field = GetOrCreateObjectField <RenderTexture>();
                }
                else
                {
                    field = GetOrCreateObjectField <Texture2D>();
                }
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(
                        bgValue.vectorImage != null ? (UnityEngine.Object)bgValue.vectorImage :
                        (bgValue.sprite != null ? (UnityEngine.Object)bgValue.sprite :
                         (bgValue.renderTexture != null ? (UnityEngine.Object)bgValue.renderTexture :
                          (UnityEngine.Object)bgValue.texture)));
                }
            }
            else if (val is Cursor cursorValue)
            {
                // Recreate the cursor fields every time since StyleCursor
                // can be made of different fields (based on the value)
                Clear();

                if (cursorValue.texture != null)
                {
                    var uiTextureField = new ObjectField(m_PropertyName)
                    {
                        value = cursorValue.texture
                    };
                    uiTextureField.RegisterValueChangedCallback(e =>
                    {
                        var currentCursor     = (Cursor)StyleDebug.GetComputedStyleValue(m_SelectedElement.computedStyle, m_PropertyInfo.id);
                        currentCursor.texture = e.newValue as Texture2D;
                        SetPropertyValue(new StyleCursor(currentCursor));
                    });
                    Add(uiTextureField);

                    var uiHotspotField = new Vector2Field("hotspot")
                    {
                        value = cursorValue.hotspot
                    };
                    uiHotspotField.RegisterValueChangedCallback(e =>
                    {
                        var currentCursor     = (Cursor)StyleDebug.GetComputedStyleValue(m_SelectedElement.computedStyle, m_PropertyInfo.id);
                        currentCursor.hotspot = e.newValue;
                        SetPropertyValue(new StyleCursor(currentCursor));
                    });
                    Add(uiHotspotField);
                }
                else
                {
                    int mouseId = cursorValue.defaultCursorId;
                    var uiField = new EnumField(m_PropertyName, (MouseCursor)mouseId);
                    uiField.RegisterValueChangedCallback(e =>
                    {
                        int cursorId = Convert.ToInt32(e.newValue);
                        var cursor   = new Cursor()
                        {
                            defaultCursorId = cursorId
                        };
                        SetPropertyValue(new StyleCursor(cursor));
                    });
                    Add(uiField);
                }
                Add(m_SpecificityLabel);
                SetSpecificity(specificity);
            }
            else if (val is TextShadow textShadow)
            {
                ColorField colorFieldfield = GetOrCreateFields <ColorField, Color>(m_PropertyName, 0);
                if (!IsFocused(colorFieldfield))
                {
                    colorFieldfield.SetValueWithoutNotify(textShadow.color);
                }

                Vector2Field vector2Field = GetOrCreateFields <Vector2Field, Vector2>("offset", 1);
                if (!IsFocused(vector2Field))
                {
                    vector2Field.SetValueWithoutNotify(textShadow.offset);
                }

                FloatField floatField = GetOrCreateFields <FloatField, float>("blur", 2);
                if (!IsFocused(floatField))
                {
                    floatField.SetValueWithoutNotify(textShadow.blurRadius);
                }

                if (childCount == 3)
                {
                    Add(m_SpecificityLabel);
                }
            }
            else if (val is Rotate rotate)
            {
                FloatField floatField = GetOrCreateFields <FloatField, float>(m_PropertyName, 0);
                if (!IsFocused(floatField))
                {
                    floatField.SetValueWithoutNotify(rotate.angle.value);
                }
                Add(m_SpecificityLabel);
                SetSpecificity(specificity);
            }
            else if (val is Scale scale)
            {
                Vector3Field vector3Field = GetOrCreateFields <Vector3Field, Vector3>(m_PropertyName, 0);
                if (!IsFocused(vector3Field))
                {
                    vector3Field.SetValueWithoutNotify(scale.value);
                }
                Add(m_SpecificityLabel);
                SetSpecificity(specificity);
            }
            else if (val is Translate translate)
            {
                StyleLengthField fieldx = GetOrCreateFields <StyleLengthField, StyleLength>(m_PropertyName, 0);
                if (!IsFocused(fieldx))
                {
                    fieldx.SetValueWithoutNotify(translate.x);
                }
                StyleLengthField fieldy = GetOrCreateFields <StyleLengthField, StyleLength>("y", 1);
                if (!IsFocused(fieldy))
                {
                    fieldy.SetValueWithoutNotify(translate.x);
                }
                FloatField floatField = GetOrCreateFields <FloatField, float>("z", 2);
                if (!IsFocused(floatField))
                {
                    floatField.SetValueWithoutNotify(translate.z);
                }
                Add(m_SpecificityLabel);
                SetSpecificity(specificity);
                SetEnabled(false);
            }
            else if (val is TransformOrigin transformOrigin)
            {
                StyleLengthField fieldx = GetOrCreateFields <StyleLengthField, StyleLength>(m_PropertyName, 0);
                if (!IsFocused(fieldx))
                {
                    fieldx.SetValueWithoutNotify(transformOrigin.x);
                }
                StyleLengthField fieldy = GetOrCreateFields <StyleLengthField, StyleLength>("y", 1);
                if (!IsFocused(fieldy))
                {
                    fieldy.SetValueWithoutNotify(transformOrigin.x);
                }
                FloatField floatField = GetOrCreateFields <FloatField, float>("z", 2);
                if (!IsFocused(floatField))
                {
                    floatField.SetValueWithoutNotify(transformOrigin.z);
                }
                Add(m_SpecificityLabel);
                SetSpecificity(specificity);
                SetEnabled(false);
            }
            else if (val is Enum)
            {
                Enum      enumValue = (Enum)val;
                EnumField field     = GetOrCreateEnumField(enumValue);
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(enumValue);
                }
            }
            else
            {
                var type = val.GetType();
                Debug.Assert(type.IsArrayOrList(), "Expected List type");

                var listValue   = val as System.Collections.IList;
                var valueString = listValue[0].ToString();
                for (int i = 1; i < listValue.Count; i++)
                {
                    valueString += $", {listValue[i]}";
                }
                TextField field = GetOrCreateField <TextField, string>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(valueString);
                }
            }

            SetSpecificity(specificity);
        }
Esempio n. 11
0
        public void Update(InspectorDataProxy <Color> proxy)
        {
            var c = proxy.Data;

            m_Field.SetValueWithoutNotify(new UnityEngine.Color(c.r, c.g, c.b, c.a));
        }