georgejecook / UnityTimelineEvents

Adds ability to execute arbitrary code, with int, bool, float, string and enum values, at both runtime and edit time, from Unity timelines.
276 stars 30 forks source link

How to pause and resume anims arranged by Timeline? #14

Open Jazz-mang opened 4 years ago

Jazz-mang commented 4 years ago

hello here, I made a individual pause Function using UGUI( i made it into a perfab), it works well in all projects except projects using timeline animations. I use timeline api for pause and resume, it can pause the graphs but when i trigger the proceed button, the next graphs( at the same clip) acts oddly, for example, in an explosion scene clip, some models should have been blown up and fallen down, but the fact is the models becomes relatively static and remain in the scene all the time, just like they are locked, untill the next timeline clip triggered, they are still there, the next timeline clip acts well.

the following code is what i made to realize pause and resume play functions, i have wasted a whole afternoon tring to fix it, but not solve it yet. is there any resolutions? Thanks for your help.

`private PlayableDirector[] Pd = null;

void Start() { Pd = Resources.FindObjectsOfTypeAll(typeof(PlayableDirector)) as PlayableDirector[]; }

void PauseButtonFunc() { if (currentVideoPlayer != null && currentVideoPlayer.isPlaying) {

            currentVideoPlayer.Pause();
        }
        AudioListener.pause = true;    

        if (Pd != null)
        {
            for (int i = 0; i < Pd.Length; i++)
            {
                if (Pd[i].isActiveAndEnabled)
                {
                    Pd[i].Pause();
                }
            }
        }

}

void ProceedButtonFunc() {
if (currentVideoPlayer!=null && !currentVideoPlayer.isPlaying) { currentVideoPlayer.Play(); } AudioListener.pause = false; Time.timeScale = 1;

        if (Pd != null)
        {
            for (int i = 0; i < Pd.Length; i++)
            {
                if (!Pd[i].isActiveAndEnabled)
                {
                    Pd[i].Play();
                }
            }
        }

}`

Jazz-mang commented 4 years ago

The unity-technology gave me a solution and my current problems were solved, but i still don't know how playabledirector.pause() and playabledirector.play() works. Are there bugs exited?