DrawTextureWithTexCoords()的使用
来源:互联网 发布:温室效应 知乎 编辑:程序博客网 时间:2024/05/15 09:03
一、新建一个脚本挂在主像机上
- using UnityEngine;
- using System.Collections;
- public class DrawTextureWithTexCoordsTest : MonoBehaviour {
- public Texture tex;
- void OnGUI () {
- //指定要显示在的屏幕区域
- Rect destRect = new Rect(50, 50, tex.width, tex.height);
- //指定要显示的图片区域
- Rect sourceRect = new Rect(0, 0, tex.width, tex.height);
- DrawTextureWithTexCoords(destRect, sourceRect, tex);
- }
- void DrawTextureWithTexCoords(Rect destRect, Rect sourceRect, Texture tex)
- {
- int tw, th;
- tw = tex.width;
- th = tex.height;
- //------------调整放缩比例------------------
- sourceRect.x = sourceRect.x / tw;
- //屏幕坐标系原点: 左上角
- //图片坐标系原点: 左下角
- //图片的Y轴与屏幕的Y转方向相反,这里需要颠倒一下(都以左上角为坐标原点)
- sourceRect.y = 1.0f - (sourceRect.y + sourceRect.height) / th;
- sourceRect.width = sourceRect.width / tw;
- sourceRect.height = sourceRect.height / th;
- //------------------------------------------
- GUI.DrawTextureWithTexCoords(destRect, tex, sourceRect, true);
- }
- }
DrawTextureWithTexCoords(Rect position, Texture image, Rect texCoords, bool alphaBlend)
参数说明:
position: 屏幕坐标的具体位置
image: 显示用的纹理图片
texCoords: 当图片长宽比不适合给定范围长宽比的时候如何伸缩图像 (这点要注意)
alphaBlend: 是否启用默认的alpha渲染管线
如果是使用NGUI来做的话,那么我们就需要通过将Scale和UV Rectangle结合起来使用,具体使用方法参照赛车项目的档位加速条的制作
0 0
- DrawTextureWithTexCoords()的使用
- GUID使用的使用
- ${}的使用
- 的使用
- @[],@()的使用
- ->的使用
- +、-、*、/、%的使用
- &&的使用
- %:的使用
- Makefile中使用$$的使用
- Makefile中使用$$的使用
- Red5的使用--使用日志
- prefernce的使用具体使用
- 【工具使用】git 的使用
- 关于使用AsyncTaskLoader的使用
- 使用CABasicAnimation的基本使用
- 使用RocketMQ的客户端使用
- gulp的使用基本使用
- 【Qt】滚动条QScroolBar实现滚屏功能
- LeetCode(74) Search a 2D Matrix
- Chef之Resource
- AutoLayout中的Scrollview笔记
- 初始化参数之cursor_sharing
- DrawTextureWithTexCoords()的使用
- LeetCode_108Convert Sorted Array to Binary Search Tree
- 多图片上传
- JFinal功能浅析
- golang 类型转换
- 【数学】 LightOJ 1234 Harmonic Number
- LeetCode的算法题1:Two Sum
- angularJS学习笔记之一
- 字符串-07. 说反话-加强版 (20)