返回介绍

GUI.DrawTexture 绘制纹理

发布于 2019-12-18 15:37:45 字数 4096 浏览 1075 评论 0 收藏 0

JavaScript => public static function DrawTexture(position: Rect, image: Texture): void;
JavaScript => public static function DrawTexture(position: Rect, image: Texture, scaleMode: ScaleMode): void;
JavaScript => public static function DrawTexture(position: Rect, image: Texture, scaleMode: ScaleMode, alphaBlend: bool): void;
JavaScript => public static function DrawTexture(position: Rect, image: Texture, scaleMode: ScaleMode, alphaBlend: bool, imageAspect: float): void;

C# => public static void DrawTexture(Rect position, Texture image);
C# => public static void DrawTexture(Rect position, Texture image, ScaleMode scaleMode);
C# => public static void DrawTexture(Rect position, Texture image, ScaleMode scaleMode, bool alphaBlend);
C# => public static void DrawTexture(Rect position, Texture image, ScaleMode scaleMode, bool alphaBlend, float imageAspect);

Parameters 参数

positionRectangle on the screen to draw the texture within.
在屏幕上绘制一个内部包含纹理的矩形。
imageTexture to display.
显示纹理
scaleModeHow to scale the image when the aspect ratio of it doesn't fit the aspect ratio to be drawn within.
图片的缩放模式,当矩形的长宽比不匹配图片的长宽比时如何缩放图像。
alphaBlendWhether to apply alpha blending when drawing the image (enabled by default).
图片的混合模式,是否通道混合图片显示,默认为混合通道,如果不,图片直接被绘制显示。
imageAspectAspect 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.
源图片的长宽比,如果为0,则使用图像的长宽比。通过“宽/高”获得所需的长宽比,这允许源图像的宽高比被调整而不影响像素宽度和高度。

Description 描述

Draw a texture within a rectangle.

在矩形内绘制一个纹理

JavaScript:

	// Draws a texture in the left corner of the screen.
	// The texture is drawn in a window 60x60 pixels.
	// The source texture is given an aspect ratio of 10x1
	// and scaled to fit in the 60x60 rectangle.  Because
	// the aspect ratio is preserved, the texture will fit
	// inside a 60x10 pixel area of the screen rectangle.
	var aTexture : Texture;
 
	function OnGUI() {
		if(!aTexture){
			Debug.LogError("Assign a Texture in the inspector.");
			return;
		}
		GUI.DrawTexture(Rect(10,10,60,60), aTexture, ScaleMode.ScaleToFit, true, 10.0f);
	}

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    public Texture aTexture;
    void OnGUI() {
        if (!aTexture) {
            Debug.LogError("Assign a Texture in the inspector.");
            return;
        }
        GUI.DrawTexture(new Rect(10, 10, 60, 60), aTexture, ScaleMode.ScaleToFit, true, 10.0F);
    }
}

gui

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文