GUI.DrawTexture 绘制纹理

本文详细介绍了Unity中GUI.DrawTexture函数的用法,包括其参数解释和一个具体的使用示例。展示了如何通过设置不同的参数来调整纹理的显示效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

GUI.DrawTexture 绘制纹理

static function DrawTexture (position : Rectimage : TexturescaleMode : ScaleMode = ScaleMode.StretchToFillalphaBlend : bool = true,imageAspect : float = 0) : void

Parameters参数

  • position
    Rectangle on the screen to draw the texture within.
    在屏幕上绘制一个内部包含纹理的矩形。
    • image
      Texture to display.
      显示纹理
      • scaleMode
        How to scale the image when the aspect ratio of it doesn't fit the aspect ratio to be drawn within.
        图片的缩放模式,当矩形的长宽比不匹配图片的长宽比时如何缩放图像。
        • alphaBlend
          Whether to alpha blend the image on to the display (the default). If false, the picture is drawn on to the display.
          图片的混合模式,是否通道混合图片显示,默认为混合通道,如果不,图片直接被绘制显示。
          • 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. 
            源图片的长宽比,如果为0,则使用图像的长宽比。通过"宽/高"获得所需的长宽比,这允许源图像的宽高比被调整而不影响像素宽度和高度。
            var aTexture : Texture ;function OnGUI() {if(!aTexture){ //如果不指定图片会输出这条息
                       Debug.LogError ("请指定一个纹理图片");return;} //绘制一个60x60像素大小的矩形,添加一个图片将被拉伸
            //匹配个矩形,并且进行通道混合,图片缩放比例为10:1
                        GUI.DrawTexture ( Rect (10,10,60,60), aTexture, ScaleMode.ScaleToFit, true, 10.0f);
            }





using UnityEngine; using System.Collections; public class Helper : MonoBehaviour { public Texture2D[] helpTextures; public Texture2D leftArrows; public Texture2D rightArrows; private int helpValue = 0; public GUIStyle myStyle; public Texture2D backButton; public int w; public int h; // Use this for initialization void Start () { this.enabled=false; } // Update is called once per frame void Update () { if(Input.GetKeyUp(KeyCode.Escape)) { helpValue = 0; this.enabled=false; InitButton s=(InitButton)GetComponent("InitButton"); s.enabled=true; } } void OnGUI () { GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), helpTextures[helpValue], ScaleMode.StretchToFill); if(helpValue != 0 && helpValue != helpTextures.Length - 1){ if(GUI.Button(new Rect(Screen.width * 0.1f, Screen.height * 0.4f, Screen.width * 0.1f, Screen.height * 0.2f), leftArrows, myStyle)){ helpValue--; } if(GUI.Button(new Rect(Screen.width * 0.8f, Screen.height * 0.4f, Screen.width * 0.1f, Screen.height * 0.2f), rightArrows, myStyle)){ helpValue++; } }else if(helpValue == 0){ if(GUI.Button(new Rect(Screen.width * 0.8f, Screen.height * 0.4f, Screen.width * 0.1f, Screen.height * 0.2f), rightArrows, myStyle)){ helpValue++; } }else if(helpValue == helpTextures.Length - 1){ if(GUI.Button(new Rect(Screen.width * 0.1f, Screen.height * 0.4f, Screen.width * 0.1f, Screen.height * 0.2f), leftArrows, myStyle)){ helpValue--; } if(GUI.Button(new Rect(Screen.width * 0.8f, Screen.height * 0.4f, Screen.width/5, Screen.height/5), backButton, myStyle)){ helpValue = 0; Chooes s=(Chooes)GetComponent("Chooes"); s.enabled=true; GameObject fly=GameObject.Find("flyer"); Transform plane=fly.transform.Find("plane"); plane.renderer.enabled=false; Transform p=plane.transform.Find("p47 prop01"); p.renderer.enabled=false; this.enabled=false; } } } }我说的这个代码
最新发布
05-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值