Ejemplo n.º 1
0
        internal static bool TryGetImageSourceFromValue(StylePropertyValue propertyValue, out ImageSource source)
        {
            source = new ImageSource();

            switch (propertyValue.handle.valueType)
            {
            case StyleValueType.ResourcePath:
            {
                string path = propertyValue.sheet.ReadResourcePath(propertyValue.handle);
                if (!string.IsNullOrEmpty(path))
                {
                    source.texture = Panel.LoadResource(path, typeof(Texture2D)) as Texture2D;
                    if (source.texture == null)
                    {
                        source.vectorImage = Panel.LoadResource(path, typeof(VectorImage)) as VectorImage;
                    }
                }

                if (source.texture == null && source.vectorImage == null)
                {
                    Debug.LogWarning(string.Format("Image not found for path: {0}", path));
                    return(false);
                }
            }
            break;

            case StyleValueType.AssetReference:
            {
                var o = propertyValue.sheet.ReadAssetReference(propertyValue.handle);
                source.texture     = o as Texture2D;
                source.vectorImage = o as VectorImage;
                if (source.texture == null && source.vectorImage == null)
                {
                    Debug.LogWarning("Invalid image specified");
                    return(false);
                }
            }
            break;

            default:
                Debug.LogWarning("Invalid value for image texture " + propertyValue.handle.valueType);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public StyleBackground ReadStyleBackground(int index)
        {
            ImageSource        imageSource        = default(ImageSource);
            StylePropertyValue stylePropertyValue = this.m_Values[this.m_CurrentValueIndex + index];
            bool flag = stylePropertyValue.handle.valueType == StyleValueType.Keyword;

            if (flag)
            {
                bool flag2 = stylePropertyValue.handle.valueIndex != 6;
                if (flag2)
                {
                    string            arg_68_0   = "Invalid keyword for image source ";
                    StyleValueKeyword valueIndex = (StyleValueKeyword)stylePropertyValue.handle.valueIndex;
                    Debug.LogWarning(arg_68_0 + valueIndex.ToString());
                }
            }
            else
            {
                bool flag3 = !StylePropertyReader.TryGetImageSourceFromValue(stylePropertyValue, this.dpiScaling, out imageSource);
                if (flag3)
                {
                    imageSource.texture = (Panel.LoadResource("d_console.warnicon", typeof(Texture2D), this.dpiScaling) as Texture2D);
                }
            }
            bool            flag4 = imageSource.texture != null;
            StyleBackground result;

            if (flag4)
            {
                result = new StyleBackground(imageSource.texture);
            }
            else
            {
                bool flag5 = imageSource.vectorImage != null;
                if (flag5)
                {
                    result = new StyleBackground(imageSource.vectorImage);
                }
                else
                {
                    result = default(StyleBackground);
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        static int ReadEnum(StyleEnumType enumType, StylePropertyValue value)
        {
            string enumString = null;
            var    handle     = value.handle;

            if (handle.valueType == StyleValueType.Keyword)
            {
                var keyword = value.sheet.ReadKeyword(handle);
                enumString = keyword.ToUssString();
            }
            else
            {
                enumString = value.sheet.ReadEnum(handle);
            }

            StylePropertyUtil.TryGetEnumIntValue(enumType, enumString, out var intValue);
            return(intValue);
        }
Ejemplo n.º 4
0
        static public Angle ReadAngle(StylePropertyValue value)
        {
            if (value.handle.valueType == StyleValueType.Keyword)
            {
                var keyword = (StyleValueKeyword)value.handle.valueIndex;
                switch (keyword)
                {
                case StyleValueKeyword.None:
                    return(Angle.None());

                default:
                    return(new Angle());
                }
            }

            var dimension = value.sheet.ReadDimension(value.handle);

            return(dimension.ToAngle());
        }
Ejemplo n.º 5
0
        public StyleInt ReadStyleEnum(StyleEnumType enumType, int index)
        {
            StylePropertyValue stylePropertyValue = this.m_Values[this.m_CurrentValueIndex + index];
            StyleValueHandle   handle             = stylePropertyValue.handle;
            bool   flag = handle.valueType == StyleValueType.Keyword;
            string value;

            if (flag)
            {
                StyleValueKeyword svk = stylePropertyValue.sheet.ReadKeyword(handle);
                value = svk.ToUssString();
            }
            else
            {
                value = stylePropertyValue.sheet.ReadEnum(handle);
            }
            int enumIntValue = StylePropertyUtil.GetEnumIntValue(enumType, value);

            return(new StyleInt(enumIntValue));
        }
Ejemplo n.º 6
0
        static public Scale ReadScale(int valCount, StylePropertyValue val1, StylePropertyValue val2, StylePropertyValue val3)
        {
            if (val1.handle.valueType == StyleValueType.Keyword && (StyleValueKeyword)val1.handle.valueIndex == StyleValueKeyword.None)
            {
                return(Scale.None());
            }

            var scale = Vector3.one;

            switch (valCount)
            {
            case 1:     // If only one argument, the translation is along both axes
                if (val1.handle.valueType == StyleValueType.Dimension || val1.handle.valueType == StyleValueType.Float)
                {
                    scale.x = val1.sheet.ReadFloat(val1.handle);
                    scale.y = scale.x;
                }
                break;

            case 2:    //X Y value
                if (val1.handle.valueType == StyleValueType.Dimension || val1.handle.valueType == StyleValueType.Float)
                {
                    scale.x = val1.sheet.ReadFloat(val1.handle);
                }

                if (val2.handle.valueType == StyleValueType.Dimension || val2.handle.valueType == StyleValueType.Float)
                {
                    scale.y = val2.sheet.ReadFloat(val2.handle);
                }
                break;

            case 3:     //X Y Z value
                if (val3.handle.valueType == StyleValueType.Dimension || val3.handle.valueType == StyleValueType.Float)
                {
                    scale.z = val3.sheet.ReadFloat(val3.handle);
                }
                goto case 2;     //Parse the first 2 parameters
            }
            return(new Scale(scale));
        }
Ejemplo n.º 7
0
        public StyleFont ReadStyleFont(int index)
        {
            Font font = null;
            StylePropertyValue stylePropertyValue = this.m_Values[this.m_CurrentValueIndex + index];
            StyleValueType     valueType          = stylePropertyValue.handle.valueType;
            StyleValueType     styleValueType     = valueType;

            if (styleValueType != StyleValueType.ResourcePath)
            {
                if (styleValueType != StyleValueType.AssetReference)
                {
                    Debug.LogWarning("Invalid value for font " + stylePropertyValue.handle.valueType.ToString());
                }
                else
                {
                    font = (stylePropertyValue.sheet.ReadAssetReference(stylePropertyValue.handle) as Font);
                    bool flag = font == null;
                    if (flag)
                    {
                        Debug.LogWarning("Invalid font reference");
                    }
                }
            }
            else
            {
                string text  = stylePropertyValue.sheet.ReadResourcePath(stylePropertyValue.handle);
                bool   flag2 = !string.IsNullOrEmpty(text);
                if (flag2)
                {
                    font = (Panel.LoadResource(text, typeof(Font), this.dpiScaling) as Font);
                }
                bool flag3 = font == null;
                if (flag3)
                {
                    Debug.LogWarning(string.Format("Font not found for path: {0}", text));
                }
            }
            return(new StyleFont(font));
        }
Ejemplo n.º 8
0
        static public Rotate ReadRotate(int valCount, StylePropertyValue val1, StylePropertyValue val2, StylePropertyValue val3, StylePropertyValue val4)
        {
            if (val1.handle.valueType == StyleValueType.Keyword && (StyleValueKeyword)val1.handle.valueIndex == StyleValueKeyword.None)
            {
                return(Rotate.None());
            }

            var rot = Rotate.Initial();

            switch (valCount)
            {
            case 1:     // If only one argument, the only argument is an angle and the rotation is in Z
                if (val1.handle.valueType == StyleValueType.Dimension)
                {
                    rot.angle = ReadAngle(val1);
                    //we leave axis to the default value;
                }
                break;
                //other rotations are not supported
            }
            return(rot);
        }
Ejemplo n.º 9
0
        static private Length ReadTransformOriginEnum(StylePropertyValue value, out bool isVertical, out bool isHorizontal)
        {
            if (value.handle.valueType == StyleValueType.Enum)
            {
                var enumValue = (TransformOriginOffset)ReadEnum(StyleEnumType.TransformOriginOffset, value);
                switch (enumValue)
                {
                case TransformOriginOffset.Left:
                    isVertical = false; isHorizontal = true;
                    return(Length.Percent(0));

                case TransformOriginOffset.Top:
                    isVertical = true; isHorizontal = false;
                    return(Length.Percent(0));

                case TransformOriginOffset.Center:
                    isVertical = true; isHorizontal = true;
                    return(Length.Percent(50));

                case TransformOriginOffset.Right:
                    isVertical = false; isHorizontal = true;
                    return(Length.Percent(100));

                case TransformOriginOffset.Bottom:
                    isVertical = true; isHorizontal = false;
                    return(Length.Percent(100));
                }
            }
            else if (value.handle.valueType == StyleValueType.Dimension || value.handle.valueType == StyleValueType.Float)
            {
                isVertical = true; isHorizontal = true;
                return(value.sheet.ReadDimension(value.handle).ToLength());
            }

            isVertical = false; isHorizontal = false; // should not matter because there would be no ambiguity
            return(Length.Percent(50));
        }
Ejemplo n.º 10
0
        internal static bool TryGetImageSourceFromValue(StylePropertyValue propertyValue, float dpiScaling, out ImageSource source)
        {
            source = default(ImageSource);
            StyleValueType valueType      = propertyValue.handle.valueType;
            StyleValueType styleValueType = valueType;
            bool           result;

            if (styleValueType <= StyleValueType.AssetReference)
            {
                if (styleValueType != StyleValueType.ResourcePath)
                {
                    if (styleValueType == StyleValueType.AssetReference)
                    {
                        UnityEngine.Object @object = propertyValue.sheet.ReadAssetReference(propertyValue.handle);
                        source.texture     = (@object as Texture2D);
                        source.vectorImage = (@object as VectorImage);
                        bool flag = source.texture == null && source.vectorImage == null;
                        if (flag)
                        {
                            Debug.LogWarning("Invalid image specified");
                            result = false;
                            return(result);
                        }
                        goto IL_24E;
                    }
                }
                else
                {
                    string text  = propertyValue.sheet.ReadResourcePath(propertyValue.handle);
                    bool   flag2 = !string.IsNullOrEmpty(text);
                    if (flag2)
                    {
                        source.texture = (Panel.LoadResource(text, typeof(Texture2D), dpiScaling) as Texture2D);
                        bool flag3 = source.texture == null;
                        if (flag3)
                        {
                            source.vectorImage = (Panel.LoadResource(text, typeof(VectorImage), dpiScaling) as VectorImage);
                        }
                    }
                    bool flag4 = source.texture == null && source.vectorImage == null;
                    if (flag4)
                    {
                        Debug.LogWarning(string.Format("Image not found for path: {0}", text));
                        result = false;
                        return(result);
                    }
                    goto IL_24E;
                }
            }
            else if (styleValueType != StyleValueType.ScalableImage)
            {
                if (styleValueType == StyleValueType.MissingAssetReference)
                {
                    result = false;
                    return(result);
                }
            }
            else
            {
                ScalableImage scalableImage = propertyValue.sheet.ReadScalableImage(propertyValue.handle);
                bool          flag5         = scalableImage.normalImage == null && scalableImage.highResolutionImage == null;
                if (flag5)
                {
                    Debug.LogWarning("Invalid scalable image specified");
                    result = false;
                    return(result);
                }
                bool flag6 = dpiScaling > 1f;
                if (flag6)
                {
                    source.texture = scalableImage.highResolutionImage;
                    source.texture.pixelsPerPoint = 2f;
                }
                else
                {
                    source.texture = scalableImage.normalImage;
                }
                bool flag7 = !Mathf.Approximately(dpiScaling % 1f, 0f);
                if (flag7)
                {
                    source.texture.filterMode = FilterMode.Bilinear;
                }
                goto IL_24E;
            }
            Debug.LogWarning("Invalid value for image texture " + propertyValue.handle.valueType.ToString());
            result = false;
            return(result);

IL_24E:
            result = true;
            return(result);
        }
Ejemplo n.º 11
0
        public StyleCursor ReadStyleCursor(int index)
        {
            float          x = 0f;
            float          y = 0f;
            int            defaultCursorId = 0;
            Texture2D      texture         = null;
            StyleValueType valueType       = this.GetValueType(index);
            bool           flag            = valueType == StyleValueType.ResourcePath || valueType == StyleValueType.AssetReference || valueType == StyleValueType.ScalableImage;
            bool           flag2           = flag;

            if (flag2)
            {
                bool flag3 = this.valueCount < 1;
                if (flag3)
                {
                    Debug.LogWarning(string.Format("USS 'cursor' has invalid value at {0}.", index));
                }
                else
                {
                    ImageSource        imageSource = default(ImageSource);
                    StylePropertyValue value       = this.GetValue(index);
                    bool flag4 = StylePropertyReader.TryGetImageSourceFromValue(value, this.dpiScaling, out imageSource);
                    if (flag4)
                    {
                        texture = imageSource.texture;
                        bool flag5 = this.valueCount >= 3;
                        if (flag5)
                        {
                            StylePropertyValue value2 = this.GetValue(index + 1);
                            StylePropertyValue value3 = this.GetValue(index + 2);
                            bool flag6 = value2.handle.valueType != StyleValueType.Float || value3.handle.valueType != StyleValueType.Float;
                            if (flag6)
                            {
                                Debug.LogWarning("USS 'cursor' property requires two integers for the hot spot value.");
                            }
                            else
                            {
                                x = value2.sheet.ReadFloat(value2.handle);
                                y = value3.sheet.ReadFloat(value3.handle);
                            }
                        }
                    }
                }
            }
            else
            {
                bool flag7 = StylePropertyReader.getCursorIdFunc != null;
                if (flag7)
                {
                    StylePropertyValue value4 = this.GetValue(index);
                    defaultCursorId = StylePropertyReader.getCursorIdFunc(value4.sheet, value4.handle);
                }
            }
            UnityEngine.UIElements.Cursor v = new UnityEngine.UIElements.Cursor
            {
                texture         = texture,
                hotspot         = new Vector2(x, y),
                defaultCursorId = defaultCursorId
            };
            return(new StyleCursor(v));
        }
Ejemplo n.º 12
0
        public StyleInt ReadStyleInt(int index)
        {
            StylePropertyValue stylePropertyValue = this.m_Values[this.m_CurrentValueIndex + index];

            return(new StyleInt((int)stylePropertyValue.sheet.ReadFloat(stylePropertyValue.handle)));
        }
Ejemplo n.º 13
0
        static public Translate ReadTranslate(int valCount, StylePropertyValue val1, StylePropertyValue val2, StylePropertyValue val3)
        {
            if (val1.handle.valueType == StyleValueType.Keyword && (StyleValueKeyword)val1.handle.valueIndex == StyleValueKeyword.None)
            {
                return(Translate.None());
            }


            Length x = 0, y = 0;
            float  z = 0;

            switch (valCount)
            {
            case 1:    // If only one argument, the translation is along both axes
                if (val1.handle.valueType == StyleValueType.Dimension || val1.handle.valueType == StyleValueType.Float)
                {
                    x = val1.sheet.ReadDimension(val1.handle).ToLength();
                    y = val1.sheet.ReadDimension(val1.handle).ToLength();
                }
                break;

            case 2:    //X Y value
                if (val1.handle.valueType == StyleValueType.Dimension || val1.handle.valueType == StyleValueType.Float)
                {
                    x = val1.sheet.ReadDimension(val1.handle).ToLength();
                }

                if (val2.handle.valueType == StyleValueType.Dimension || val2.handle.valueType == StyleValueType.Float)
                {
                    y = val2.sheet.ReadDimension(val2.handle).ToLength();
                }
                break;

            case 3:     //X Y Z value
                if (val3.handle.valueType == StyleValueType.Dimension || val3.handle.valueType == StyleValueType.Float)
                {
                    var dimension = val3.sheet.ReadDimension(val3.handle);
                    if (dimension.unit != Dimension.Unit.Pixel && dimension.unit != Dimension.Unit.Unitless)
                    {
                        z = dimension.value;
                    }
                }
                goto case 2;     //Parse the first 2 parameters
            }
            return(new Translate(x, y, z));
        }
Ejemplo n.º 14
0
        static public TransformOrigin ReadTransformOrigin(int valCount, StylePropertyValue val1, StylePropertyValue val2, StylePropertyValue zVvalue)
        {
            Length x = Length.Percent(50), y = Length.Percent(50);
            float  z = 0;

            switch (valCount)
            {
            case 1:     //Single parameter, Could be x-offset(length or %) or offset-keyword (left, right, top, bottom, or center)
            {
                var val = ReadTransformOriginEnum(val1, out bool isVertical, out bool isHorizontal);
                if (isHorizontal)         //We apply on X by default, except if we have top or bottom
                {
                    x = val;
                }
                else
                {
                    y = val;
                }
                break;
            }

            case 2:     //two parameter ( x, y ) whether they are value or keyword. The order can be inverted if using keywords (ie top, left)
            {
                var len1 = ReadTransformOriginEnum(val1, out bool isVertical1, out bool isHorizontal1);
                var len2 = ReadTransformOriginEnum(val2, out bool isVertical2, out bool isHorizontal2);

                if (!isHorizontal1 || !isVertical2)        //Argument probably are "swapped" if one of both cant be assigned "in order" to x, y
                {
                    if (isHorizontal2 && isVertical1)
                    {
                        x = len2;
                        y = len1;
                    }
                }
                else
                {
                    x = len1;
                    y = len2;
                }

                break;
            }

            case 3:     // xyz
                if (zVvalue.handle.valueType == StyleValueType.Dimension || zVvalue.handle.valueType == StyleValueType.Float)
                {
                    var dimension = zVvalue.sheet.ReadDimension(zVvalue.handle);
                    z = dimension.value;
                }

                goto case 2;     //Go parse the first arguments
            }


            return(new TransformOrigin(x, y, z));
        }
Ejemplo n.º 15
0
        public bool IsKeyword(int index, StyleValueKeyword keyword)
        {
            StylePropertyValue stylePropertyValue = this.m_Values[this.m_CurrentValueIndex + index];

            return(stylePropertyValue.handle.valueType == StyleValueType.Keyword && stylePropertyValue.handle.valueIndex == (int)keyword);
        }
        internal static bool TryGetImageSourceFromValue(StylePropertyValue propertyValue, float dpiScaling, out ImageSource source)
        {
            source = new ImageSource();

            switch (propertyValue.handle.valueType)
            {
            case StyleValueType.ResourcePath:
            {
                string path = propertyValue.sheet.ReadResourcePath(propertyValue.handle);
                if (!string.IsNullOrEmpty(path))
                {
                    //TODO: This will use GUIUtility.pixelsPerPoint as targetDpi, this may not be the best value for the current panel
                    source.texture = Panel.LoadResource(path, typeof(Texture2D), dpiScaling) as Texture2D;
                    if (source.texture == null)
                    {
                        source.vectorImage = Panel.LoadResource(path, typeof(VectorImage), dpiScaling) as VectorImage;
                    }
                }

                if (source.texture == null && source.vectorImage == null)
                {
                    Debug.LogWarning(string.Format("Image not found for path: {0}", path));
                    return(false);
                }
            }
            break;

            case StyleValueType.AssetReference:
            {
                var o = propertyValue.sheet.ReadAssetReference(propertyValue.handle);
                source.texture     = o as Texture2D;
                source.vectorImage = o as VectorImage;
                if (source.texture == null && source.vectorImage == null)
                {
                    Debug.LogWarning("Invalid image specified");
                    return(false);
                }
            }
            break;

            case StyleValueType.ScalableImage:
            {
                var img = propertyValue.sheet.ReadScalableImage(propertyValue.handle);

                if (img.normalImage == null && img.highResolutionImage == null)
                {
                    Debug.LogWarning("Invalid scalable image specified");
                    return(false);
                }

                if (dpiScaling > 1.0f)
                {
                    source.texture = img.highResolutionImage;
                    source.texture.pixelsPerPoint = 2.0f;
                }
                else
                {
                    source.texture = img.normalImage;
                }

                if (!Mathf.Approximately(dpiScaling % 1.0f, 0))
                {
                    source.texture.filterMode = FilterMode.Bilinear;
                }
            }
            break;

            default:
                Debug.LogWarning("Invalid value for image texture " + propertyValue.handle.valueType);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 17
0
        public string ReadAsString(int index)
        {
            StylePropertyValue stylePropertyValue = this.m_Values[this.m_CurrentValueIndex + index];

            return(stylePropertyValue.sheet.ReadAsString(stylePropertyValue.handle));
        }