unity 插件iTween 官方…
来源:互联网 发布:sql server 2008注册码 编辑:程序博客网 时间:2024/06/05 22:16
在学习unity的时候会用到一些强大的插件,iTween就是一个,它是一个动画库,它的应用非常广泛,学习它推荐可以看一下官方给的例子很是经典,应该包括了它里面的所有方法的用法,还有能产生的效果,很强大,之所以有这个插件,作者是奔着以最小的投入产生最大的产出,不说了,直接上例子,现在我们来学习第一个例子Flythrough:
1。创建场景物体,三个Cube、一个plane作为地面,两个pointlight调整摄像机的位置使得视图恰可以斜视场景。如图
给三个Cube上不一样颜色的材质吧看着舒服一点。
2、控制摄像机运动
新建一个C#脚本文件命名“cameracontroller”
[csharp] viewplaincopy
- "code"
class="csharp">using UnityEngine; - using
System.Collections; -
- public
class cameraController : MonoBehaviour { -
public Transform //摄像机移动路径节点[] movepath; -
public Transform //摄像机投射方向路径节点[] targetpath; -
public Transform //摄像机投射点looktarget; -
public float value; -
-
-
private float redposition=0.16f; -
private float blueposition=0.53f; -
private float greenposition=1.0f; -
-
//gui style; -
public Font font; -
private GUIStyle newstyle= GUIStyle (); -
-
// Use this for initialization -
void Start () { -
style.font=font; -
-
-
-
} -
void OnGUI() -
{ -
value =GUI.VerticalSlider (new Rect //垂直滑动条,控制摄像机移动(Screen.width -20,20,15,Screen .height -40),value ,1,0); -
iTween .PutOnPath (gameObject ,movepath ,value );//iTween方法,在movepath节点构成的路径上根据value的值把gameobject移动到相应的位置 -
iTween .PutOnPath (looktarget ,targetpath ,value ); -
transform .LookAt (iTween .PointOnPath (targetpath,value ));//iTween.pointonpath是根据value的值把looktarget移动到相应的位置,然后摄像机投射向那个位置 -
-
if(GUI.Button ( newRect "red"))(5,Screen .height -25,50,20), -
{ -
SlideTo(redposition ); -
-
} -
if(GUI.Button ( newRect "blue"))(60,Screen .height -25,50,20), -
{ -
SlideTo(blueposition ); -
-
} -
if(GUI.Button ( newRect "green"))(115,Screen .height -25,50,20), -
{ -
SlideTo(greenposition ); -
-
} -
} -
void OnDrawGizmos() -
{ -
iTween .DrawPath (movepath ,Color.magenta ); -
iTween .DrawPath (targetpath ,Color .cyan ); -
Gizmos .color =Color.black; -
Gizmos .DrawLine (transform .position ,looktarget .position ); -
-
} -
void SlideTo( floatposition) -
{ -
iTween .Stop (gameObject );//销毁gameobject上的所有iTween -
//插值方法 -
iTween.ValueTo (gameObject,iTween.Hash ("from",value , "to",position, "time",2,"easetype",iTween.EaseType.easeInOutCubic,"onupdate","Slidevalue")); -
-
} -
void Slidevalue( floatp) -
-
{ -
value=p; -
} -
// Update is called once per frame -
void Update () { -
-
} - }
脚本的作用就是根据所给的值让摄像机移动到相应的位置,代码很简单
因为定义了摄像机移动的路径和投射点的路径节点所以在Hierarchy面板中新建空物体作为节点,如图:
然后把相应的节点拖动到脚本的相应位置:
那就看一下咱的阶段性效果吧;
曲线位置编辑是比较好时间的,不知道哪位大神能给个简单的方法,可以省点时间。
3.给每个节点分别加个可视化的线条球以便与编辑;
新建C#脚本,命名“targetpath”
[csharp] viewplaincopy
- using
UnityEngine; - using
System.Collections; -
- public
class targetpath : MonoBehaviour { -
-
void OnDrawGizmos() -
{ -
Gizmos .color =Color.cyan ; -
Gizmos .DrawSphere(transform .position ,0.25f); -
-
} - }
Gizmos 辅助线框
Gizmos are used to give visual debugging or setup aids in the sceneview.
Gizmos是用于在场景视图可视化调试或辅助设置。
不懂得话看文档啊,其实我也是用到了才看的,我是菜鸟啦,到此基本完工了,自己刚刚写blog可能有很多地方说的不够详实,原谅一下菜鸟啦。
看一下效果如何:
这是我的学习笔记了,代码对照着官方的文档很容易就能读懂的,也达到了iTween的初衷,以最小的投入得到最大的产出。行了,在学习中。
0 0
- unity 插件iTween 官方…
- unity 插件iTween 官方例子学习心得
- [unity3d] iTween文档解析(1…
- [unity3d] iTween文档解析(2…
- [unity3d] iTween文档解析(3) (…
- Unity中itween插件官方Demo的学习笔记(一)
- nodejs learnyounode pass 官方 An…
- Unity Itween插件
- 官方SkyDrive Windows Phone 客户…
- Adobe photoshop CS5 新功能官方视…
- Android SDK & Android NDK 官方下…
- Android SDK & Android NDK 官方下…
- Ubuntu 11.04 Change From Unity T…
- unity 插件 iTween简单用法
- [Unity-3] iTween动画插件
- unity 插件 iTween简单用法
- Acer A500 官方最新推送…
- Acer A500 官方最新推送…
- Delegate类简介
- unity3d异步加载场景
- 个人学习总结一异常
- C# Lambda表达式
- unity3d的图片淡入淡出代码
- unity 插件iTween 官方…
- [unity3D插件]Unity界面插件NGUI核…
- [unity3d] iTween文档解析(1…
- tomcat配置文件server.xml详解
- [unity3d] iTween文档解析(2…
- [unity3d] iTween文档解析(3) (…
- iTween用法
- 相机淡入淡出JS脚本
- 更换贴图脚本-unity3d