iTweenはとても便利なAssetですが、onupdate
やoncomplete
でdelegate
が使えないという点が少し不便だったので調べてみたところ簡単に変更できるようです。
//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{
Debug.LogError("iTween Error: Callback method references must be passed as a String!");
Destroy (this);
}
という部分を
//throw an error if a string wasn't passed for callback:
if (tweenArguments[callbackType] is Action<object>) {
((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);
}
と書き換えます。
すると、次のような感じでonupdate
が使えるようになります。
Hashtable ht = new Hashtable ();
ht.Add ("from", 0.0f);
ht.Add ("to", 1.0f);
ht.Add ("onupdate", (System.Action<object>)(v => {
Debug.Log("v = " + (float)v);
}));
iTween.MoveTo(gameObject, ht);
便利です。
リンク
Specifying a delegate for the value of onupdate in iTween. – Unity Answers
https://answers.unity.com/questions/490719/specifying-a-delegate-for-the-value-of-onupdate-in.html