Adventure Creator Wikia
Advertisement

The following custom Action (Third Party: Cinema Director) allows for the playback handling of Cinema Director sequences:

ActionCinemaDirector.cs:

using UnityEngine;
using System.Collections.Generic;

#if UNITY_EDITOR
using UnityEditor;
#endif

namespace AC
{
	
	[System.Serializable]
	public class ActionCinemaDirector : Action
	{

		public bool disableCamera;
		public int constantID = 0;
		public int parameterID = -1;
		public CinemaDirector.Cutscene cdCutscene;


		public override ActionCategory Category { get { return ActionCategory.ThirdParty; }}
		public override string Title { get { return "Cinema Director"; }}
		public override string Description { get { return "Runs a Cutscene built with Cinema Director. Note that Cinema Director is a separate Unity Asset, and the 'CinemaDirectorIsPresent' preprocessor must be defined for this to work."; }}


		public override void AssignValues (List<ActionParameter> parameters)
		{
			cdCutscene = AssignFile <CinemaDirector.Cutscene> (parameters, parameterID, constantID, cdCutscene);
		}
		
		
		public override float Run ()
		{
			if (!isRunning)
			{
				if (cdCutscene != null)
				{
					isRunning = true;
					cdCutscene.Play ();

					if (disableCamera)
					{
						KickStarter.mainCamera.Disable ();
					}

					if (willWait)
					{
						return cdCutscene.Duration;
					}
				}
			}
			else
			{
				if (disableCamera)
				{
					KickStarter.mainCamera.Enable ();
				}

				isRunning = false;
			}

			return 0f;
		}


		public override void Skip ()
		{
			if (cdCutscene)
			{
				if (disableCamera)
				{
					KickStarter.mainCamera.Enable ();
				}

				cdCutscene.Skip ();
				if (!cdCutscene.IsSkippable)
				{
					ACDebug.LogWarning ("Cannot skip Cinema Director cutscene " + cdCutscene.name, cdCutscene);
				}
			}
		}
		
		
		#if UNITY_EDITOR
		
		public override void ShowGUI (List<ActionParameter> parameters)
		{
			parameterID = Action.ChooseParameterGUI ("Director cutscene:", parameters, parameterID, ParameterType.GameObject);
			if (parameterID >= 0)
			{
				constantID = 0;
				cdCutscene = null;
			}
			else
			{
				cdCutscene = (CinemaDirector.Cutscene) EditorGUILayout.ObjectField ("Director cutscene:", cdCutscene, typeof (CinemaDirector.Cutscene), true);
				
				constantID = FieldToID <CinemaDirector.Cutscene> (cdCutscene, constantID);
				cdCutscene = IDToField <CinemaDirector.Cutscene> (cdCutscene, constantID, false);
			}

			disableCamera = EditorGUILayout.Toggle ("Override AC camera?", disableCamera);
			willWait = EditorGUILayout.Toggle ("Wait until finish?", willWait);
		}


		public override void AssignConstantIDs (bool saveScriptsToo, bool fromAssetFile)
		{
			constantID = AssignConstantID <CinemaDirector.Cutscene> (cdCutscene, constantID, parameterID);
		}


		public override string SetLabel ()
		{
			if (cdCutscene != null)
			{
				return cdCutscene.gameObject.name;
			}
			return string.Empty;
		}


		public override bool ReferencesObjectOrID (GameObject _gameObject, int id)
		{
			if (parameterID < 0)
			{
				if (cdCutscene && cdCutscene.gameObject == _gameObject) return true;
				if (constantID == id) return true;
			}
			return base.ReferencesObjectOrID (_gameObject, id);
		}

		#endif


		public static ActionCinemaDirector CreateNew_ResumeLastTrack (CinemaDirector.Cutscene cutsceneToPlay, bool waitUntilFinish = true)
		{
			ActionCinemaDirector newAction = CreateNew<ActionCinemaDirector> ();
			newAction.cdCutscene = cutsceneToPlay;
			newAction.TryAssignConstantID (newAction.cdCutscene, ref newAction.constantID);
			newAction.willWait = waitUntilFinish;
		}

	}
	
}
Advertisement