Demigiant Forum

Unity Assets => DOTween & DOTween Pro => Topic started by: focus on November 24, 2015, 06:51:04 PM

Title: DOTween Pro code-related questions
Post by: focus 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 =\
Title: Re: DOTween Pro code-related questions
Post by: Daniele 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 ;)
Title: Re: DOTween Pro code-related questions
Post by: focus 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?
Title: Re: DOTween Pro code-related questions
Post by: Daniele 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
Title: Re: DOTween Pro code-related questions
Post by: focus 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...
Title: Re: DOTween Pro code-related questions
Post by: Daniele on November 25, 2015, 10:17:33 AM
You could give the tween you want a univocal ID, and then use GetTweensById (http://dotween.demigiant.com/documentation.php?api=TweensById)
Code: [Select]
DOTween.GetTweensById(myUnivocalId)[0]...
Title: Re: DOTween Pro code-related questions
Post by: focus on November 25, 2015, 12:41:56 PM
Woohoo, that's it! Thank you, totally missed the id field in the inspector ^^
Title: Re: DOTween Pro code-related questions
Post by: focus 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?
Title: Re: DOTween Pro code-related questions
Post by: focus 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 ^^
Title: Re: DOTween Pro code-related questions
Post by: Daniele 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.
Title: Re: DOTween Pro code-related questions
Post by: focus 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).
Title: Re: DOTween Pro code-related questions
Post by: Daniele on November 26, 2015, 11:14:09 AM
Ah! You sure can use the tween variable directly. I always forget to mention that :D
Title: Re: DOTween Pro code-related questions
Post by: focus on December 02, 2015, 12:48:29 PM
Pew pew, just a reminder about OnTweenCreated callback! ^^
Title: Re: DOTween Pro code-related questions
Post by: Daniele on December 02, 2015, 05:26:20 PM
You mean this thing (http://forum.demigiant.com/index.php?topic=200.0)? :)
Title: Re: DOTween Pro code-related questions
Post by: focus on December 02, 2015, 05:29:00 PM
Haha, you're quick, as always! Thanks!!
Title: Re: DOTween Pro code-related questions
Post by: Daniele on December 02, 2015, 05:31:24 PM
P.S. About the "Mono.Cecil.AssemblyResolutionException UnityEngine.UI.dll" error you were finding, it will just have to be ignored for now. It is apparently a Unity bug (http://forum.unity3d.com/threads/5-2-1p3-mono-cecil-assemblyresolutionexception-unityengine-ui-dll.361666/) and I can't fix it, even if it causes no issues.
Title: Re: DOTween Pro code-related questions
Post by: focus on December 02, 2015, 05:32:55 PM
Ah, sorry for the false alarm then! Glad to know it's not on your side ^^
Title: Re: DOTween Pro code-related questions
Post by: cynicalwanderer on December 02, 2015, 05:46:59 PM
You mean this thing (http://forum.demigiant.com/index.php?topic=200.0)? :)

Awesome, this will be handy for something I need as well.