I've added Timeline play event to my project. It's still W.I.P but I thought others might find it useful.
image

You should be able to Play, Pause, Resume, Restart or Stop timeline.
The wait until finished function I only tested with timelines that don't wrap or hold timeline.
I will likely add animation track binding options. (I'll post an update);

You need to create new C# script by right clicking in project window and clicking "Create/C# Script
", then name it PlayTimelineStep and copy this code inside the file replacing the unity generated code.

You should be able to create this new event step with "Animation + Audio/Animation/Play Timeline Director", and well, just supply the object that has timeline director on it.

(My project is on 2017 unity so I don't have timeline stop event hooks they added in 2018 version of timeline. )

Word of warning! DO SAVE YOUR SCENE AND PROJECT BEFORE RUNNING THE GAME WITH THIS EVENT.
Sometimes unity would lock up as I was testing it, and well I had to close Unity from task manager. (This should be fixed now, but just in case)

using UnityEngine;
using ORKFramework;
using ORKFramework.Menu;
using ORKFramework.Reflection;
using ORKFramework.Behaviours;
using System.Collections.Generic;
namespace ORKFramework.Events.Steps
{
public enum TIMELINEPLAYENUM { Play, Resume, Pause, Stop, Restart}
[ORKEditorHelp("Play Timeline Director", "Perform Timeline Director Playback Operation", "")]
[ORKEventStep(typeof(BaseEvent))]
[ORKNodeInfo("Animation + Audio/Animation")]
public class PlayTimelineStep : BaseEventStep
{
[ORKEditorInfo(labelText = "Timeline Operation")]
public TIMELINEPLAYENUM TimeplayOperation;
// moving object
[ORKEditorInfo(labelText = "Timeline Director Object")]
public EventObjectSetting TimelineObject = new EventObjectSetting();
[ORKEditorInfo(labelText = "Wait until Timeline Director animation has finished")]
public bool WaitUntilFinished;

private List<GameObject> TimelineObjects;


public PlayTimelineStep()
{

}
UnityEngine.Playables.PlayableDirector TimelineDirector;
public override void Execute(BaseEvent baseEvent)
{
this.TimelineObjects = this.TimelineObject.GetObject(baseEvent);

if (this.TimelineObjects.Count > 0)
{
TimelineDirector = TimelineObjects[0].GetComponent<UnityEngine.Playables.PlayableDirector>();
if (TimelineDirector != null)
{
switch (TimeplayOperation)
{
case TIMELINEPLAYENUM.Play:
if (WaitUntilFinished)
{
TimelineDirector.Play();
this.Continue(baseEvent);
}
else
{
TimelineDirector.Play();
Clear(baseEvent);
}
break;
case TIMELINEPLAYENUM.Resume:
if (WaitUntilFinished)
{
TimelineDirector.Resume();
this.Continue(baseEvent);
}
else
{
TimelineDirector.Resume();
Clear(baseEvent);
}
break;
case TIMELINEPLAYENUM.Restart:
if (WaitUntilFinished)
{
TimelineDirector.time = 0;
TimelineDirector.Play();
this.Continue(baseEvent);
}
else
{
TimelineDirector.Play();
Clear(baseEvent);
}
break;
case TIMELINEPLAYENUM.Pause:
TimelineDirector.Pause();
Clear(baseEvent);
break;
case TIMELINEPLAYENUM.Stop:
TimelineDirector.Stop();
Clear(baseEvent);
break;
default:
break;
}

}
else
{
Debug.LogError("Play Timeline Director Event Step: Supplied Timeline GameObject Does Not Have Timeline Director Component On It");
Clear(baseEvent);
}
}
else
{
Debug.LogError("Play Timeline Director Event Step: Could not find supplied Timeline GameObject");
Clear(baseEvent);
}
}

public override void Continue(BaseEvent baseEvent)
{
if (TimelineDirector.state != UnityEngine.Playables.PlayState.Playing)
{
Clear(baseEvent);
}
else
{
baseEvent.StartContinue(Time.deltaTime+ Time.deltaTime, this);
}
}


void Clear(BaseEvent baseEvent)
{
this.TimelineObjects = null;
baseEvent.StepFinished(this.next);
}
/*
============================================================================
Node name functions
============================================================================
*/
public override string GetNodeDetails()
{
return "Play timeline animation";
}
}
}
Post edited by hellwalker on
  • Good job :)
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Sign In or Register to comment.