unity开发之四:摄像机渲染纹理RenderTexture的使用
来源:互联网 发布:淘宝网电影票 编辑:程序博客网 时间:2024/05/16 06:52
一.首先我们得拿到渲染纹理
我们在project面板creat一个RenderTexture,然后把这个渲染纹理给相机的Rendertexture,如下图所示:
然后如下面代码:
RenderTexture renderTexture = _mainCamera.targetTexture;//拿到目标渲染纹理RenderTexture.active = renderTexture;Texture2D tex = new Texture2D(renderTexture.width, renderTexture.height);//新建纹理存储渲染纹理tex.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);//把渲染纹理的像素给Texture2D,才能在项目里面使用tex.Apply();//记得应用一下,不然很蛋疼byte[] bytes = tex.EncodeToPNG();//拿到图片的byteFile.WriteAllBytes(Application.dataPath + "/Resources/ScreenShort/" + _index .ToString()+ ".png", bytes);//写入本地
二.把拿到的渲染纹理,加入滑动列表,成为子项
/// <summary> /// 往面料滑动列表刷数据 /// </summary> private void UpadteClothData() { ClearPrintData(_iteCloths); for (int i = 0; i < _CustomDatas.Count; i++) { //根据数据个数实例化滑动列表子项 Button item = Instantiate(_item); item.name = _CustomDatas[i].id.ToString(); CustomData clothdata = _CustomDatas[i]; Image[] _ClothImags = item.GetComponentsInChildren<Image>(); for (int j = 0; j < _ClothImags.Length; j++) { if (_ClothImags[j].name == "sprite") { Sprite spr = Sprite.Create(_CustomDatas[i].spr, new Rect(0, 0, _CustomDatas[i].spr.width, _CustomDatas[i].spr.height), Vector2.zero); spr.name = j.ToString(); _ClothImags[j].sprite = spr; } item.transform.SetParent(_ScreenshotScrollView.transform); item.transform.localPosition = new Vector3(item.transform.localPosition.x, item.transform.localPosition.y, _ScreenshotScrollView.transform.position.z); item.transform.localScale = new Vector3(2, 2, 2); _iteCloths.Add(item); } } }
关于ugui滑动列表的使用,最关键的是子项的创建和销毁,但是当我们不停的创建销毁子项的时候,会产生很多内存碎片,很不好,然后我们产生了对象池这个概念,但是我们还有另外一种做法,就是不进行子项的创建和销毁,而是替换子项的数据,不停的去刷新子项数据!下一节主要讲ugui滑动列表,并且实现这种功能!
阅读全文
0 0
- unity开发之四:摄像机渲染纹理RenderTexture的使用
- Unity中透明材质物体渲染到RenderTexture的问题
- 关于Unity 的 RenderTexture
- Unity摄像机的使用四:望远镜的效果
- 摄像机目标渲染纹理targetTexture
- Unity 游戏开发技巧集锦之使用cookie类型的纹理模拟云层的移动
- Cocos2d-x 3.x RenderTexture渲染纹理源码分析
- Cocos2d-x 3.x RenderTexture渲染纹理源码分析
- 【Cocos2d-X开发学习笔记】第07期:渲染框架之摄像机类(CCCamera)的使用
- 【Cocos2d-X开发学习笔记】第07期:渲染框架之摄像机类(CCCamera)的使用
- UGUI(二)摄像机渲染纹理
- UGUI(2)摄像机渲染纹理
- UGUI(九)摄像机渲染纹理
- RenderTexture的使用
- 使用渲染纹理的制作摄像头
- 使用渲染纹理的制作摄像头
- Unity摄像机的使用二:摄像机的切换
- Unity使用RenderTexture进行截屏
- C++动态内存管理
- 【个人模板】 筛法求素数
- Ford:$27 Security Access(2)
- 二进制安装mariadb的脚本
- linux——linux基础习题
- unity开发之四:摄像机渲染纹理RenderTexture的使用
- SQL Server 2014 虚拟机的自动备份 (Resource Manager)
- 【个人模板】 动态规划01背包
- 网络判断
- noip2017提高组初赛答案
- CSDN-markdown编辑器手册
- Git-------(1)如何用Git拷贝项目
- Linux中对文件以及目录的基础操作
- Unity实现RPG角色对话框