笔记丨unity itween功能的简单使用
2020-05-08 04:02
92 查看
利用itween类中的的MoveTo函数实现人物简单线性移动动画
MoveTo函数原型以及使用说明:(使用键值对作为参数)
/// <summary> /// Changes a GameObject's position over time to a supplied destination with FULL customization options. /// </summary> /// <param name="position"> /// A <see cref="Transform"/> or <see cref="Vector3"/> for a point in space the GameObject will animate to. /// </param> /// <param name="path"> /// A <see cref="Transform[]"/> or <see cref="Vector3[]"/> for a list of points to draw a Catmull-Rom through for a curved animation path. /// </param> /// <param name="movetopath"> /// A <see cref="System.Boolean"/> for whether to automatically generate a curve from the GameObject's current position to the beginning of the path. True by default. /// </param> /// <param name="x"> /// A <see cref="System.Single"/> or <see cref="System.Double"/> for the individual setting of the x axis. /// </param> /// <param name="y"> /// A <see cref="System.Single"/> or <see cref="System.Double"/> for the individual setting of the y axis. /// </param> /// <param name="z"> /// A <see cref="System.Single"/> or <see cref="System.Double"/> for the individual setting of the z axis. /// </param> /// <param name="orienttopath"> /// A <see cref="System.Boolean"/> for whether or not the GameObject will orient to its direction of travel. False by default. /// </param> /// <param name="looktarget"> /// A <see cref="Vector3"/> or A <see cref="Transform"/> for a target the GameObject will look at. /// </param> /// <param name="looktime"> /// A <see cref="System.Single"/> or <see cref="System.Double"/> for the time in seconds the object will take to look at either the "looktarget" or "orienttopath". /// </param> /// <param name="lookahead"> /// A <see cref="System.Single"/> or <see cref="System.Double"/> for how much of a percentage to look ahead on a path to influence how strict "orientopath" is. /// </param> /// <param name="axis"> /// A <see cref="System.String"/>. Restricts rotation to the supplied axis only. /// </param> /// <param name="islocal"> /// A <see cref="System.Boolean"/> for whether to animate in world space or relative to the parent. False by default. /// </param> /// <param name="time"> /// A <see cref="System.Single"/> or <see cref="System.Double"/> for the time in seconds the animation will take to complete. /// </param> /// <param name="speed"> /// A <see cref="System.Single"/> or <see cref="System.Double"/> can be used instead of time to allow animation based on speed /// </param> /// <param name="delay"> /// A <see cref="System.Single"/> or <see cref="System.Double"/> for the time in seconds the animation will wait before beginning. /// </param> /// <param name="easetype"> /// A <see cref="EaseType"/> or <see cref="System.String"/> for the shape of the easing curve applied to the animation. /// </param> /// <param name="looptype"> /// A <see cref="LoopType"/> or <see cref="System.String"/> for the type of loop to apply once the animation has completed. /// </param> /// <param name="onstart"> /// A <see cref="System.String"/> for the name of a function to launch at the beginning of the animation. /// </param> /// <param name="onstarttarget"> /// A <see cref="GameObject"/> for a reference to the GameObject that holds the "onstart" method. /// </param> /// <param name="onstartparams"> /// A <see cref="System.Object"/> for arguments to be sent to the "onstart" method. /// </param> /// <param name="onupdate"> /// A <see cref="System.String"/> for the name of a function to launch on every step of the animation. /// </param> /// <param name="onupdatetarget"> /// A <see cref="GameObject"/> for a reference to the GameObject that holds the "onupdate" method. /// </param> /// <param name="onupdateparams"> /// A <see cref="System.Object"/> for arguments to be sent to the "onupdate" method. /// </param> /// <param name="oncomplete"> /// A <see cref="System.String"/> for the name of a function to launch at the end of the animation. /// </param> /// <param name="oncompletetarget"> /// A <see cref="GameObject"/> for a reference to the GameObject that holds the "oncomplete" method. /// </param> /// <param name="oncompleteparams"> /// A <see cref="System.Object"/> for arguments to be sent to the "oncomplete" method. /// </param> public static void MoveTo(GameObject target, Hashtable args){ //clean args: args = iTween.CleanArgs(args); //additional property to ensure ConflictCheck can work correctly since Transforms are refrences: if(args.Contains("position")){ if (args["position"].GetType() == typeof(Transform)) { Transform transform = (Transform)args["position"]; args["position"]=new Vector3(transform.position.x,transform.position.y,transform.position.z); args["rotation"]=new Vector3(transform.eulerAngles.x,transform.eulerAngles.y,transform.eulerAngles.z); args["scale"]=new Vector3(transform.localScale.x,transform.localScale.y,transform.localScale.z); } }
在水缸按钮被点击这个函数体内直接调用MoveTo函数实现小男孩的线性移动
关于其中使用到的键值对的说明:
//让小男孩从缸中爬出,坐标是(0.7f,1.68f,2.68f) //小男孩view组件非常重要,因为通过它可以直接访问挂在view组件的小男孩本身这个游戏物体,也可以访问小男孩这个游戏物体身上的任何一个组件。 //直接调用MoveTo函数,使用四组重要的键值对来控制小男孩的移动动画 //第一个参数是一个游戏物体,表示需要移动的游戏物体 //position-vector3表示移动的目的地 //easetype表示动画类型,iTween.EaseType.linear是一个枚举,表示线性运行,就是匀速播放 //time是表示动画播放持续时间 //oncomplete表示播放动画结束后回调函数MoveOver,这里MoveOver需要自行编写,目的是为了让小男孩爬出后结束爬出动作,切换到下一动作 // "oncomplete", "MoveOver",让动画播放完以后回调MoveOver函数
iTween.MoveTo(xiaoNanHaiView.gameObject, iTween.Hash("position", new Vector3(0.7f, 1.68f, 2.68f), "easetype", iTween.EaseType.linear, "time", 5f, "oncomplete", "MoveOver" ,"oncomplete", "MoveOver",);
动画执行完毕后调用函数MoveOver:
效果:
移动前:
移动后:
相关文章推荐
- unity实现简单的加密使用次数限制时间限制功能
- Unity 学习笔记(1) -- Unity简介及简单使用
- Unity DoTween加iTweenPath的简单使用
- unity实现简单的加密使用次数限制时间限制功能
- unity实现简单的加密使用次数限制时间限制功能
- Unity 学习笔记(1) — Unity简介及简单使用
- [Nodejs]初探nodejs学习笔记- 如何使用nodejs搭建简单的UDP聊天功能
- 使用FLEX实现简单WEB在线拍照功能
- 在IE下使用Firebug的简单功能
- 使用Hashtable实现简单缓存功能
- MonoRail学习笔记三:使用方便功能强大的routing功能
- ASP.NET使用Cookie简单实现记住登陆状态功能
- iOS开发学习笔记:使用xcode里的单元测试,放在STAssert…里面的语句无法使用自动完成功能
- [ASP]RegExp对象提供简单的正则表达式支持功能使用说明
- Ubuntu8.04简单使用笔记
- 使用.NET自带的功能制作简单的注册码
- J2EE实践第四部分-使用SAP CAF实现功能的简单小例子
- 在IE下使用Firebug的简单功能
- 在IE下使用Firebug的简单功能
- 使用mongodb 的MapReduce功能笔记