- Home /
Using iTween ValueTo with onupdateparams
I have hundreds of objects (not GameObjects) and I need to interpolate some values on them. Instead of making them separate GameObjects, I would definitely prefer keeping their classes as lightweight as possible.
The problem with ValueTo is, I need to send an object reference to onupdate and I totally agree that iTween should also send the interpolation value to onupdate as well :). But there is an inconsistency since iTween seems to use onupdateparams parameter internally to hold the interpolation value and overwrites what we have given when creating the tween.
I can't find any examples around that uses ValueTo with onupdateparams, even in iTween's Callbacks Example and ValueTo Example.
Ok, I'ma going to bump this question up, as I find meself needing the same question answered. Is there a example of this out there someplace? I purchased a couple examples from pixelplacement, but alas, there is not the example I need in there that I can find.
I can move my GUI thingy just fine, but I do need to send a var along with that onupdate...
Thanks in advance.
Ok. I have found a way to do what I need to do, without having to pass that extra param with the onupdateparams. So this isn't as dire a thing as it would otherwise be.
Still, I kindof would love to see this question answered if there actually is an answer...maybe Pixelplacement would like to take a crack at it? ^_~
Thanks in advance
Answer by Wolfram · Jul 05, 2012 at 01:05 PM
With the solution prevented by karsten here, you only need to change 3 lines of code in iTween, and can then use an inline delegate for "onupdate"/"oncomplete"/"onstart" (instead of an explicit function) to execute arbitrary code with any parameters you like.
So for example you could then do something like:
string colorToChange="_Color";
iTween.ValueTo(gameObject, iTween.Hash(
"from", a,
"to", b,
"onupdate", (Action<object>) (newVal => {
Debug.Log("running iTween onupdate for "+colorToChange+" "+(float)newVal);
renderer.material.SetColor(colorToChange,Color.white*(float)newVal);
}
));
Answer by dannyskim · Dec 04, 2011 at 09:48 PM
Just like you said in your original question, the onupdateparams are handled internally by the iTween API. I have to agree with you it's a bit vague on how to utilize and set your value from the onupdate callback method, so I'll give you a straight example and hopefully you can extrapolate what you need.
public float fromValue = 0;
private IEnumerator valueToExample()
{
iTween.ValueTo( "from", fromValue, "to", 10, "onupdatetarget", gameObject, "onupdate", updateFromValue, "time", 5, "easetype", iTween.EaseType.easeOutExpo );
}
public void updateFromValue( float newValue )
{
fromValue = newValue;
Debug.Log( "My Value that is tweening: " + fromValue );
}
}
Your answer
