*

par

  • ***
  • 9
    • View Profile
New to DOTween, was lured in by all the good reviews.  This means I am retrofitting my code from my current tween engine to DOTween.

I lean towards coding rather than using the Unity GUI for doing anything, this way I can have complete control of whats going on.

  • Is there an API doc listing all of your packages, classes, public types, functions, attributes, etc?
  • What is the relationship between a tween and a GameObject?  I see a tween.target method but it returns an "Object".... is this a GameObject or a Transform or... ?
  • How do I get the GameObject (or Transform) that a tween is associated with?
  • How do I get the tween from the Transform (or GameObject) that I know had a tween associated with it?

There are many reasons why one would want this info.  One simple example is GameObject reuse.  If I have a list of GameObjects that go obsolete at the end of an animation (tween), I don't necessarily want that GameObject to be destroyed, I want to reuse it (or perhaps I really do want that destroyed.. all depends on the situation).  That means it would be nice to know all of the relationships between your framework and Unity's as depending on the use case, I might have a list of tweens that I set off or I might have a list of GameObjects/Transforms that I want to manage.

Thanks much!

PAR

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: DOTween API Doc and Relationships between Tween and GameObject/Transform
« Reply #1 on: December 15, 2015, 11:54:09 AM »
Hi!

  • There's the official docs, which include all the public API. If you're asking if there's a more "classic" version of it, then no. The reason is that DOTween uses a lot of internal extension methods, and API doc generators just create a mess with those
  • None. The target of a tween is simply the thing from which you call the DO(Move/Color/Whatever). So in case of an Image.DOColor, the target is the image, while in case of a transform.DOMove the target is the transform. The target is NEVER a gameObject (unless you're using DOTween Pro Animations, in which case the target is actually set as the gameObject for convenience), simply because it has no animatable properties. Also, consider that if you create an animation with the generic way, so without the DO shortcuts, the target will be NULL. Internally, the target has no use other than an ID to determine how many tweens are running on the same target.
  • myTween.target gets the aforementioned target, which will be a transform in case of DOMove etc, but otherwise a tween has no idea of gameObjects or transforms, because tweens are not tied only to gameObjects: you can tween every property you want.
  • DOTween.TweensByTarget returns a list of all tweens with the given target

Most important, tweens are not related to gameObjects at all. DOTween is a separate engine that animates what you tell it, which can be a transform but also a float on a class that has nothing to do with Unity.

Cheers,
Daniele

*

par

  • ***
  • 9
    • View Profile
Re: DOTween API Doc and Relationships between Tween and GameObject/Transform
« Reply #2 on: December 15, 2015, 03:49:55 PM »
Thanks much for the fast reply!

1) Ok, ya I read your official docs and, while they cover the basics it would be nice to have a full API reference.  And I ask this as a purchaser of the Pro version, I would never expect it w/out paying :P
2/3) So you're saying that whatever is used in your shortcut methods, the tween's target is always that object?  So is the following accurate?
  • Tween one = transform.DoMove();  -> one.target = (UnityEngine.Transform)transform?
  • Tween two = image.DOColor(); -> two.target = (UnityEngine.UI.Image)image?
If this is the case I can appreciate it.  The safe thing to do during a production application would be to check the type on these before using them but if you have hundreds of them per frame, the check will be a performance hit.
4) Tween one = transform.DoMove(); List<Tween> onesTweens = DOTween.TweensByTarget(one.target)?
If the list is long, how do I check which tween is which in a performant way?  A shortcut would be an id or enum that I could place on the tween and just check equality but if I dont have that what would be your suggested way?

I usually always keep references to things so I can avoid the performance hit of doing searches (i.e. I never do GameObject.GetComponent<Whatever Component> as that is a performance hit).  But there are definitely times I will need to check what is what.

Thanks again!

PAR

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: DOTween API Doc and Relationships between Tween and GameObject/Transform
« Reply #3 on: December 15, 2015, 04:42:51 PM »
Ahoy! :)

1) The official docs are the full API reference. They were a pain to create and a pain to maintain, since they require a lot of manual work, but it's the only way. API generators simply don't work with DOTween's architecture (which is pretty weird in order to boost performance), so a classic API reference is just not possible. I created it initially (you can see it here), but then I realized it's unreadable so stopped updating it and removed the link from the website.

2/3) Yes, definitely accurate

4) You can indeed add IDs to tweens (using SetId), so then you can get a list of tweens with the given ID (using TweensById) and use that instead. Or you can filter the "list by targets" by checking the tween.id that you set.

Alternately, note also that every static DOTween control method (like DOTween.Play/Pause/etc) accept a target or an ID if you want, so your operation will already be filtered.

Cheers!
Daniele

*

par

  • ***
  • 9
    • View Profile
Re: DOTween API Doc and Relationships between Tween and GameObject/Transform
« Reply #4 on: December 15, 2015, 04:57:10 PM »
Great!  Thanks much for your responses and I look forward to testing this all out!

And I looked at your API and yes, that would have been wonderful if it had worked.  Bummer you had so much trouble with it.

Cheers!

PAR
« Last Edit: December 15, 2015, 05:12:26 PM by par »