SLATE integration

The follow Action (Third Party: Slate), allows for the control of Slate cutscenes.

```
using System;
using System.Collections.Generic;
using UnityEngine;
#if UNITY\_EDITOR
using UnityEditor;
#endif

namespace AC
{

 [Serializable]
 public class ActionSLATE : Action
 {

 [SerializeField] private Slate.Cutscene slateCutscene;
 [SerializeField] private int constantID = 0;
 [SerializeField] private int parameterID = -1;
 private Slate.Cutscene runtimeSlateCutscene;

 [SerializeField] private float startTime;
 [SerializeField] private float endTime;
 [SerializeField] private Slate.Cutscene.WrapMode wrapMode = Slate.Cutscene.WrapMode.Once;
 [SerializeField] private Slate.Cutscene.PlayingDirection playDirection = Slate.Cutscene.PlayingDirection.Forwards;
 [SerializeField] private Slate.Cutscene.StopMode stopMode;
 [SerializeField] private string sectionName;
 [SerializeField] private bool alsoSkip;
 [SerializeField] private GameObject newActor;
 [SerializeField] private int newActorConstantID = 0;
 [SerializeField] private int newActorParameterID = -1;
 private GameObject runtimeNewActor;
 private bool isComplete;

 [SerializeField] private SlateMethod method = SlateMethod.Play;
 private enum SlateMethod { Play, PlayDetailed, PlaySection, PlayFromSection, Sample, Stop, Pause, Resume, Rewind, SkipAll, SkipCurrentSection, BreakSectionLoop, JumpToSection, SetGroupActorOfName };

 public override ActionCategory Category { get { return ActionCategory.ThirdParty; } }
 public override string Title { get { return "Slate"; } }
 public override string Description { get { return "Runs a Slate Cutscene"; } }

 public override void AssignValues (List<ActionParameter> parameters)
 {
 runtimeSlateCutscene = AssignFile (parameters, parameterID, constantID, slateCutscene);
 runtimeNewActor = AssignFile (parameters, newActorParameterID, newActorConstantID, newActor);
 }

 public override float Run ()
 {
 if (runtimeSlateCutscene == null)
 {
 return 0f;
 }

 if (!isRunning)
 {
 isComplete = false;

 switch (method)
 {
 case SlateMethod.Play:
 if (willWait)
 {
 if (UsesSlateCamera ())
 {
 KickStarter.mainCamera.Disable ();
 }
 runtimeSlateCutscene.Play (startTime, OnComplete);
 isRunning = true;
 return defaultPauseTime;
 }
 runtimeSlateCutscene.Play (startTime);
 return 0f;

 case SlateMethod.PlayDetailed:
 if (willWait)
 {
 if (UsesSlateCamera ())
 {
 KickStarter.mainCamera.Disable ();
 }
 runtimeSlateCutscene.Play (startTime, endTime, wrapMode, OnComplete, playDirection);
 isRunning = true;
 return defaultPauseTime;
 }
 runtimeSlateCutscene.Play (startTime, endTime, wrapMode, null, playDirection);
 return 0f;

 case SlateMethod.PlaySection:
 if (willWait)
 {
 if (UsesSlateCamera ())
 {
 KickStarter.mainCamera.Disable ();
 }
 runtimeSlateCutscene.PlaySection (sectionName, wrapMode, OnComplete);
 isRunning = true;
 return defaultPauseTime;
 }
 runtimeSlateCutscene.PlaySection (sectionName, wrapMode, null);
 return 0f;

 case SlateMethod.PlayFromSection:
 if (willWait)
 {
 if (UsesSlateCamera ())
 {
 KickStarter.mainCamera.Disable ();
 }
 runtimeSlateCutscene.PlayFromSection (sectionName, wrapMode, OnComplete);
 isRunning = true;
 return defaultPauseTime;
 }
 runtimeSlateCutscene.PlayFromSection (sectionName, wrapMode, null);
 return 0f;

 case SlateMethod.Sample:
 if (startTime >= 0f)
 {
 runtimeSlateCutscene.Sample (startTime);
 }
 else
 {
 runtimeSlateCutscene.Sample ();
 }
 return 0f;

 case SlateMethod.Stop:
 runtimeSlateCutscene.Stop (stopMode);
 return 0f;

 case SlateMethod.Pause:
 runtimeSlateCutscene.Pause ();
 return 0f;

 case SlateMethod.Resume:
 runtimeSlateCutscene.Resume ();
 return 0f;

 case SlateMethod.Rewind:
 runtimeSlateCutscene.Rewind ();
 return 0f;

 case SlateMethod.SkipAll:
 runtimeSlateCutscene.SkipAll ();
 return 0f;

 case SlateMethod.SkipCurrentSection:
 runtimeSlateCutscene.SkipCurrentSection ();
 return 0f;

 case SlateMethod.BreakSectionLoop:
 runtimeSlateCutscene.BreakSectionLoop ();
 return 0f;

 case SlateMethod.JumpToSection:
 runtimeSlateCutscene.JumpToSection (sectionName);
 return 0f;

 case SlateMethod.SetGroupActorOfName:
 runtimeSlateCutscene.SetGroupActorOfName (sectionName, runtimeNewActor);
 return 0f;

 default:
 return 0f;
 }
 }

 switch (method)
 {
 if (isComplete)
 {
 if (UsesSlateCamera ())
 {
 KickStarter.mainCamera.Enable ();
 }
 isRunning = false;
 return 0f;
 }
 return defaultPauseTime;

 default:
 isRunning = false;
 return 0f;
 }
 }

 private void OnComplete ()
 {
 isComplete = true;
 }

 public override void Skip ()
 {
 if (runtimeSlateCutscene == null)
 {
 return;
 }

 switch (method)
 {
 runtimeSlateCutscene.SkipAll ();
 if (willWait && UsesSlateCamera ())
 {
 KickStarter.mainCamera.Enable ();
 }
 break;

 case SlateMethod.PlaySection:
 runtimeSlateCutscene.PlaySection (sectionName);
 runtimeSlateCutscene.SkipCurrentSection ();
 if (willWait && UsesSlateCamera ())
 {
 KickStarter.mainCamera.Enable ();
 }
 break;

 default:
 Run ();
 break;
 }
 }

 private bool UsesSlateCamera ()
 {
 return runtimeSlateCutscene && runtimeSlateCutscene.cameraTrack && runtimeSlateCutscene.cameraTrack.isActive;
 }

 #if UNITY\_EDITOR
 override public void ShowGUI (List<ActionParameter> parameters)
 {
 parameterID = ChooseParameterGUI ("Slate Cutscene:", parameters, parameterID, ParameterType.GameObject);
 if (parameterID >= 0)
 {
 constantID = 0;
 slateCutscene = null;
 }
 else
 {
 slateCutscene = (Slate.Cutscene) EditorGUILayout.ObjectField ("Slate Cutscene:", slateCutscene, typeof (Slate.Cutscene), true);
 constantID = FieldToID (slateCutscene, constantID);
 slateCutscene = IDToField (slateCutscene, constantID, false);
 }

 method = (SlateMethod) EditorGUILayout.EnumPopup ("Method:", method);

 switch (method)
 {
 case SlateMethod.Play:
 startTime = EditorGUILayout.FloatField ("Start time:", startTime);
 break;

 case SlateMethod.PlayDetailed:
 startTime = EditorGUILayout.FloatField ("Start time:", startTime);
 endTime = EditorGUILayout.FloatField ("End time:", endTime);
 wrapMode = (Slate.Cutscene.WrapMode) EditorGUILayout.EnumPopup ("Wrap mode:", wrapMode);
 playDirection = (Slate.Cutscene.PlayingDirection) EditorGUILayout.EnumPopup ("Play direction:", playDirection);
 break;

 sectionName = EditorGUILayout.TextField ("Section name:", sectionName);
 wrapMode = (Slate.Cutscene.WrapMode) EditorGUILayout.EnumPopup ("Wrap mode:", wrapMode);
 break;

 case SlateMethod.Sample:
 startTime = EditorGUILayout.FloatField ("Time:", startTime);
 EditorGUILayout.HelpBox ("Set to negative to sample the current time", MessageType.Info);
 break;

 case SlateMethod.Stop:
 stopMode = (Slate.Cutscene.StopMode) EditorGUILayout.EnumPopup ("Stop mode:", stopMode);
 break;

 case SlateMethod.BreakSectionLoop:
 alsoSkip = EditorGUILayout.Toggle ("Also skip?", alsoSkip);
 break;

 case SlateMethod.JumpToSection:
 sectionName = EditorGUILayout.TextField ("Section name:", sectionName);
 break;

 case SlateMethod.SetGroupActorOfName:
 sectionName = EditorGUILayout.TextField ("Group name:", sectionName);
 newActorParameterID = ChooseParameterGUI ("Slate Cutscene:", parameters, newActorParameterID, ParameterType.GameObject);
 if (newActorParameterID >= 0)
 {
 newActor = null;
 newActorConstantID = 0;
 }
 else
 {
 newActor = (GameObject) EditorGUILayout.ObjectField ("New actor:", newActor, typeof (GameObject), true);
 newActorConstantID = FieldToID (newActor, newActorConstantID);
 newActor = IDToField (newActor, newActorConstantID, false);
 }
 break;

 default:
 break;
 }

 switch (method)
 {
 willWait = EditorGUILayout.Toggle ("Wait until finish?", willWait);
 break;

 default:
 break;
 }
 }

 public override void AssignConstantIDs (bool saveScriptsToo, bool fromAssetFile)
 {
 AssignConstantID (slateCutscene, constantID, parameterID);
 }

 #endif

 }
}

```