Пример #1
0
        public static void DrawTexture(Rect screenRect, Texture texture, Rect sourceRect, int leftBorder, int rightBorder, int topBorder, int bottomBorder, [UnityEngine.Internal.DefaultValue("null")] Material mat, [UnityEngine.Internal.DefaultValue("-1")] int pass)
        {
            InternalDrawTextureArguments internalDrawTextureArguments = default(InternalDrawTextureArguments);

            internalDrawTextureArguments.screenRect   = screenRect;
            internalDrawTextureArguments.texture      = texture;
            internalDrawTextureArguments.sourceRect   = sourceRect;
            internalDrawTextureArguments.leftBorder   = leftBorder;
            internalDrawTextureArguments.rightBorder  = rightBorder;
            internalDrawTextureArguments.topBorder    = topBorder;
            internalDrawTextureArguments.bottomBorder = bottomBorder;
            Color32 color = default(Color32);

            color.r = (color.g = (color.b = (color.a = 128)));
            internalDrawTextureArguments.color = color;
            internalDrawTextureArguments.mat   = mat;
            internalDrawTextureArguments.pass  = pass;
            Graphics.DrawTexture(ref internalDrawTextureArguments);
        }
Пример #2
0
 internal static extern void DrawTexture(ref InternalDrawTextureArguments arguments);
Пример #3
0
 /// <summary>
 ///   <para>Draw a texture in screen coordinates.</para>
 /// </summary>
 /// <param name="screenRect">Rectangle on the screen to use for the texture. In pixel coordinates with (0,0) in the upper-left corner.</param>
 /// <param name="texture">Texture to draw.</param>
 /// <param name="sourceRect">Region of the texture to use. In normalized coordinates with (0,0) in the bottom-left corner.</param>
 /// <param name="leftBorder">Number of pixels from the left that are not affected by scale.</param>
 /// <param name="rightBorder">Number of pixels from the right that are not affected by scale.</param>
 /// <param name="topBorder">Number of pixels from the top that are not affected by scale.</param>
 /// <param name="bottomBorder">Number of pixels from the bottom that are not affected by scale.</param>
 /// <param name="color">Color that modulates the output. The neutral value is (0.5, 0.5, 0.5, 0.5). Set as vertex color for the shader.</param>
 /// <param name="mat">Custom Material that can be used to draw the texture. If null is passed, a default material with the Internal-GUITexture.shader is used.</param>
 public static void DrawTexture(Rect screenRect, Texture texture, Rect sourceRect, int leftBorder, int rightBorder, int topBorder, int bottomBorder, [DefaultValue("null")] Material mat)
 {
   InternalDrawTextureArguments arguments = new InternalDrawTextureArguments();
   arguments.screenRect = screenRect;
   arguments.texture = texture;
   arguments.sourceRect = sourceRect;
   arguments.leftBorder = leftBorder;
   arguments.rightBorder = rightBorder;
   arguments.topBorder = topBorder;
   arguments.bottomBorder = bottomBorder;
   Color32 color32 = new Color32();
   color32.r = color32.g = color32.b = color32.a = (byte) 128;
   arguments.color = color32;
   arguments.mat = mat;
   Graphics.DrawTexture(ref arguments);
 }
Пример #4
0
 public static void DrawTexture(Rect screenRect, Texture texture, Rect sourceRect, int leftBorder, int rightBorder, int topBorder, int bottomBorder, Color color, [UnityEngine.Internal.DefaultValue("null")] Material mat)
 {
     InternalDrawTextureArguments arguments = new InternalDrawTextureArguments {
         screenRect = screenRect,
         texture = texture,
         sourceRect = sourceRect,
         leftBorder = leftBorder,
         rightBorder = rightBorder,
         topBorder = topBorder,
         bottomBorder = bottomBorder,
         color = color,
         mat = mat
     };
     DrawTexture(ref arguments);
 }
Пример #5
0
 public static void DrawTexture(Rect screenRect, Texture texture, Rect sourceRect, int leftBorder, int rightBorder, int topBorder, int bottomBorder, [UnityEngine.Internal.DefaultValue("null")] Material mat)
 {
     Color32 color;
     InternalDrawTextureArguments arguments = new InternalDrawTextureArguments {
         screenRect = screenRect,
         texture = texture,
         sourceRect = sourceRect,
         leftBorder = leftBorder,
         rightBorder = rightBorder,
         topBorder = topBorder,
         bottomBorder = bottomBorder
     };
     color = new Color32 {
         r = color.g = color.b = (byte) (color.a = 0x80)
     };
     arguments.color = color;
     arguments.mat = mat;
     DrawTexture(ref arguments);
 }
Пример #6
0
 public static void DrawTextureWithTexCoords(Rect position, Texture image, Rect texCoords, bool alphaBlend)
 {
     if (Event.current.type == EventType.Repaint)
     {
         Material material = !alphaBlend ? blitMaterial : blendMaterial;
         InternalDrawTextureArguments arguments = new InternalDrawTextureArguments {
             texture = image,
             leftBorder = 0,
             rightBorder = 0,
             topBorder = 0,
             bottomBorder = 0,
             color = color,
             mat = material,
             screenRect = position,
             sourceRect = texCoords
         };
         Graphics.DrawTexture(ref arguments);
     }
 }
Пример #7
0
        public static void DrawTexture(Rect position, Texture image, ScaleMode scaleMode, bool alphaBlend, float imageAspect)
        {
            if (Event.current.type == EventType.Repaint)
            {
                if (image == null)
                {
                    Debug.LogWarning("null texture passed to GUI.DrawTexture");
                }
                else
                {
                    if (imageAspect == 0f)
                    {
                        imageAspect = ((float) image.width) / ((float) image.height);
                    }
                    Material material = !alphaBlend ? blitMaterial : blendMaterial;
                    float num = position.width / position.height;
                    InternalDrawTextureArguments arguments = new InternalDrawTextureArguments {
                        texture = image,
                        leftBorder = 0,
                        rightBorder = 0,
                        topBorder = 0,
                        bottomBorder = 0,
                        color = color,
                        mat = material
                    };
                    switch (scaleMode)
                    {
                        case ScaleMode.StretchToFill:
                            arguments.screenRect = position;
                            arguments.sourceRect = new Rect(0f, 0f, 1f, 1f);
                            Graphics.DrawTexture(ref arguments);
                            break;

                        case ScaleMode.ScaleAndCrop:
                        {
                            if (num <= imageAspect)
                            {
                                float width = num / imageAspect;
                                arguments.screenRect = position;
                                arguments.sourceRect = new Rect(0.5f - (width * 0.5f), 0f, width, 1f);
                                Graphics.DrawTexture(ref arguments);
                                break;
                            }
                            float height = imageAspect / num;
                            arguments.screenRect = position;
                            arguments.sourceRect = new Rect(0f, (1f - height) * 0.5f, 1f, height);
                            Graphics.DrawTexture(ref arguments);
                            break;
                        }
                        case ScaleMode.ScaleToFit:
                        {
                            if (num <= imageAspect)
                            {
                                float num5 = num / imageAspect;
                                arguments.screenRect = new Rect(position.xMin, position.yMin + ((position.height * (1f - num5)) * 0.5f), position.width, num5 * position.height);
                                arguments.sourceRect = new Rect(0f, 0f, 1f, 1f);
                                Graphics.DrawTexture(ref arguments);
                                break;
                            }
                            float num4 = imageAspect / num;
                            arguments.screenRect = new Rect(position.xMin + ((position.width * (1f - num4)) * 0.5f), position.yMin, num4 * position.width, position.height);
                            arguments.sourceRect = new Rect(0f, 0f, 1f, 1f);
                            Graphics.DrawTexture(ref arguments);
                            break;
                        }
                    }
                }
            }
        }
Пример #8
0
 /// <summary>
 ///   <para>Draw a texture within a rectangle.</para>
 /// </summary>
 /// <param name="position">Rectangle on the screen to draw the texture within.</param>
 /// <param name="image">Texture to display.</param>
 /// <param name="scaleMode">How to scale the image when the aspect ratio of it doesn't fit the aspect ratio to be drawn within.</param>
 /// <param name="alphaBlend">Whether to apply alpha blending when drawing the image (enabled by default).</param>
 /// <param name="imageAspect">Aspect ratio to use for the source image. If 0 (the default), the aspect ratio from the image is used.  Pass in w/h for the desired aspect ratio.  This allows the aspect ratio of the source image to be adjusted without changing the pixel width and height.</param>
 public static void DrawTexture(Rect position, Texture image, ScaleMode scaleMode, bool alphaBlend, float imageAspect)
 {
   GUIUtility.CheckOnGUI();
   if (Event.current.type != EventType.Repaint)
     return;
   if ((Object) image == (Object) null)
   {
     Debug.LogWarning((object) "null texture passed to GUI.DrawTexture");
   }
   else
   {
     if ((double) imageAspect == 0.0)
       imageAspect = (float) image.width / (float) image.height;
     Material material = !alphaBlend ? GUI.blitMaterial : GUI.blendMaterial;
     float num1 = position.width / position.height;
     InternalDrawTextureArguments arguments = new InternalDrawTextureArguments();
     arguments.texture = image;
     arguments.leftBorder = 0;
     arguments.rightBorder = 0;
     arguments.topBorder = 0;
     arguments.bottomBorder = 0;
     arguments.color = (Color32) GUI.color;
     arguments.mat = material;
     switch (scaleMode)
     {
       case ScaleMode.StretchToFill:
         arguments.screenRect = position;
         arguments.sourceRect = new Rect(0.0f, 0.0f, 1f, 1f);
         Graphics.DrawTexture(ref arguments);
         break;
       case ScaleMode.ScaleAndCrop:
         if ((double) num1 > (double) imageAspect)
         {
           float height = imageAspect / num1;
           arguments.screenRect = position;
           arguments.sourceRect = new Rect(0.0f, (float) ((1.0 - (double) height) * 0.5), 1f, height);
           Graphics.DrawTexture(ref arguments);
           break;
         }
         float width = num1 / imageAspect;
         arguments.screenRect = position;
         arguments.sourceRect = new Rect((float) (0.5 - (double) width * 0.5), 0.0f, width, 1f);
         Graphics.DrawTexture(ref arguments);
         break;
       case ScaleMode.ScaleToFit:
         if ((double) num1 > (double) imageAspect)
         {
           float num2 = imageAspect / num1;
           arguments.screenRect = new Rect(position.xMin + (float) ((double) position.width * (1.0 - (double) num2) * 0.5), position.yMin, num2 * position.width, position.height);
           arguments.sourceRect = new Rect(0.0f, 0.0f, 1f, 1f);
           Graphics.DrawTexture(ref arguments);
           break;
         }
         float num3 = num1 / imageAspect;
         arguments.screenRect = new Rect(position.xMin, position.yMin + (float) ((double) position.height * (1.0 - (double) num3) * 0.5), position.width, num3 * position.height);
         arguments.sourceRect = new Rect(0.0f, 0.0f, 1f, 1f);
         Graphics.DrawTexture(ref arguments);
         break;
     }
   }
 }