找回密码
 立即注册
楼主: 小米

[ugui/ngui] NGUI UITexture Resource加载图片代码

[复制链接]
发表于 2013-5-16 12:01 | 显示全部楼层 |阅读模式
  1. public class BrawlerPlayerBarTemp : MonoBehavior

  2. {



  3.     // Define all Canvases and GUIX controls here

  4.     Texture2D playerHealthMaskTexture;

  5.     Color[] playerHealthColors;

  6.     Texture2D playerHealthTexture;



  7.     public BrawlerPlayerBarTemp()

  8.     {

  9.         // Set up the texture that will be used for the power bar (need to custom mask it).

  10.         playerHealthMaskTexture = (Texture2D)Resources.Load("UI/Brawler/PlayerBarHealthMask");

  11.         playerHealthTexture = new Texture2D(playerHealthMaskTexture.width, playerHealthMaskTexture.height, TextureFormat.ARGB32, true);



  12.         int width = playerHealthMaskTexture.width;

  13.         int height = playerHealthMaskTexture.height;



  14.         for (int i = 0; i < width; i++)

  15.         {

  16.             for (int j = 0; j < height; j++)

  17.             {

  18.                 int bitIdx = i + j * width;

  19.                 if ((playerHealthColors[bitIdx]).a > 0)

  20.                 {

  21.                     playerHealthColors[bitIdx] = new Color(1f, 0f, 0f, 1f);

  22.                                     }

  23.                 else

  24.                 {

  25.                     playerHealthColors[bitIdx] = new Color(0f, 0f, 0f, 0f);

  26.                                     }

  27.             }

  28.         }

  29.     }



  30.     public void OnGUI    {

  31. playerHealthTexture.SetPixels(playerHealthColors);

  32.         playerHealthTexture.Apply();

  33. GUI.DrawTexture(new Rect(0, 0, 300, 120), playerHealthTexture);

  34.     }
复制代码

评分

参与人数 1鲜花 +1 收起 理由
cxbsr + 1

查看全部评分

发表于 2014-10-29 15:09 | 显示全部楼层
怎么看全部的代码啊??
发表于 2017-3-8 16:48 | 显示全部楼层
好帖就是要顶
发表于 2017-3-8 17:04 | 显示全部楼层
顶顶多好
发表于 2017-3-8 16:24 | 显示全部楼层
说的非常好
发表于 2017-3-8 16:52 | 显示全部楼层
很好哦
发表于 2017-3-8 16:56 | 显示全部楼层
LZ真是人才
发表于 2017-3-31 09:10 | 显示全部楼层
很不错
发表于 2017-3-31 09:35 | 显示全部楼层
顶顶多好
发表于 2017-3-31 09:50 | 显示全部楼层
说的非常好
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-4-29 18:34 , Processed in 0.100464 second(s), 27 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表