Exemplo n.º 1
0
        public static void DrawSprite(Sprite sprite, Rect drawArea, Color color)
        {
            if ((Object)sprite == (Object)null)
            {
                return;
            }
            Texture2D texture = sprite.texture;

            if ((Object)texture == (Object)null)
            {
                return;
            }
            Rect rect  = sprite.rect;
            Rect inner = rect;

            inner.xMin += sprite.border.x;
            inner.yMin += sprite.border.y;
            inner.xMax -= sprite.border.z;
            inner.yMax -= sprite.border.w;
            Vector4 outerUv = DataUtility.GetOuterUV(sprite);
            Rect    uv      = new Rect(outerUv.x, outerUv.y, outerUv.z - outerUv.x, outerUv.w - outerUv.y);
            Vector4 padding = DataUtility.GetPadding(sprite);

            padding.x /= rect.width;
            padding.y /= rect.height;
            padding.z /= rect.width;
            padding.w /= rect.height;
            SpriteDrawUtility.DrawSprite((Texture)texture, drawArea, padding, rect, inner, uv, color, (Material)null);
        }
Exemplo n.º 2
0
        public override void OnPreviewGUI(Rect rect, GUIStyle background)
        {
            RawImage rawImage    = base.target as RawImage;
            Texture  mainTexture = rawImage.mainTexture;

            if (!(mainTexture == null))
            {
                Rect outer = RawImageEditor.Outer(rawImage);
                SpriteDrawUtility.DrawSprite(mainTexture, rect, outer, rawImage.uvRect, rawImage.canvasRenderer.GetColor());
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Draw the Image preview.
        /// </summary>

        public override void OnPreviewGUI(Rect rect, GUIStyle background)
        {
            Image image = target as Image;
            if (image == null) return;

            UnityEngine.UI.Sprite sf = image.sprite;
            if (sf == null) return;

            if (sf.type == Sprite.Type.Sprite && sf.sprite != null)
                SpriteDrawUtility.DrawSprite(sf.sprite, rect, image.canvasRenderer.GetColor());
        }
Exemplo n.º 4
0
        /// <summary>
        /// <para>Custom preview for Image component.</para>
        /// </summary>
        /// <param name="rect">Rectangle in which to draw the preview.</param>
        /// <param name="background">Background image.</param>
        public override void OnPreviewGUI(Rect rect, GUIStyle background)
        {
            RawImage target      = base.target as RawImage;
            Texture  mainTexture = target.mainTexture;

            if (mainTexture != null)
            {
                Rect outer = Outer(target);
                SpriteDrawUtility.DrawSprite(mainTexture, rect, outer, target.uvRect, target.canvasRenderer.GetColor());
            }
        }
Exemplo n.º 5
0
        /// <summary>
        ///   <para>Custom preview for Image component.</para>
        /// </summary>
        /// <param name="rect">Rectangle in which to draw the preview.</param>
        /// <param name="background">Background image.</param>
        public override void OnPreviewGUI(Rect rect, GUIStyle background)
        {
            RawImage target      = this.target as RawImage;
            Texture  mainTexture = target.mainTexture;

            if ((Object)mainTexture == (Object)null)
            {
                return;
            }
            Rect outer = RawImageEditor.Outer(target);

            SpriteDrawUtility.DrawSprite(mainTexture, rect, outer, target.uvRect, target.canvasRenderer.GetColor());
        }
Exemplo n.º 6
0
        public override void OnPreviewGUI(Rect rect, GUIStyle background)
        {
            Image image = base.target as Image;

            if (!(image == null))
            {
                Sprite sprite = image.sprite;
                if (!(sprite == null))
                {
                    SpriteDrawUtility.DrawSprite(sprite, rect, image.canvasRenderer.GetColor());
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// <para>Custom preview for Image component.</para>
        /// </summary>
        /// <param name="rect">Rectangle in which to draw the preview.</param>
        /// <param name="background">Background image.</param>
        public override void OnPreviewGUI(Rect rect, GUIStyle background)
        {
            Image target = base.target as Image;

            if (target != null)
            {
                Sprite sprite = target.sprite;
                if (sprite != null)
                {
                    SpriteDrawUtility.DrawSprite(sprite, rect, target.canvasRenderer.GetColor());
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Draw the Image preview.
        /// </summary>
        public override void OnPreviewGUI(Rect rect, GUIStyle background)
        {
            RawImage rawImage = target as RawImage;
            Texture  tex      = rawImage.mainTexture;

            if (tex == null)
            {
                return;
            }

            var outer = Outer(rawImage);

            SpriteDrawUtility.DrawSprite(tex, rect, outer, rawImage.uvRect, rawImage.canvasRenderer.GetColor());
        }
Exemplo n.º 9
0
        /// <summary>
        ///   <para>Custom preview for Image component.</para>
        /// </summary>
        /// <param name="rect">Rectangle in which to draw the preview.</param>
        /// <param name="background">Background image.</param>
        public override void OnPreviewGUI(Rect rect, GUIStyle background)
        {
            Image target = this.target as Image;

            if ((UnityEngine.Object)target == (UnityEngine.Object)null)
            {
                return;
            }
            Sprite sprite = target.sprite;

            if ((UnityEngine.Object)sprite == (UnityEngine.Object)null)
            {
                return;
            }
            SpriteDrawUtility.DrawSprite(sprite, rect, target.canvasRenderer.GetColor());
        }
Exemplo n.º 10
0
        /// <summary>
        /// Draw the Image preview.
        /// </summary>

        public override void OnPreviewGUI(Rect rect, GUIStyle background)
        {
            Image image = target as Image;

            if (image == null)
            {
                return;
            }

            Sprite sf = image.sprite;

            if (sf == null)
            {
                return;
            }

            SpriteDrawUtility.DrawSprite(sf, rect, image.canvasRenderer.GetColor());
        }
Exemplo n.º 11
0
        /// <summary>
        /// Draw the Image preview.
        /// </summary>

        public override void OnPreviewGUI(Rect rect, GUIStyle background)
        {
            RawImage rawImage = target as RawImage;
            Texture  tex      = rawImage.mainTexture;

            if (tex == null)
            {
                return;
            }

            Rect outer = rawImage.uvRect;

            outer.xMin *= rawImage.rectTransform.rect.width;
            outer.xMax *= rawImage.rectTransform.rect.width;
            outer.yMin *= rawImage.rectTransform.rect.height;
            outer.yMax *= rawImage.rectTransform.rect.height;

            SpriteDrawUtility.DrawSprite(tex, rect, outer, rawImage.uvRect, rawImage.canvasRenderer.GetColor());
        }
Exemplo n.º 12
0
        /// <summary>
        /// Draw the Image preview.
        /// </summary>

        public override void OnPreviewGUI(Rect rect, GUIStyle background)
        {
            AltSketchPaint paint = target as AltSketchPaint;
            Texture        tex   = paint.mainTexture;

            if (tex == null)
            {
                return;
            }

            Rect outer = paint.UVRect;

            outer.xMin *= paint.rectTransform.rect.width;
            outer.xMax *= paint.rectTransform.rect.width;
            outer.yMin *= paint.rectTransform.rect.height;
            outer.yMax *= paint.rectTransform.rect.height;

            SpriteDrawUtility.DrawSprite(tex, rect, outer, paint.UVRect, paint.canvasRenderer.GetColor());
        }
Exemplo n.º 13
0
 public static void DrawSprite(Sprite sprite, Rect drawArea, Color color)
 {
     if (!(sprite == null))
     {
         Texture2D texture = sprite.texture;
         if (!(texture == null))
         {
             Rect rect  = sprite.rect;
             Rect inner = rect;
             inner.xMin += sprite.border.x;
             inner.yMin += sprite.border.y;
             inner.xMax -= sprite.border.z;
             inner.yMax -= sprite.border.w;
             Vector4 outerUV = DataUtility.GetOuterUV(sprite);
             Rect    uv      = new Rect(outerUV.x, outerUV.y, outerUV.z - outerUV.x, outerUV.w - outerUV.y);
             Vector4 padding = DataUtility.GetPadding(sprite);
             padding.x /= rect.width;
             padding.y /= rect.height;
             padding.z /= rect.width;
             padding.w /= rect.height;
             SpriteDrawUtility.DrawSprite(texture, drawArea, padding, rect, inner, uv, color, null);
         }
     }
 }
Exemplo n.º 14
0
        private static void DrawSprite(Texture tex, Rect drawArea, Vector4 padding, Rect outer, Rect inner, Rect uv, Color color, Material mat)
        {
            Rect position = drawArea;

            position.width  = Mathf.Abs(outer.width);
            position.height = Mathf.Abs(outer.height);
            if (position.width > 0f)
            {
                float num = drawArea.width / position.width;
                position.width  *= num;
                position.height *= num;
            }
            if (drawArea.height > position.height)
            {
                position.y += (drawArea.height - position.height) * 0.5f;
            }
            else if (position.height > drawArea.height)
            {
                float num2 = drawArea.height / position.height;
                position.width  *= num2;
                position.height *= num2;
            }
            if (drawArea.width > position.width)
            {
                position.x += (drawArea.width - position.width) * 0.5f;
            }
            EditorGUI.DrawTextureTransparent(position, null, ScaleMode.ScaleToFit, outer.width / outer.height);
            GUI.color = color;
            Rect position2 = new Rect(position.x + position.width * padding.x, position.y + position.height * padding.w, position.width - position.width * (padding.z + padding.x), position.height - position.height * (padding.w + padding.y));

            if (mat == null)
            {
                GUI.DrawTextureWithTexCoords(position2, tex, uv, true);
            }
            else
            {
                EditorGUI.DrawPreviewTexture(position2, tex, mat);
            }
            GUI.BeginGroup(position);
            tex       = SpriteDrawUtility.contrastTexture;
            GUI.color = Color.white;
            if (inner.xMin != outer.xMin)
            {
                float x = (inner.xMin - outer.xMin) / outer.width * position.width - 1f;
                SpriteDrawUtility.DrawTiledTexture(new Rect(x, 0f, 1f, position.height), tex);
            }
            if (inner.xMax != outer.xMax)
            {
                float x2 = (inner.xMax - outer.xMin) / outer.width * position.width - 1f;
                SpriteDrawUtility.DrawTiledTexture(new Rect(x2, 0f, 1f, position.height), tex);
            }
            if (inner.yMin != outer.yMin)
            {
                float num3 = (inner.yMin - outer.yMin) / outer.height * position.height - 1f;
                SpriteDrawUtility.DrawTiledTexture(new Rect(0f, position.height - num3, position.width, 1f), tex);
            }
            if (inner.yMax != outer.yMax)
            {
                float num4 = (inner.yMax - outer.yMin) / outer.height * position.height - 1f;
                SpriteDrawUtility.DrawTiledTexture(new Rect(0f, position.height - num4, position.width, 1f), tex);
            }
            GUI.EndGroup();
        }
Exemplo n.º 15
0
 public static void DrawSprite(Texture tex, Rect drawArea, Rect outer, Rect uv, Color color)
 {
     SpriteDrawUtility.DrawSprite(tex, drawArea, Vector4.zero, outer, outer, uv, color, null);
 }
Exemplo n.º 16
0
        private static void DrawSprite(Texture tex, Rect drawArea, Vector4 padding, Rect outer, Rect inner, Rect uv, Color color, Material mat)
        {
            Rect position1 = drawArea;

            position1.width  = Mathf.Abs(outer.width);
            position1.height = Mathf.Abs(outer.height);
            if ((double)position1.width > 0.0)
            {
                float num = drawArea.width / position1.width;
                position1.width  *= num;
                position1.height *= num;
            }
            if ((double)drawArea.height > (double)position1.height)
            {
                position1.y += (float)(((double)drawArea.height - (double)position1.height) * 0.5);
            }
            else if ((double)position1.height > (double)drawArea.height)
            {
                float num = drawArea.height / position1.height;
                position1.width  *= num;
                position1.height *= num;
            }
            if ((double)drawArea.width > (double)position1.width)
            {
                position1.x += (float)(((double)drawArea.width - (double)position1.width) * 0.5);
            }
            EditorGUI.DrawTextureTransparent(position1, (Texture)null, ScaleMode.ScaleToFit, outer.width / outer.height);
            GUI.color = color;
            Rect position2 = new Rect(position1.x + position1.width * padding.x, position1.y + position1.height * padding.w, position1.width - position1.width * (padding.z + padding.x), position1.height - position1.height * (padding.w + padding.y));

            if ((Object)mat == (Object)null)
            {
                GUI.DrawTextureWithTexCoords(position2, tex, uv, true);
            }
            else
            {
                EditorGUI.DrawPreviewTexture(position2, tex, mat);
            }
            GUI.BeginGroup(position1);
            tex       = (Texture)SpriteDrawUtility.contrastTexture;
            GUI.color = Color.white;
            if ((double)inner.xMin != (double)outer.xMin)
            {
                SpriteDrawUtility.DrawTiledTexture(new Rect((float)(((double)inner.xMin - (double)outer.xMin) / (double)outer.width * (double)position1.width - 1.0), 0.0f, 1f, position1.height), tex);
            }
            if ((double)inner.xMax != (double)outer.xMax)
            {
                SpriteDrawUtility.DrawTiledTexture(new Rect((float)(((double)inner.xMax - (double)outer.xMin) / (double)outer.width * (double)position1.width - 1.0), 0.0f, 1f, position1.height), tex);
            }
            if ((double)inner.yMin != (double)outer.yMin)
            {
                float num = (float)(((double)inner.yMin - (double)outer.yMin) / (double)outer.height * (double)position1.height - 1.0);
                SpriteDrawUtility.DrawTiledTexture(new Rect(0.0f, position1.height - num, position1.width, 1f), tex);
            }
            if ((double)inner.yMax != (double)outer.yMax)
            {
                float num = (float)(((double)inner.yMax - (double)outer.yMin) / (double)outer.height * (double)position1.height - 1.0);
                SpriteDrawUtility.DrawTiledTexture(new Rect(0.0f, position1.height - num, position1.width, 1f), tex);
            }
            GUI.EndGroup();
        }