예제 #1
0
        private Rect GetSourceRect()
        {
            Rect    zero   = Rect.zero;
            Vector2 vector = Vector2.zero;
            Texture image  = this.image;
            bool    flag   = image != null;

            if (flag)
            {
                vector = this.GetTextureDisplaySize(image);
            }
            VectorImage vectorImage = this.vectorImage;
            bool        flag2       = vectorImage != null;

            if (flag2)
            {
                vector = vectorImage.size;
            }
            bool flag3 = vector != Vector2.zero;

            if (flag3)
            {
                zero.x      = this.uv.x * vector.x;
                zero.width  = this.uv.width * vector.x;
                zero.y      = (1f - this.uv.y - this.uv.height) * vector.y;
                zero.height = this.uv.height * vector.y;
            }
            return(zero);
        }
예제 #2
0
 public static Background FromVectorImage(VectorImage vi)
 {
     return(new Background()
     {
         vectorImage = vi
     });
 }
예제 #3
0
        internal static Background FromObject(object obj)
        {
            Texture2D  texture2D = obj as Texture2D;
            bool       flag      = texture2D != null;
            Background result;

            if (flag)
            {
                result = Background.FromTexture2D(texture2D);
            }
            else
            {
                VectorImage vectorImage = obj as VectorImage;
                bool        flag2       = vectorImage != null;
                if (flag2)
                {
                    result = Background.FromVectorImage(vectorImage);
                }
                else
                {
                    result = default(Background);
                }
            }
            return(result);
        }
예제 #4
0
        private void CalculateUV(Rect srcRect)
        {
            this.m_UV = new Rect(0f, 0f, 1f, 1f);
            Vector2 vector = Vector2.zero;
            Texture image  = this.image;
            bool    flag   = image != null;

            if (flag)
            {
                vector = this.GetTextureDisplaySize(image);
            }
            VectorImage vectorImage = this.vectorImage;
            bool        flag2       = vectorImage != null;

            if (flag2)
            {
                vector = vectorImage.size;
            }
            bool flag3 = vector != Vector2.zero;

            if (flag3)
            {
                this.m_UV.x      = srcRect.x / vector.x;
                this.m_UV.width  = srcRect.width / vector.x;
                this.m_UV.height = srcRect.height / vector.y;
                this.m_UV.y      = 1f - this.m_UV.height - srcRect.y / vector.y;
            }
        }
예제 #5
0
 public Background(Texture2D t)
 {
     m_Texture       = t;
     m_Sprite        = null;
     m_RenderTexture = null;
     m_VectorImage   = null;
 }
예제 #6
0
        public bool TryGetValue(CustomStyleProperty <VectorImage> property, out VectorImage value)
        {
            if (m_CustomProperties != null && m_CustomProperties.TryGetValue(property.name, out var customProp))
            {
                var source = new ImageSource();
                if (StylePropertyReader.TryGetImageSourceFromValue(customProp, dpiScaling, out source) && source.vectorImage != null)
                {
                    value = source.vectorImage;
                    return(true);
                }
            }

            value = null;
            return(false);
        }
            public static RectangleParams MakeVectorTextured(Rect rect, Rect uv, VectorImage vectorImage, ScaleMode scaleMode, ContextType panelContext)
            {
                var playmodeTintColor = panelContext == ContextType.Editor
                    ? UIElementsUtility.editorPlayModeTintColor
                    : Color.white;

                var rp = new RectangleParams
                {
                    rect              = rect,
                    uv                = uv,
                    color             = Color.white,
                    vectorImage       = vectorImage,
                    scaleMode         = scaleMode,
                    playmodeTintColor = playmodeTintColor
                };

                return(rp);
            }
예제 #8
0
        private void OnCustomStyleResolved(CustomStyleResolvedEvent e)
        {
            // We should consider not exposing image as a style at all, since it's intimately tied to uv/sourceRect
            Texture2D    textureValue     = null;
            VectorImage  vectorImageValue = null;
            string       scaleModeValue;
            Color        tintValue   = Color.white;
            ICustomStyle customStyle = e.customStyle;

            if (!m_ImageIsInline && customStyle.TryGetValue(s_ImageProperty, out textureValue))
            {
                m_Image = textureValue;
                if (m_Image != null)
                {
                    m_VectorImage = null;
                }
            }

            if (!m_ImageIsInline && customStyle.TryGetValue(s_VectorImageProperty, out vectorImageValue))
            {
                m_VectorImage = vectorImageValue;
                if (m_VectorImage != null)
                {
                    m_Image = null;
                }
            }

            if (!m_ScaleModeIsInline && customStyle.TryGetValue(s_ScaleModeProperty, out scaleModeValue))
            {
                int scaleModeIntValue;

                if (StyleSheetCache.TryParseEnum <ScaleMode>(scaleModeValue, out scaleModeIntValue))
                {
                    m_ScaleMode = (ScaleMode)scaleModeIntValue;
                }
            }

            if (!m_TintColorIsInline && customStyle.TryGetValue(s_TintColorProperty, out tintValue))
            {
                m_TintColor = tintValue;
            }
        }
예제 #9
0
        private void OnCustomStyleResolved(CustomStyleResolvedEvent e)
        {
            Texture2D    image       = null;
            VectorImage  vectorImage = null;
            Color        white       = Color.white;
            ICustomStyle customStyle = e.customStyle;
            bool         flag        = !this.m_ImageIsInline && customStyle.TryGetValue(Image.s_ImageProperty, out image);

            if (flag)
            {
                this.m_Image = image;
                bool flag2 = this.m_Image != null;
                if (flag2)
                {
                    this.m_VectorImage = null;
                }
            }
            bool flag3 = !this.m_ImageIsInline && customStyle.TryGetValue(Image.s_VectorImageProperty, out vectorImage);

            if (flag3)
            {
                this.m_VectorImage = vectorImage;
                bool flag4 = this.m_VectorImage != null;
                if (flag4)
                {
                    this.m_Image = null;
                }
            }
            string value;
            bool   flag5 = !this.m_ScaleModeIsInline && customStyle.TryGetValue(Image.s_ScaleModeProperty, out value);

            if (flag5)
            {
                this.m_ScaleMode = (ScaleMode)StylePropertyUtil.GetEnumIntValue(StyleEnumType.ScaleMode, value);
            }
            bool flag6 = !this.m_TintColorIsInline && customStyle.TryGetValue(Image.s_TintColorProperty, out white);

            if (flag6)
            {
                this.m_TintColor = white;
            }
        }
예제 #10
0
        private void OnCustomStyleResolved(CustomStyleResolvedEvent e)
        {
            // We should consider not exposing image as a style at all, since it's intimately tied to uv/sourceRect
            Texture2D    textureValue     = null;
            Sprite       spriteValue      = null;
            VectorImage  vectorImageValue = null;
            string       scaleModeValue;
            Color        tintValue   = Color.white;
            ICustomStyle customStyle = e.customStyle;

            if (!m_ImageIsInline && customStyle.TryGetValue(s_ImageProperty, out textureValue))
            {
                m_Image       = textureValue;
                m_Sprite      = null;
                m_VectorImage = null;
            }

            if (!m_ImageIsInline && customStyle.TryGetValue(s_SpriteProperty, out spriteValue))
            {
                m_Image       = null;
                m_Sprite      = spriteValue;
                m_VectorImage = null;
            }

            if (!m_ImageIsInline && customStyle.TryGetValue(s_VectorImageProperty, out vectorImageValue))
            {
                m_Image       = null;
                m_Sprite      = null;
                m_VectorImage = vectorImageValue;
            }

            if (!m_ScaleModeIsInline && customStyle.TryGetValue(s_ScaleModeProperty, out scaleModeValue))
            {
                StylePropertyUtil.TryGetEnumIntValue(StyleEnumType.ScaleMode, scaleModeValue, out var intValue);
                SetScaleMode((ScaleMode)intValue);
            }

            if (!m_TintColorIsInline && customStyle.TryGetValue(s_TintColorProperty, out tintValue))
            {
                m_TintColor = tintValue;
            }
        }
예제 #11
0
 internal StyleBackground(VectorImage v, StyleKeyword keyword)
     : this(Background.FromVectorImage(v), keyword)
 {
 }
예제 #12
0
 /// <summary>
 /// Creates from either a <see cref="Background"/> or a <see cref="StyleKeyword"/>.
 /// </summary>
 public StyleBackground(VectorImage v)
     : this(v, StyleKeyword.Undefined)
 {
 }
예제 #13
0
 public Background(Texture2D t)
 {
     m_Texture     = t;
     m_VectorImage = null;
 }
예제 #14
0
            public static MeshGenerationContextUtils.RectangleParams MakeVectorTextured(Rect rect, Rect uv, VectorImage vectorImage, ScaleMode scaleMode, ContextType panelContext)
            {
                Color color = (panelContext == ContextType.Editor) ? UIElementsUtility.editorPlayModeTintColor : Color.white;

                return(new MeshGenerationContextUtils.RectangleParams
                {
                    rect = rect,
                    uv = uv,
                    color = Color.white,
                    vectorImage = vectorImage,
                    scaleMode = scaleMode,
                    playmodeTintColor = color
                });
            }
예제 #15
0
 public StyleBackground(VectorImage v)
 {
     this = new StyleBackground(v, StyleKeyword.Undefined);
 }
예제 #16
0
 internal StyleBackground(VectorImage v, StyleKeyword keyword)
 {
     this = new StyleBackground(Background.FromVectorImage(v), keyword);
 }
예제 #17
0
 public Background(Texture2D t)
 {
     this.m_Texture     = t;
     this.m_VectorImage = null;
 }