*

focus

  • ***
  • 26
    • View Profile
    • blog
DOTween Pro code-related questions
« on: November 24, 2015, 06:51:04 PM »
Hey again, Dainele! And, obviously all other forum residents!

Is it possible to somehow control DOTweenAnimation's events from code?
For example, I'd like to subscribe to the OnComplete event from code, but not sure it's possible without making public proxy which will be called by the event which I can set up in inspector.

Sorry if my question was answered before, I did tried to search forums without success before posting it =\
« Last Edit: November 24, 2015, 06:54:18 PM by focus »

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: DOTween Pro code-related questions
« Reply #1 on: November 24, 2015, 07:46:31 PM »
Hello master Dmitriy!

You could get a reference to the DOTweenAnimation's tween (myTweenAnimation.GetTweens() returns a list of all tweens created by the Animation, in top-to-bottom order) and do:
Code: [Select]
myTweenReference.OnComplete(Something);

OnComplete is always assignable at any time. Passing a NULL value to it will clear it, otherwise it will re-assign it ;)

*

focus

  • ***
  • 26
    • View Profile
    • blog
Re: DOTween Pro code-related questions
« Reply #2 on: November 24, 2015, 07:50:41 PM »
Awesome, thanks, Daniele!

But what if I'll need to have few different DOTweenAnimations on the same object?
Will GetTweens still return tweens for the specific DOTweenAnimation and not all tweens from all DOTweenAnimations on same object?

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: DOTween Pro code-related questions
« Reply #3 on: November 24, 2015, 07:57:03 PM »
Yesyes, sorry I mis-wrote. GetTweens indeed returns all tweens created by all DOTweenAnimations on the same gameObject, top-to-bottom :P

*

focus

  • ***
  • 26
    • View Profile
    • blog
Re: DOTween Pro code-related questions
« Reply #4 on: November 25, 2015, 09:34:45 AM »
Ah, cool, thanks for the clarification.
But is it possible to get the tween for the exact DOTweenAnimation somehow?

I'm trying to make component which should start DOTweenAnimation and wait for the completion to report about it to the central manager class...

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: DOTween Pro code-related questions
« Reply #5 on: November 25, 2015, 10:17:33 AM »
You could give the tween you want a univocal ID, and then use GetTweensById
Code: [Select]
DOTween.GetTweensById(myUnivocalId)[0]...

*

focus

  • ***
  • 26
    • View Profile
    • blog
Re: DOTween Pro code-related questions
« Reply #6 on: November 25, 2015, 12:41:56 PM »
Woohoo, that's it! Thank you, totally missed the id field in the inspector ^^

*

focus

  • ***
  • 26
    • View Profile
    • blog
Re: DOTween Pro code-related questions
« Reply #7 on: November 25, 2015, 12:47:09 PM »
BTW, is DOTweenAnimation.DOPlay() method starts all animations for the game object too?
I see it calls  DOTween.Play(this.gameObject); internally...

Should I explicitly call DOPlayById() instead to play specific animation?
It might be handy to have something like

if (!string.IsNullOrEmpty(id))
{
  DOTween.Play(this.gameObject, id);
}
else
{
  DOTween.Play(this.gameObject);
}

in the DOPlay() to handle it automatically, or DOPlay works as expected now?

*

focus

  • ***
  • 26
    • View Profile
    • blog
Re: DOTween Pro code-related questions
« Reply #8 on: November 25, 2015, 01:54:34 PM »
And one more silly question from me: is it possible somehow to know the DOTweenAnimation's tween was created?
I've noticed it may be created in Awake or even Start phases, and I'm trying to get the Animation's tween as early as possible, currently using small delay to make sure it's created.
Would be nice to be able to get some callback at the CreateTween() method completion ^^

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: DOTween Pro code-related questions
« Reply #9 on: November 25, 2015, 02:13:22 PM »
DOPlay doesn't accept an ID to conform to both DOTweenPath and DOTweenAnimation behaviors, so I'm afraid you'll have to call DOPlayById :P

About knowing when a tween is created you're right, I will add an OnTweenCreated callback. But can I ask you the favor of reminding me next week? I am stumped with two overlapped clients job this week and I have no time to do anything :B In the meantime, unless you're using a RectTransform as a target for a DOMove (not as the target to move, but as the target to move to) the tween will always be created inside Awake.

*

focus

  • ***
  • 26
    • View Profile
    • blog
Re: DOTween Pro code-related questions
« Reply #10 on: November 25, 2015, 04:18:33 PM »
Just found you have the public field tween for the DOTweenAnimation!
Lol, it's what I've searched for, I can control that tween explicitly to start, pause and add OnComplete for the specific DOTweenAnimation!

Or I'm missing something here? %)

OnTweenCreated callback would be really nice to have, I'll try to not forget to remind you about it next week! =D
Moved initialisation to the Start phase so far (which is fine for me anyways for now).

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: DOTween Pro code-related questions
« Reply #11 on: November 26, 2015, 11:14:09 AM »
Ah! You sure can use the tween variable directly. I always forget to mention that :D

*

focus

  • ***
  • 26
    • View Profile
    • blog
Re: DOTween Pro code-related questions
« Reply #12 on: December 02, 2015, 12:48:29 PM »
Pew pew, just a reminder about OnTweenCreated callback! ^^

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: DOTween Pro code-related questions
« Reply #13 on: December 02, 2015, 05:26:20 PM »
You mean this thing? :)

*

focus

  • ***
  • 26
    • View Profile
    • blog
Re: DOTween Pro code-related questions
« Reply #14 on: December 02, 2015, 05:29:00 PM »
Haha, you're quick, as always! Thanks!!