toppic
当前位置: 首页> 科幻小说小说> 干货 | 二.iTween插件的(Move)方法使用

干货 | 二.iTween插件的(Move)方法使用

2022-02-08 10:27:41

本章内容是由菜鸟在线高级讲师夏洛克为大家带来的关于iTween相关知识。


本节重点:

1、五种移动方法;

2、函数的基础属性及用法。


iTween官网:

http://itween.pixelplacement.com/index.php


1、五种移动方法


MoveTo:从原始位置移动到目标位置。


MoveFrom:从目标位置移动到原始位置。


MoveAdd:随时间移动游戏对象的位置,根据提供的量。


MoveBy:增加提供的坐标到游戏对象的位置。(与MoveAdd一样)


MoveUpdate:类似于MoveTo,在Update()或FixedUpdate()方法或循环环境中调用。提供每帧改变属性值的环境。不依赖于EaseType.


动画的方法一般有两种重载:


a,最小定制选项,只需要提供最少必需参数


//target:要移动的物体;position:要移动的位置;time:动画的运行的时间


public static void MoveTo(GameObject target, Vector3 position, float time);


b,完全定制选项,可定制所有的参数


//target:要移动的物体;args:定制的数组


public static void MoveTo(GameObject target, Hashtable args);


2、函数的基础属性及用法


基础属性比较简单直接上代码

public GameObject btnBegin;

void Start () { 

   

 //键值对儿的形式保存iTween所用到的参数 

 Hashtable args = new Hashtable(); 

   

//这里是设置类型,iTween的类型又很多种,在源码中的枚举EaseType中 

//例如移动的特效,先震动     在移动、先后退在移动、先加速在变速、等等 

args.Add("easeType", iTween.EaseType.easeInOutExpo); 

  

//移动的速度, 

//args.Add("speed",10f); 

//移动的整体时间。如果与speed共存那么优先speed 

args.Add("time",10f); 

//这个是处理颜色的。可以看源码的那个枚举。 

args.Add("NamedValueColor","_SpecColor"); 

//延迟执行时间 

args.Add("delay", 0.1f); 

         

//是否让游戏对象始终面朝路径行进的方向,拐弯的地方会自动旋转。 

args.Add("orienttopath", true); 

//移动的过程中面朝一个点,当“orienttopath”为true时该参数失效 

args.Add("looktarget",Vector3.zero); 

//游戏对象看向“looktarget”的秒数。 

args.Add("looktime",1.1); 

 

//游戏对象移动的路径可以为Vector3[]或Transform[] 类型。可通过iTweenPath编辑获取路径 

Vector3[] testPath = { new Vector3(0, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 1), new Vector3(1, 1, 1), new Vector3(1, 5, 1) }; 

args.Add("path", testPath); 

//是否移动到路径的起始位置(false:游戏对象立即处于路径的起始点,true:游戏对象将从原是位置移动到路径的起始点) 

args.Add("movetopath", false); 

 

//当包含“path”参数且“orienttopath”为true时,该值用于计算“looktarget”的值,表示游戏物体看着前方点的位置,(百分比,默认0.05) 

args.Add("lookahead",0.01); 

 

//限制仅在指定的轴上旋转 

args.Add("axis", "x"); 

//是否使用局部坐标(默认为false) 

args.Add("islocal", false); 

 

//三个循环类型 none loop pingPong (一般 循环 来回)   

//args.Add("loopType", "none"); 

//args.Add("loopType", "loop");   

args.Add("loopType", iTween.LoopType.pingPong); 

   

//处理移动过程中的事件。 

//开始发生移动时调用AnimationStart方法,5.0表示它的参数 

args.Add("onstart", "AnimationStart"); 

args.Add("onstartparams", 5.0f); 

//设置接受方法的对象,默认是自身接受,这里也可以改成别的对象接受, 

//那么就得在接收对象的脚本中实现AnimationStart方法。 

args.Add("onstarttarget", gameObject); 


//移动结束时调用,参数和上面类似 

args.Add("oncomplete", "AnimationEnd"); 

args.Add("oncompleteparams", "end"); 

args.Add("oncompletetarget", gameObject); 

   

//移动中调用,参数和上面类似 

args.Add("onupdate", "AnimationUpdate"); 

args.Add("onupdatetarget", gameObject); 

args.Add("onupdateparams", true); 

   

// x y z 标示移动的位置。 

args.Add("x",-5); 

args.Add("y",1); 

args.Add("z",1); 

//当然也可以写Vector3 

//args.Add("position",Vectoe3.zero); 

//最终让改对象开始移动 

iTween.MoveTo(btnBegin, args);   

    } 

//对象移动中调用 

void AnimationUpdate(bool f) 

    { 

    Debug.Log("update :" + f); 

    } 

//对象开始移动时调用 

void AnimationStart(float f) 

    { 

     Debug.Log("start :" + f); 

     } 

//对象移动时调用 

void AnimationEnd(string f) 

    { 

     Debug.Log("end : " + f); 

    } 


欢迎加入菜鸟交流群:

HTML5:276675549  |  Unity3D:389411254


友情链接