Unity3D之UGUI学习笔记(一):UGUI介绍以及Canvas

本文介绍了Unity UI系统的演变过程,从早期的OnGUI到流行的NGUI,再到官方推出的UGUI。详细解析了UGUI的特点,包括Canvas的不同渲染模式、CanvasScaler的缩放模式以及EventSystem的配置。

UGUI是Unity3D4.6官方提供的UI系统,支持2D和3D UI的开发。

Unity3D UI史

OnGUI

在Unity4.6之前,官方提供的是OnGUI函数来开发UI界面,当然问题也比较多,首先不支持可视化开发,其次UI始终位于所有3D对象的上方,无法实现在UI上添加3D模型的效果。

现在一般这套系统多用来在Unity编辑器中开发界面或者快速搭建一些调试界面时使用。

NGUI

大名鼎鼎的NGUI是可以看做是开发Unity游戏必备的插件,支持可视化开发,同时也支持2D和3D UI的开发,想在UI上显示3D模型和粒子也没问题。

我也有一套NGUI的学习笔记,还在完善中,详情可以点击:http://www.cnblogs.com/hammerc/p/4481597.html

UGUI

首先这套官方的UI系统就是被Unity请去的NGUI作者开发的,所以在操作上两者大体一致,同时UGUI是开源的系统,大家可以在下面的连接中获得UGUI的源码:

https://bitbucket.org/Unity-Technologies/ui/src

官方案例

大家可以下载一下官方提供的UGUI案例:

https://www.assetstore.unity3d.com/en/#!/content/25468

Canvas

在UGUI中,其根容器为Canvas,我们发现无论添加任何UI到场景中,都会默认生成Canvas以及EventSystem。

所有的UI都必须作为Canvas的子级进行添加。

我们接下来详细的看看Canvas的一些设置:

Canvas

Render Mode:渲染模式,如下

  1. Screen Space - Overlay:2DUI,始终显示在屏幕最前方。
  2. Screen Space - Camera:2D及3DUI,绑定到指定摄像机,可显示3D内容,同时UI可以进行3D方面的旋转,UI可以获得3D效果。
  3. World Space:3DUI,存在3D空间中的UI。

Pixel Perfect:是否已像素的方式来显示UI。

Sort Order:不同Canvas之间的前后显示排列设置。

Canvas Scaler

Ui Scale Mode:UI缩放模式,如下:

  1. Constant Pixel Size:像素大小始终不变,即一个100*100的图片在任何的分辨率下都占用100*100的像素。一般PC上会使用这种方式,因为PC端分辨率差异并不大。
  2. Scale With Screen Size:不关心图片的实际像素大小,而只关心Width及Height值,这个值如果是1000,那么100高度的图片在任何分辨率下都只占用屏幕1/10的尺寸。一般移动端会使用这种方式,因为移动端分辨率差异较大。
  3. Constant Physical Size:根据物理单位来进行缩放。

Graphic Raycaster

场景中的射线调整,用于交互事件的配置。

EventSystem

我们简单看下EventSystem,后面会有笔记详细记录EventSystem的使用方法:

这里绑定了3个脚本,可以发现除了本身的EventSystem外,还添加了关于标准输入(即鼠标键盘)和触摸输入两个输入脚本。

转载于:https://www.cnblogs.com/hammerc/p/4837204.html

The complete Visual Behaviour Authoring framework for Unity, empowering you to create advanced AI Behaviours and Logic, including three separate, fully featured, yet seamlessly interchangeable modules for you to choose and easily add in your game: • Behaviour Trees • Hierarchical State Machines • Dialogue Trees NodeCanvas is a production ready framework used by many awesome games including Kim, Pamela, Hurtworld, Shroud of the Avatar, Kingdom and Ghost of a Tale. [Games Showcase] Feature Highlights ------------------------------------- • Choose the right tool for the task at hand. • Design reactive Behaviour Trees and Hierarchical State Machines within an intuitive, designer friendly visual node editor: (Full Undo/Redo, Zoom In/Out, Multi-selection, Duplication, Copy/Pasting, JSON Import/Export, Groups, Comments and more) • Use local & global variables of any type, visually or in code, for creating reusable and actor-oriented, parametric behaviours, optionally saving and loading those variables between gaming sessions. • Data Bind variables with any component property of any type directly. • Sync variables automatically over the network using UNET, for creating multiplayer games. • Visually Debug behaviours with realtime, colorful and informative runtime debugging. • Live Edit everything while in play mode to perfectly understand your design goals and how to achieve them. • Utilize any existing code directly with advanced and extremely fast Reflection Tasks, automatically integrating Unity's and 3rd Party asset APIs. • Work with Lists/Arrays, Enums, Interfaces and pretty much ANY Variable Type you need out-of-the-box. • React to world changes and transfer data using the built-in Event System. • Reuse and Bind made behaviours among any number of different agents. • Organize your designs using Behaviour Sub-Trees and Sub-State Machines. • Extend NodeCanvas Framework to create your own Actions, Conditions, Nodes or even completely new modules with the e
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值