Adventure Creator Wikia
Advertisement

This Action allows you to change the time a Timeline is currently at. To use it:

  1. Create a new C# file named ActionTimelineTime and place it in a unique folder, or existing custom Actions folder.
  2. Point to this folder from the Actions Manager's Custom Actions file browser
  3. The Action is now available to use as the "Custom: Set Timeline time" Action.


ActionTimelineTime.cs:

using UnityEngine;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine.Playables;


namespace AC
{

	[System.Serializable]
	public class ActionTimelineTime : Action
	{
		
		public override ActionCategory Category { get { return ActionCategory.Custom; }}
		public override string Title { get { return "Set Timeline time"; }}
		public override string Description { get { return "Sets a Timline's current time to a specific moment."; }}


		public PlayableDirector director;
		public int directorConstantID;
		protected PlayableDirector runtimeDirector;

		public float time;


		public override void AssignValues (List<ActionParameter> parameters)
		{
			runtimeDirector = AssignFile <PlayableDirector> (directorConstantID, director);
		}
		
		
		public override float Run ()
		{
			if (runtimeDirector)
			{
				runtimeDirector.time = time;
				runtimeDirector.Evaluate ();
			}
			return 0f;
		}


		public override void Skip ()
		{
			Run ();
		}

		
		#if UNITY_EDITOR

		public override void ShowGUI ()
		{
			director = (PlayableDirector) EditorGUILayout.ObjectField ("Director:", director, typeof (PlayableDirector), true);
			directorConstantID = FieldToID <PlayableDirector> (director, directorConstantID);
			director = IDToField <PlayableDirector> (director, directorConstantID, false);

			time = EditorGUILayout.FloatField ("New time (s):", time);
		}

		#endif
		
	}

}
Advertisement