dotween icon indicating copy to clipboard operation
dotween copied to clipboard

Add support for Chronos

Open jangooni opened this issue 11 years ago • 23 comments

Could you add support for Chronos? http://forum.unity3d.com/threads/released-chronos-time-control.317688/ http://ludiq.io/chronos/tutorial

thanks for a great product!

jangooni avatar May 19 '15 01:05 jangooni

Chronos looks very very nice, but from a quick glance it seems it can't really be setup via code, but only via drag & drop. Am I wrong?

Also, what type of support you had in mind? DOTween already has its own timeScale (both Unity-dependent and Unity-independent), and each tween has a specific additional timeScale you can act upon.

Demigiant avatar May 19 '15 08:05 Demigiant

Hi Daniele,

Chronos runs on it's own Global time scale which can be set for specific enemy types, level areas, GUI, or player. IE time can slow down for enemies that get hit by a time grenade. It'd be nice to have support for this in DOTween. I think the easiest way to add support for this would be to allow the user to pass in a time object. I haven't looked at the Github code, but maybe I'll do that tonight and let you know.

Thanks for a great control!

On Tue, May 19, 2015 at 3:39 AM, Daniele Giardini [email protected] wrote:

Chronos looks very very nice, but from a quick glance it seems it can't really be setup via code, but only via drag & drop. Am I wrong?

Also, what type of support you had in mind? DOTween already has its own timeScale (both Unity-dependent and Unity-independent), and each tween has a specific additional timeScale you can act upon.

— Reply to this email directly or view it on GitHub https://github.com/Demigiant/dotween/issues/19#issuecomment-103400185.

jangooni avatar May 20 '15 02:05 jangooni

Hi!

Did you check how it could be done, by any chance? I know nothing of Chronos right now. Maybe if you could show me how it could be integrated, even with stub code so I can just understand the logic, I might see if it can be done.

Cheers!

Demigiant avatar May 24 '15 10:05 Demigiant

Hi Daniele,

Sorry for the delay, I haven't had a chance to implement it yet. I'll let you know as soon as I do.

-Jon

On Sun, May 24, 2015 at 5:25 AM, Daniele Giardini [email protected] wrote:

Hi!

Did you check how it could be done, by any chance? I know nothing of Chronos right now. Maybe if you could show me how it could be integrated, even with stub code so I can just understand the logic, I might see if it can be done.

Cheers!

— Reply to this email directly or view it on GitHub https://github.com/Demigiant/dotween/issues/19#issuecomment-104998780.

jangooni avatar May 27 '15 14:05 jangooni

Hey, got redirected here from Unity Forum ;) Chronos aside, I would like to be able to provide own timer implementation and inject it to DOTween. I assume DOTween uses Unity's Time class but I want (for example) to be able to pass a timer object associated with specific GameObject. So say transform.DOMoveX(1, 1, _timer) where _timer is abstract thing that DOTween uses to measure elapsed time.

slimshader avatar Jul 02 '15 21:07 slimshader

Hey,

I don't know if it can help with what you have in mind, but DOTween has its own timeScale (which is multiplied by Unity's), plus every single tween has a separate one (multiplied by DOTween's timeScale and Unity's).

Demigiant avatar Jul 02 '15 21:07 Demigiant

Since passing of time in custom timer may vary in speed through since tween it might be very difficult to workaround by constantly changing each tween's timeScale (especially if I still want to keep tween's timeScale wrt to its timer). If DOTween had abstracted Timer (with default implementation of Unity's Time) it would be ideal.

slimshader avatar Jul 02 '15 22:07 slimshader

Then the static DOTween.timeScale should be good, if I understood correctly :)

Demigiant avatar Jul 02 '15 22:07 Demigiant

Static timeScale should be useful for per GameObject timers running at different speeds and with those speed changing at different rates (non linear ways)? How...?

slimshader avatar Jul 02 '15 22:07 slimshader

Please take a look ad Chronos demo video (tho mind that it does not matter that it is Chronos, just that time is controller in various ways):

https://www.youtube.com/watch?v=-zq1OZuGXoc

Now say I want my tweens inside Area Control (1:11 min) to go backward in time (rewind). In such case timer.elapsedTime should produce negative values and tweens should just still scale it by own timeScale. What do you think?

slimshader avatar Jul 03 '15 13:07 slimshader

Hey sorry for the late reply. My computer is dying (which happens when you use a 7 years old laptop :P) and I'm kind of stumped while waiting for a new one. I'm writing to Chronos' author in the meantime to see if he has any suggestions. Please ping me back around Thursday, if I still haven't come out with some info.

Demigiant avatar Jul 11 '15 18:07 Demigiant

Chronos author here, hello!

I'll talk with Demigiant in PM to see if we can enable a Chronos integration in DOTween. :)

lazlo-bonin avatar Jul 11 '15 18:07 lazlo-bonin

Fantastic news :)

slimshader avatar Jul 11 '15 18:07 slimshader

Took a while, but I finally made some tests.

DOTween works with negative timeScales (meaning it plays backwards instead of forwards), so that part is good. To attach a tween to a Chronos timeline, Lazlo suggested to use an update routine, so this should work:

myTween.OnUpdate(()=> myTween.timeScale = myChronosTimeline.timeScale);

I don't have Chronos, so if some user is interested and can check this out it would be great :)

Demigiant avatar Aug 06 '15 14:08 Demigiant

If you want to make this an extension method and easily use it with Chronos, you could write:

using Chronos;

public static class MyExtensions
{
    public static void RegisterTimeline(this Tween tween, Timeline timeline)
    {
        tween.OnUpdate(()=> tween.timeScale = timeline.timeScale);
    }
}

Then, when you need to register it on a tween, simply call:

myTween.RegisterTimeline(myTimeline);

lazlo-bonin avatar Aug 09 '15 20:08 lazlo-bonin

Thanks for the tip Mr Chronos :)

A note to users: Lazlo's extension method is definitely the way to go, but you'll have to create it yourself in your project. I prefer not to implement it as an official extension method (for now), both because it hides the fact that users wouldn't be able to use OnUpdate for custom methods, and because I would have to add it as an external unpackable file (which would be unpacked by DOTween's Setup in case Chronos is present).

That said, it's not a definitive choice, and I'll ponder more about it. Lazlo, in case I choose to implement it, what file-system way could I use to determine if Chronos is present? Is there some special file which is named ChronosMasterOfTheUniverse or something like that, whose existence I can query to determine Chronos availability?

Demigiant avatar Aug 09 '15 23:08 Demigiant

You should be able to look for Timekeeper.cs, which is kind of like ChronosMasterOfTheUniverse (maybe I should've chosen that name instead). It's located by default under Chronos/Source/Timekeeper.cs, but for future-proofing, maybe you shouldn't look for the exact path. I think it's unlikely other projects or plugins would use the Timekeeper name.

That being said, I'm not sure how you can integrate it even with that check. The code wouldn't compile without Chronos because of the Timeline reference, and I can't provide a preprocessor check (e.g. #define CHRONOS, because that's a file-scope only, or /define CHRONOS, because Unity projects are auto-generated). If you have some voodoo for that, I'd be curious to learn it (especially for making PlayMaker specific code only compile if necessary).

lazlo-bonin avatar Aug 10 '15 05:08 lazlo-bonin

Thanks for the info Lazlo. And I have voodoo! I have! But it's so simple it's called boodoo!

With DOTween, depending how I implement extra-plugins features, I either add an extension methods class file with an "addon" file extension, and rename that to "cs" in case I find the required plugin, or I simply write conditionals and add Unity defines automatically.

Demigiant avatar Aug 12 '15 23:08 Demigiant

@demigiant & @lazlo-bonin Tl;Dr +1 Just wanted to say it's great you guys got your heads together on this. I use DOTween and own-pending-integration Chronos. Very happy to hear this will be one fewer thing to worry about :)

Arakade avatar Sep 20 '15 11:09 Arakade

Sorry to necropost but for anyone looking to quickly use Dotween Pro with Chronos here's what I did to add support.

make the extension method as mentioned above by lazlo-bonin here

all changes in DotweenAnimation.cs

//at the top of script
using Chronos;  

//add these variables
        public bool useChronosTimescale = false;
        public Timeline myTimeline;

// find this line
//       tween.SetUpdate(isIndependentUpdate);
//and add this below it.
         if (useChronosTimescale)
         tween.RegisterTimeline(myTimeline);

then in DotweenAnimationEditor.cs:

// add to top
using Chronos;

//under this line 
//_src.isIndependentUpdate = EditorGUILayout.Toggle("Ignore TimeScale", _src.isIndependentUpdate);
//add this:
         if (_src.isIndependentUpdate)
         {
         src.useChronosTimescale = EditorGUILayout.Toggle("Use Chronos TimesScale", _src.useChronosTimescale);
         if (_src.useChronosTimescale)
         _src.myTimeline = EditorGUILayout.ObjectField(_src.myTimeline, typeof(Timeline), true) as Timeline;  //(_src.endValueTransform, typeof(Transform), true) as Transform
         }

So now, if you set the bool Ignore Timescale in the editor a second bool will show to use Chronos or not. Drag and drop in your Timeline component and Enjoy!

christougher avatar Jan 31 '19 23:01 christougher