iTween用法与常见问题

  1. iTween oncomplete回调不工作

iTween.MoveTo (newBoom, iTween.Hash 
    "y", 100f,
    "speed",Boomspeed,
    "EaseType",BoomeaseType,
    "LoopType",BoomloopType,
    "oncomplete","BoomComplete"
    ));

// ...
void BoomComplete(){
    print("complete");
}
解决方法:添加 oncompletetarget 参数,给出回调对象:
iTween.MoveTo (newBoom, iTween.Hash(
    // ...
    "oncomplete", "BoomComplete",
    "oncompletetarget", gameObject
    ));
  1. iTween指定特定的回调: onupdate, oncomplete
    找到 void CallBack, 修改如下代码:

void CallBack(string callbackType){
    if (tweenArguments.Contains(callbackType) && !tweenArguments.Contains("ischild")) {
        //establish target:
        GameObject target;
        if (tweenArguments.Contains(callbackType+"target")) {
            target=(GameObject)tweenArguments[callbackType+"target"];
        }else{
            target=gameObject;    
        }
        
        //throw an error if a string wasn't passed for callback:
        if (tweenArguments[callbackType].GetType() == typeof(System.String)) {
            target.SendMessage((string)tweenArguments[callbackType],
                    (object)tweenArguments[callbackType+"params"],SendMessageOptions.DontRequireReceiver);
        }else if (tweenArguments[callbackType] is Action) {      // ADD CODE HERE !
            ((Action)tweenArguments[callbackType]).Invoke();
        }else if (tweenArguments[callbackType] is Action<object>) { // ADD CODE HERE !
            ((Action<object>)tweenArguments[callbackType]).Invoke((object)tweenArguments[callbackType + "params"]);
        }else{
            Debug.LogError("iTween Error: Callback method references must be passed as a String!");
            Destroy (this);
        }
    }
}
修改后的使用方法如下:
iTween.MoveTo(gameObject, iTween.Hash(
    "x", x,
    "y", y,
    "time", t,
    "easeType", iTween.EaseType.easeInCubic, 
    "oncomplete", (Action)Landing));
    
void Landing() {
    // TODO
}

 

参考链接:
http://www.javashuo.com/article/p-dhoqvkrs-gu.html
https://qa.1r1g.com/sf/ask/2280535771/

posted @ 2023-04-16 12:24  opencoder  阅读(99)  评论(0编辑  收藏  举报