用NGUI实现刮刮乐的效果
来源:互联网 发布:人体测量尺寸数据 编辑:程序博客网 时间:2024/05/18 20:12
用NGUI实现刮刮乐的效果
需要设置纹理是可读写的。
using UnityEngine;[RequireComponent(typeof(UITexture))]public class ChangeTexturePixel : MonoBehaviour {private UITexture mUITex;private Texture2D MyTex;public int Radius = 10;public Color Col = new Color(0,0,0,0);void Awake(){mUITex = GetComponent<UITexture>();var tex = mUITex.mainTexture as Texture2D;MyTex = new Texture2D(tex.width, tex.height, tex.format, false);MyTex.SetPixels(tex.GetPixels());MyTex.Apply();mUITex.mainTexture = MyTex;}void ChangePixelColorByCircle(int x, int y, int radius, Color col){for (int i = -Radius; i < Radius; i++){var py = y + i;if (py < 0 || py >= MyTex.height){continue;}for (int j = -Radius; j < Radius; j++){var px = x + j;if (px < 0 || px >= MyTex.width){continue;}if (new Vector2(px - x, py - y).magnitude > Radius){continue;}MyTex.SetPixel(px, py, Col);}}MyTex.Apply();}int[] WorldPos2Pix(Vector3 worldPos){var temp = transform.InverseTransformPoint(worldPos);var pos = new Vector2(temp.x+mUITex.width/2,temp.y+mUITex.height/2);float rateX = mUITex.width / (float)MyTex.width;float rateY = mUITex.height / (float)MyTex.height;return new []{(int)(pos.x / rateX), (int)(pos.y/rateY)};}void Update (){if (Input.GetMouseButton(0)){Vector3 worldPos = UICamera.currentCamera.ScreenToWorldPoint(Input.mousePosition);var posA = WorldPos2Pix(worldPos);ChangePixelColorByCircle(posA[0], posA[1], Radius, Col);}}}
0 0
- 用NGUI实现刮刮乐的效果
- NGUI实现翻牌效果
- NGUI实现背包效果
- NGUI用于实现类似于android的Activity之间的效果
- Unity3D学习之(用NGUI创建动画以及冷却效果的实现)
- NGUI|如何做出用鼠标滚动切换武器的效果
- Unity拖拽NGUI中的Texture效果实现
- Unity3D NGUI蒙版效果实现方法
- Unity插件NGUI实现技能冷却效果
- 【NGUI】实现半圆形进度条,技能CD效果
- [NGUI]用SrollViewPanel实现相册的滚动。
- NGUI 图集解包的实现
- 用NGUI实现TableView
- NGUI对游戏里各种常见UI效果的实现总结
- Unity引擎模拟实现HTML5 animation 动画效果,取代NGUI的Tweener缓动
- NGUI 类皇室战争(CR)的滚动列表效果完整实现(一)
- NGUI 类皇室战争(CR)的滚动列表效果完整实现(二)
- NGUI 类皇室战争(CR)的滚动列表效果完整实现(三)
- Keil 汉字显示不正常,删除时要删两下
- 每天一个linux命令(3):pwd命令
- RecyclerView的各种版本兼容问题处理集锦
- 人生第一篇博客
- 光流定点程序梳理
- 用NGUI实现刮刮乐的效果
- 日请求过亿的Web系统PHP7升级实践
- X11算法 VS Scrypt算法
- 101. Symmetric Tree
- jquery+ajax使用
- 1085. Perfect Sequence
- Effective Jave——第4条:通过私有构造器强化不可实例化的能力
- listview的item点击事件不触发的处理
- grep