博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Unity3D摄像机裁剪——NGUI篇
阅读量:1982 次
发布时间:2019-04-27

本文共 1395 字,大约阅读时间需要 4 分钟。

有时候,需要在一个UIScrollView中显示一个带有3D模型或者粒子特效的列表

NGUI的UIScrollView无法裁剪3D模型和粒子特效,所以想到一个办法就是使用摄像机来裁剪

最重要的是摄像机的裁剪区域的设置,需要使用到NGUI的UIViewport脚本

预设上需要事先挂好摄像机,并创建一个 topLeft 和一个 bottomRight 作为裁剪区域的左上角和右下角的定位

结构如下:

    UI Root

     |__UICamera

           |___myPanel

                 |___myUiCamera

                 |___topLeft

                 |___bottomRight

                 |___scrollviewPanel               

                         |___uiGrid

                                 |___item0

                                        |___obj3d

                                 |___item1

                                        |___obj3d

                                 |___item2

                                        |___obj3d

 

 

 

摄像机 myUiCamera 的ClearFlags设置为Depth only,Projection设置为Orthographic(正交)

Culling Mask可以用代码动态设置,假设obj_3d的layer我们设置成24,代码如下

int layer = 24;NGUITools.SetLayer(obj3d, layer);myUiCamera.cullingMask = 2^layer;     //相当于1左移24位

接下来是设置裁剪区,接口

public static void SetCullingCamViewport(Camera sourceCam, Camera targetCam, Transform topLeftTrans, Transform bottomRightTrans, GameObject dragRoot){    Vector3 camPos = (topLeftTrans.localPosition + bottomRightTrans.localPosition)*0.5f;    targetCam.transform.localPosition = camPos;    UIViewport viewport = targetCam.gameObject.AddComponent
(); viewport.topLeft = topLeftTrans; viewport.bottomRight= bottomRightTrans; viewport.sourceCamera = sourceCam; targetCam.gameObject.AddComponent
(); UIDraggableCamera dragbleCam = targetCam.gameObject.AddComponent
(); dragbleCam.rootForBounds = dragRoot;}

调用:

//假设你的NGUI主摄像机是GlobalObj.NGUICameraSetCullingCamViewport(GlobalObj.NGUICamera, myUiCamera, topLeft, bottomRight, scrollviewPanel);

 

完毕

 

转载地址:http://jdkvf.baihongyu.com/

你可能感兴趣的文章
优化算法(五)—人工蜂群算法Artificial Bee Colony Algorithm(ABC)
查看>>
轨迹规划 trajectory planning
查看>>
AGV自动导引运输车
查看>>
Trie树(字典树)
查看>>
COMP7404 Machine Learing——Logistic Regression
查看>>
COMP7404 Machine Learing——Regularization(参数C)
查看>>
COMP7404 Machine Learing——KNN
查看>>
COMP7404 Machine Learing——SVM
查看>>
COMP7404 Machine Learing——Decision Tree & Random Forests
查看>>
COMP7404 Machine Learing——Hyperparameter Grid Search & Nested Cross-Validation
查看>>
COMP7404 Machine Learing——Confusion Matrix & Precision/Recall/F1
查看>>
COMP7404 Machine Learing——ROC
查看>>
Python量子计算qiskit
查看>>
Python的多线程不是真的多线程(GIL全局解释器锁)
查看>>
Python手动读取MNIST数据集
查看>>
Python手动读取CIFAR-10数据集
查看>>
Pytorch(十一) —— 分布式(多GPU)训练
查看>>
Deeplab v3
查看>>
Pytorch之经典神经网络语义分割(3.2) —— ASPP 空洞空间金字塔池化(atrous spatial pyramid pooling )
查看>>
tensor/矩阵/图片等更换通道,调整size
查看>>