kc123kc / dotween

Automatically exported from code.google.com/p/dotween
0 stars 0 forks source link

All Tween Callbacks are being called at Tween or Sequence start #9

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
All types of callbacks are being called at tween start. So, even OnComplete 
callback is being called at tween start.

void Start()
{
    Camera.main.DOColor(Color.black, 20).OnComplete(TestCallback());
}

TweenCallback TestCallback()
{
    Debug.Log("OnComplete Called");
    return null;
}

It logs "OnComplete Called" at start up.

DOTween v0.8.145 & DOTween v0.8.150.

Is there anything wrong in my code? Or is it a bug?

Original issue reported on code.google.com by reek...@gmail.com on 7 Sep 2014 at 3:03

GoogleCodeExporter commented 9 years ago
Your code is correct. I'm gonna investigate this right now.

Original comment by daniele....@gmail.com on 7 Sep 2014 at 3:09

GoogleCodeExporter commented 9 years ago
Ooops, I quickly checked it and everything works here. Then I realized your 
code is actually not correct. You're actually calling the TestCallback method 
instead than assigning a reference it.

Instead than this:
OnComplete(TestCallback());

it should be this:
OnComplete(TestCallback);

Original comment by daniele....@gmail.com on 7 Sep 2014 at 3:13

GoogleCodeExporter commented 9 years ago
Also, the TweenCallback method should return void and not a TweenCallback:

void TestCallback()
{
    Debug.Log("OnComplete Called");
}

(sorry for the multiple separated answers)

Original comment by daniele....@gmail.com on 7 Sep 2014 at 3:14

GoogleCodeExporter commented 9 years ago
Thanks it worked. I messed with things while I tried to pass parameters in 
callback methods like HOTween's way. It would be good if you add support for 
parameter in callback methods. Otherwise I will have to implement extra methods 
for each callbacks.

Original comment by reek...@gmail.com on 7 Sep 2014 at 8:57

GoogleCodeExporter commented 9 years ago
I was actually writing about that today 
(http://forum.unity3d.com/threads/dotween-hotween-v2-a-unity-tween-engine-alpha-
now-open.260692/page-3#post-1764289), and I'm still undecided. Adding 
parameters support would make Tweens heavier (memory-wise) by approximately 24 
B. Right now you can instead use anonymous functions/lambdas to pass the 
parameters you want on the fly, like this:

void Start()
{
  Tween myTween = transform.DOMoveX(45, 1).OnComplete(() => MyFunction(myTween, 45));
}

void MyFunction(Tween t, float someFloat)
{
  // Do something
}

What do you think of this approach?

Original comment by daniele....@gmail.com on 7 Sep 2014 at 9:06

GoogleCodeExporter commented 9 years ago
Thanks. Just checked on Unity forum and implemented lambda expression. It 
worked like a charm. It is easy to implement than HOTween's params. Just one 
line of code.

You may update documentation page so that everyone can use the easy way.
After using lambda's I don't want to use params like HOTween's way.

Thanks for making such awesome tweener.

Original comment by reek...@gmail.com on 7 Sep 2014 at 9:50

GoogleCodeExporter commented 9 years ago
Very glad you like the lambda way, that took a weight out of my mind (not sure 
if this is the right English expression, but I hope it's understandable)! 
Indeed lambdas are one of my favorite C# features and I love them passionately.

Gonna update the documentation to explain this approach in the next days.

Original comment by daniele....@gmail.com on 7 Sep 2014 at 9:58