渲染物体到一张UITexture上
2015-06-23 10:12
573 查看
把这个脚本挂到一个Camera上
using UnityEngine; using System.Collections; [RequireComponent(typeof(Camera))] public class UIModelCamera : MonoBehaviour { //Render Texture属性 public int Width=256; public int Height = 256; public int Depth = 16; //所要观看的模型 public GameObject Model; //距离模型所在位置的偏移 public Vector3 Offset; //观看模型所在位置的偏移 public Vector3 LookAtOffset; //哪个UITexture要使用这个相机所渲染的Render Texture public UITexture Texture; private RenderTexture mRenderTexture; private Camera mCamera; void Awake() { mCamera = gameObject.GetComponent<Camera>(); mRenderTexture = new RenderTexture(Width, Height, Depth); mCamera.targetTexture = mRenderTexture; } // Use this for initialization void Start () { SetModel(Model); SetTexture(Texture); } void OnDestroy() { Destroy(mRenderTexture); } //设置所有观看的模型 public void SetModel(GameObject obj) { Model = obj; if(null!=Model) { gameObject.transform.position = Model.transform.position + Offset; gameObject.transform.forward = Model.transform.position + LookAtOffset - gameObject.transform.position; mCamera.cullingMask = 1<<Model.layer; } } // public void SetTexture(UITexture texture) { Texture = texture; if (null != Texture) { Texture.mainTexture = GetRenderTexture(); } } public RenderTexture GetRenderTexture() { return mRenderTexture; } #if UNITY_EDITOR void Update() { SetModel(Model); SetTexture(Texture); } #endif }
相关文章推荐
- String,StringBuffer与StringBuilder的区别
- bubble sort and heap sort and quick sort
- 黑马程序员——GUI
- RNN的历史(from Deep Learning RNNaissance with Dr. Juergen Schmidhuber)
- quintus学习笔记
- 动态计算UITableViewCell高度详解
- 学习笔记-基础知识14-GUI
- Android应用程序UI硬件加速渲染的动画执行过程分析
- servlet request 转发, 原文件和转发文件输出顺序
- String 字符串常量 StringBuffer 字符串变量(线程安全) StringBuilde
- break&continue
- iOS 自定义UIButton(图片和文字混合)
- 小白学习之路(一):stringbuilder ,stringbuffer,string区别
- Arduino 2048 小游戏得到 Banzi 大叔的赐福:It's funny!
- Android UI性能优化实战 解决布局复杂导致的程序奔溃
- IOS-UIScrollView滚动图片的简单实现
- CodeSign error: code signing is required for product type 'Unit Test Bundle' in SDK 'iOS 8.1'
- servlet request获取请求行或者请求体中的paramerter,并解决编码问题
- 使用CAShapeLayer与UIBezierPath画出想要的图形
- iOS开发之使用UIimage+ImageEffects实现图片模糊效果