#if HAVE_SLATE
using System;
using UnityEngine;
using Slate;
using Framework.Input;
using Framework.Input.States;
using Framework.Services;
namespace Framework.Cinematics {
/// Pauses a cutscene when the space bar is pressed
public class CutscenePauseKeyListener : ScriptComponent {
///
/// Called once after the GameObject the script is attached to is created
///
protected void Start() {
this.cutscene = GetComponent();
if(this.cutscene == null) {
Debug.LogWarning(
"CutscenePauseKeyListener was added to '" + gameObject.name + "' which " +
"does not have a Slate 'Cutscene' component. Pausing won't work."
);
}
}
/// Provides the instance with services it depends on
/// Input manager by which the keys will be checked
protected virtual void Inject(IInputManager inputManager) {
this.inputManager = inputManager;
}
/// Called once per visual frame to update the input devices
protected virtual void Update() {
if((this.cutscene != null) && (this.inputManager != null)) {
CinematicInputState state = this.inputManager.GetState();
// Allow the cutscene to be skipped
if(state.Skip.WasTriggered) {
if(this.cutscene.isActive) {
if(this.cutscene.isPaused) {
this.cutscene.Resume();
} else {
this.cutscene.Pause();
}
}
}
}
}
/// Input manager that is used to check input device states
[NonSerialized]
private IInputManager inputManager;
/// Cutscene that can be skipped or paused by this script
[NonSerialized]
private Cutscene cutscene;
}
} // namespace Framework.Cinematics
#endif // HAVE_SLATE