当前位置:主页 > 开发频道 > 游戏开发 > 游戏引擎 >

GuiManager2的用法,想让GUI旋转缩放是很简单的

时间: 2010-03-11 12:51 点击:

作者 gagaga 原帖地址 http://www.cocoachina.com/bbs/read.php?tid-15794.html GUIManager 2是besuser发表于unity官方论坛的一个Unity插件,主要用在iPhone上。 插件地址: http://forum.unity3d.com/viewtopic.php?t=43084 本
作者  gagaga

原帖地址  http://www.cocoachina.com/bbs/read.php?tid-15794.html

GUIManager 2是besuser发表于unity官方论坛的一个Unity插件,主要用在iPhone上。
插件地址:http://forum.unity3d.com/viewtopic.php?t=43084
本站下载地址:http://www.cocoachina.com/bbs/job.php?action-download-pid-92520-tid-15677-aid-8094.html

优 点:(这个东西真的很强大,直接拿它做一个游戏也不是不可能的)
- 支持3D旋转缩放
- 将描绘GUI元素缩减为1个drawcall,极大地提高效率
- 支持材质地图,多个GUI元素可以放到一张图片上,节省内存
- GUI元素的所有属性都可以设置动画
- 支持逐帧角色动画
- 支持Touch事件
- 所有GUI元素都支持淡入淡出。
- 可以对GUI元素调色
- 动态缩放
- GUIText和GUITexture均可集成进场景内
- 支持10个GUI层
- 支持iPhone上5个点同时触摸
- 同时支持Unity iPhone和Unity
- 可以调节GUI上的哪部分响应触摸事件
- 与屏幕分辨率无关,并非仅仅支持iPhone
- 比上一版更容易设置
- 完美像素元素碰撞支持,也可以支持非规则物体的触摸事件。

设置方法:
1 建立一个空的项目。
2 把下载来的包导入到这个项目里。
3 建一个空的GameObject,取名为GUI。找到PlugIns目录里面的GUIManager脚本,拽上去。然后设置屏幕的分辨率(比如 480x320),如果需要iTouch支持,也同样把PlugIns目录的iTouch脚本也拽进去。


4 再建立一个空的GameObject,随便取名。比如我取名叫quadmgr,拽到刚才建立的GUI下面。然后在PlugIns目录找到 GuiQuadMgr这个脚本(不要看原文,他写错了),拽到刚创建的quadmgr上。拽完后,把Position和Rotation改成0 0 0,scale改成1 1 1。


5 重复上面,建个空的GameObject,拽到quadmgr下面,随便取名,比如button。然后把PlugIns目录里的GUIQuadObj这个 脚本拽上去。
6 然后需要调整属性了:先点选回quadmgr,里面有个Material属性。如果你导入了这个插件包,里面有个默认的material,你可以用,叫 TestMaterial。先用着吧。
你可以看看这个TestMaterial,用的Shader是GUIManager With Backface。另外还有一个Shader叫GUIManager。这两个区别就是一个翻过来也会显示材质,另一个不会。
Alloc Block Size设置为1或者以上即可。
7 这里有一堆属性设置,很简单的英文,不翻译了。


* MColor – Set the tint and alpha for the gui object.
* MWidth - The width of the gui object
* MHeight - The height of the gui object
* MLocation - The initial location on the screen this gui object should be at. The anchor is in the middle of the gui.
* MRotation - The initial rotation of the gui object.
* MScale - The initial scale of the gui object.
* MUV - The lower left UV coords of the texture map to skin this gui object.
* MDepth - The layer order. Larger value objects gets placed further back.
* MAnimUV – This is the UV coords for the first frame in a sprite animation filmstrip.
* MAnimCols – The number of columns for the sprite animation filmstrip.
* MAnimMaxFrames – The total number of frames in the sprite animation.
* MCollider - You can select None, Square or Circular hit areas used for touch inputs.
* MCollider Size – Size of the touch area associated with this gui object.
* MVisible - Is this gui object visible
* MEnabled – Determine if the gui object will response to inputs like the mouse or touches.
8 在quadmgr选好层之后,下面所有子GUI元素都会显示在这个层上。
9 在主摄像机的Culling mask里关掉创建的层(这里没搞明白,目前没影响使用)。
10 创建GUI处理程序。(自带例子里用的是C#,我传的附件用的是Javascript。)把处理程序拽到子对象上(比如刚才那个button)就可以了。

然后我再简单说一下处理GUI的脚本程序怎么写:

下面这段代码是让图片里的那个字母“G”不停顺时针旋转。请注意看代码的注释。



 
private var thisObj:GUIQuadObj;
 
function Awake(){
thisObj=gameObject.GetComponent(typeof(GUIQuadObj)); //先获取要旋转的对象,那个G
}
 
function ResetAnimation(){
thisObj.Rotation=new Vector3(0,0,0); //转完一圈之后归位接着转
}
 
function Start(){
//类似的函数还有:AnimateTo, AnimateFrom, AnimateBy
thisObj.AnimateTo(3, //持续事件
gameObject, //回调对象,写gameObject就可以
"ResetAnimation", //回调函数名
null, //回调参数
"Rotation", //这个参数,可以是Rotation,Location,Scale等,参看上面第7条的属性名,把前面的M去掉,都可以调整
new Vector3(0,0,-360),
"easing",
Ani.AnimationEasingType.LinearEasing);//其他的easing方式还有:LinearEasing QuadraticEasing CubicEasing QuarticEasing QuinticEasing SinusoidalEasing ExponentialEasing CircularEasing BackEasing BounceEasing ElasticEasing
thisObj.StartAnimation (Ani.Animate.Loop, null, null, null); //循环方式有两种:Ani.Animate.OneShot, Ani.Animate.Loop
}
 


再有就是关于Texture地图的问题。例子里面带了 个图SampleMenu,刚开始使用的时候,可以直接就改它那个图,试验一下按钮或者动画怎么放。

这样一来,使用 GUIManager2,你所有的GUI旋转,缩放,动画之类的问题,就都解决了。GUI再也不会看起来很无聊了。

附:GuiManager2 类的参考:

GUIQuadObj Class:
This class handles the quad for all the GUI elements. It communicates with the GUIQuadMgr to merge all the elements into a single mesh.

顶一下(3)

100%

踩一下(0)

0%

发表评论

评价: 中立 好评 差评 请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。

表情: