Demigiant / dotween

A Unity C# animation engine. HOTween v2
http://dotween.demigiant.com
Other
2.29k stars 344 forks source link

Add support for Chronos #19

Open jangooni opened 9 years ago

jangooni commented 9 years ago

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!

Demigiant commented 9 years ago

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.

jangooni commented 9 years ago

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 notifications@github.com 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.

Demigiant commented 9 years ago

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!

jangooni commented 9 years ago

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 notifications@github.com 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.

slimshader commented 9 years ago

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.

Demigiant commented 9 years ago

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).

slimshader commented 9 years ago

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.

Demigiant commented 9 years ago

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

slimshader commented 9 years ago

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 commented 9 years ago

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?

Demigiant commented 8 years ago

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.

lazlo-bonin commented 8 years ago

Chronos author here, hello!

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

slimshader commented 8 years ago

Fantastic news :)

Demigiant commented 8 years ago

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 :)

lazlo-bonin commented 8 years ago

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);
Demigiant commented 8 years ago

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?

lazlo-bonin commented 8 years ago

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).

Demigiant commented 8 years ago

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.

Arakade commented 8 years ago

@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 :)

christougher commented 5 years ago

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!

tchrisbaker commented 3 years ago

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 :)

this worked great thanks

DanTulovsky commented 2 years ago

This seems to work, except if I pause, and then try to resume, the tween doesn't resume. Does anyone have pausing (set timeScale to 0) working?

Pixanto commented 2 years ago

I'm having the same problem