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";
}
}
}
It looks like you're new here. If you want to get involved, click one of these buttons!
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!