返回介绍

Graphics.DrawTexture 绘制纹理

发布于 2019-12-18 15:37:44 字数 5096 浏览 1624 评论 0 收藏 0

JavaScript => public static function DrawTexture(screenRect: Rect, texture: Texture, mat: Material = null): void;
JavaScript =>public static function DrawTexture(screenRect: Rect, texture: Texture, leftBorder: int, rightBorder: int, topBorder: int, bottomBorder: int, mat: Material = null): void;
JavaScript =>public static function DrawTexture(screenRect: Rect, texture: Texture, sourceRect: Rect, leftBorder: int, rightBorder: int, topBorder: int, bottomBorder: int, mat: Material = null): void;
JavaScript =>public static function DrawTexture(screenRect: Rect, texture: Texture, sourceRect: Rect, leftBorder: int, rightBorder: int, topBorder: int, bottomBorder: int, color: Color, mat: Material = null): void;
C# => public static void DrawTexture(Rect screenRect, Texture texture, Material mat = null); C# =>public static void DrawTexture(Rect screenRect, Texture texture, int leftBorder, int rightBorder, int topBorder, int bottomBorder, Material mat = null); C# =>public static void DrawTexture(Rect screenRect, Texture texture, Rect sourceRect, int leftBorder, int rightBorder, int topBorder, int bottomBorder, Material mat = null); C# =>public static void DrawTexture(Rect screenRect, Texture texture, Rect sourceRect, int leftBorder, int rightBorder, int topBorder, int bottomBorder, Color color, Material mat = null);

Parameters 参数

screenRectRectangle on the screen to use for the texture. In pixel coordinates with (0,0) in the upper-left corner.
textureTexture to draw.
sourceRectRegion of the texture to use. In normalized coordinates with (0,0) in the bottom-left corner.
leftBorderNumber of pixels from the left that are not affected by scale.
rightBorderNumber of pixels from the right that are not affected by scale.
topBorderNumber of pixels from the top that are not affected by scale.
bottomBorderNumber of pixels from the bottom that are not affected by scale.
colorColor that modulates the output. The neutral value is (0.5, 0.5, 0.5, 0.5). Set as vertex color for the shader.
matCustom Material that can be used to draw the texture. If null is passed, a default material with the Internal-GUITexture.shader is used.

Description 描述

Draw a texture in screen coordinates.

在屏幕坐标上绘制一个纹理。

If you want to draw a texture from inside of OnGUI code, you should only do that from EventType.Repaint events. It's probably better to use GUI.DrawTexture for GUI code.

如果你想从OnGUI代码里面绘制纹理,你仅需要从EventType.Repaint事件绘制。它可能比使用GUI.DrawTexture更好。

JavaScript:

	// Draws a texture on the screen at 10, 10 with 100 width, 100 height.
 
	var aTexture : Texture;
 
	function OnGUI() {
		if(Event.current.type.Equals(EventType.Repaint))
			Graphics.DrawTexture(Rect(10, 10, 100, 100), aTexture);
	}

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    public Texture aTexture;
    void OnGUI() {
        if (Event.current.type.Equals(EventType.Repaint))
            Graphics.DrawTexture(new Rect(10, 10, 100, 100), aTexture);
 
    }
}

graphics

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

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

发布评论

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