查看: 10719|回复: 1
打印 上一主题 下一主题

[教程] 分享——我对NGUI的理解

[复制链接]

12

主题

2

听众

231

积分

设计实习生

Rank: 2

纳金币
208
精华
0

最佳新人

跳转到指定楼层
楼主
发表于 2012-12-25 17:46:50 |只看该作者 |倒序浏览
今天看了一些NGUI,总结一下这个插件,在这分享一下。
首先,对于插件的理解,可以在unity3d里面运行的插件主要分为两种——
一种是跟Unity3D没关系的插件,主要是一些运行库。比如PC上的DLL,苹果机上的SO,在脚本里面都可以加载,从基础上讲,任何一个功能模块都要加载,而只要加载的都会在内存中有函数的地址来调用,在Unity脚本中正是知道这样一个原理来完成对动态连接库的使用的。所以,当你有一个可执行的动态连接库(比如用dll写的运算方法,你就可以发布成dll在通过脚本调用~)
好了,这个方式我在以后补上。今天说一下,基于Unity的插件。
基于Unity的意思是,以Unity为基础完成渲染,同样,也基于Unity的函数库。(UnityEngine.dll),所以,这些插件的功能实现完全是依托Unity开发出来的(当然,不可否认一些很NB的插件是加入了自己的一些库)
==================================================我是分割线===========================
NGUI是一款跨平台的以Unity为依托的GUI(概念就百度一下了~)
接下来做一些功能的实现。

   NGUI的出现使界面的设计可以所见即所得了;
   导入:插件打包下载后双击导入

   文件结构:导入后的文件如图所示:

这里面有些案例在Examples里面,个人很推荐学习。每个scene慢慢的学习。但是在开发的过程中就可以不用这些了直接把Script文件夹拷贝到资源目录下即可。
1.基本控件
基本空间的使用基本一样
点击标题栏里面的NGUI
选择




Button的属性设置就可以看着属性栏来设置了。

这个就是基本控件的设置了,其他的也都一样。具体使用,个人觉得试验一下就知道了。



相机的设置:

利用NGUI的时候,相机如果不理解确实很难搞,所以,我先讲一下,相机在渲染场景中是个什么地位。其实,相机只是我们想象的,为了表示一个能显示我们需要的东西的那个东西,所以起名叫相机。但是也是非常贴切的,我们看到的电视电影,都是符合这些原则的。
Variables

   
        
            fieldOfView
            
            The field of view of the camera in degrees.
            
        
        
            nearClipPlane
            
            The near clipping plane distance.
            
        
        
            farClipPlane
            
            The far clipping plane distance.
            
        
        
            renderingPath
            
            Rendering path.
            
        
        
            actualRenderingPath
            
            Actually used rendering path (Read Only).
            
        
        
            hdr
            
            High dynamic range rendering
            
        
        
            orthographicSize
            
            Camera's half-size when in orthographic mode.
            
        
        
            orthographic
            
            Is the camera orthographic (***e) or perspective (false)?
            
        
        
            transparencySortMode
            
            Transparent object sorting mode.
            
        
        
            depth
            
            Camera's depth in the camera rendering order.
            
        
        
            aspect
            
            The aspect ratio (width divided by height).
            
        
        
            cullingMask
            
            This is used to render parts of the scene selectively.
            
        
        
            backgroundColor
            
            The color with which the screen will be cleared.
            
        
        
            rect
            
            Where on the screen is the camera rendered in normalized coordinates.
            
        
        
            pixelRect
            
            Where on the screen is the camera rendered in pixel coordinates.
            
        
        
            targetTexture
            
            Destination render texture (Unity Pro only).
            
        
        
            pixelWidth
            
            How wide is the camera in pixels (Read Only).
            
        
        
            pixelHeight
            
            How tall is the camera in pixels (Read Only).
            
        
        
            cameraToWorldMatrix
            
            Matrix that transforms from camera space to world space (Read Only).
            
        
        
            worldToCameraMatrix
            
            Matrix that transforms from world to camera space.
            
        
        
            projectionMatrix
            
            Set a custom projection matrix.
            
        
        
            velocity
            
            Get the world-space speed of the camera (Read Only).
            
        
        
            clearFlags
            
            How the camera clears the background.
            
        
        
            useOcclusionCulling
            
            
            
        
        
            layerCullDistances
            
            Per-layer culling distances.
            
        
        
            layerCullSpherical
            
            How to perform per-layer culling for a Camera.
            
        
        
            depthTextureMode
            
            How and if camera generates a depth texture.
            
        
   


Functions

   
        
            ResetWorldToCameraMatrix
            
            Make the rendering position reflect the camera's position in the scene.
            
        
        
            ResetProjectionMatrix
            
            Make the projection reflect normal camera's parameters.
            
        
        
            ResetAspect
            
            Revert the aspect ratio to the screen's aspect ratio.
            
        
        
            WorldToScreenPoint
            
            Transforms position from world space into screen space.
            
        
        
            WorldToViewportPoint
            
            Transforms position from world space into viewport space.
            
        
        
            ViewportToWorldPoint
            
            Transforms position from viewport space into world space.
            
        
        
            ScreenToWorldPoint
            
            Transforms position from screen space into world space.
            
        
        
            ScreenToViewportPoint
            
            Transforms position from screen space into viewport space.
            
        
        
            ViewportToScreenPoint
            
            Transforms position from viewport space into screen space.
            
        
        
            ViewportPointToRay
            
            Returns a ray going from camera through a viewport point.
            
        
        
            ScreenPointToRay
            
            Returns a ray going from camera through a screen point.
            
        
        
            Render
            
            Render the camera manually.
            
        
        
            RenderWithShader
            
            Render the camera with shader replacement.
            
        
        
            SetReplacementShader
            
            Make the camera render with shader replacement.
            
        
        
            ResetReplacementShader
            
            Remove shader replacement from camera.
            
        
        
            RenderToCubemap
            
            Render into a static cubemap from this camera.
            
        
        
            CopyFrom
            
            Makes this camera's settings match other camera.
            
        
   


Messages Sent

   
        
            OnPreCull
            
            OnPreCull is called before a camera culls the scene.
            
        
        
            OnPreRender
            
            OnPreRender is called before a camera starts rendering the scene.
            
        
        
            OnPostRender
            
            OnPostRender is called after a camera has finished rendering the scene.
            
        
        
            OnRenderImage
            
            OnRenderImage is called after all rendering is complete to render image
            
        
        
            OnRenderObject
            
            OnRenderObject is called after camera has rendered the scene.
            
        
        
            OnWillRenderObject
            
            OnWillRenderObject is called once for each camera if the object is visible.
            
        
   


Class Variables

   
        
            main
            
            The first enabled camera tagged "MainCamera" (Read Only).
            
        
        
            current
            
            The camera we are currently rendering with, for low-level render control only (Read Only).
            
        
        
            allCameras
            
            Returns all enabled cameras in the scene.
            
        
   










这张图片就是相机组件的属性窗口,其中的属性都可以在帮助文档里面找到。这里需要说的是在我们建立NGUI的时候,会伴随着另一个Camera的创建,这个时候,就会有两个相机显示了,Q:“两个相机会同时显示?”A:“是的,只要设置不同的深度,多相机是可以显示的”,那么什么是深度呢?

深度就是决定相机所渲染的东西能不能显示的一个功能,如果我的相机深度是-1  你的相机是1 那么对不起你不过深,但是,如果你设置了相机的ClearFlags:depthOnly 并且,把 Culling Mask设置为 MyLayer(layer是用来给物体做标记的一个标签。)所有属于MyLayer的东西就都能用你的相机显示了。
所以,在NGUI里面,如果你有了一个相机,又想让GUI的材料单独显示,那么就给NGUI的东西加上一个标签,使用单独的相机显示即可。











分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

0

主题

1

听众

329

积分

设计实习生

Rank: 2

纳金币
2
精华
0

最佳新人

沙发
发表于 2013-12-26 15:42:10 |只看该作者
太强了,学习了!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-5-15 14:25 , Processed in 0.097166 second(s), 32 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部