59 lines
1.4 KiB
C#
59 lines
1.4 KiB
C#
using UnityEngine;
|
|
using UnityEngine.Playables;
|
|
using UnityEngine.UI;
|
|
|
|
public class IntroCinematicsPlayer : MonoBehaviour
|
|
{
|
|
public bool ShouldPlayIntro;
|
|
private Image introRenderer;
|
|
private PlayableDirector director;
|
|
|
|
private Animator animation;
|
|
|
|
|
|
void OnEnable()
|
|
{
|
|
// Get the director and subscribe to when it stops playing
|
|
director = GetComponent<PlayableDirector>();
|
|
introRenderer = GetComponent<Image>();
|
|
director.stopped += OnPlayableDirectorStopped;
|
|
animation = GetComponent<Animator>();
|
|
}
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
//Play the intro and unhide the Canvas object if intro is enabled
|
|
if (ShouldPlayIntro)
|
|
{
|
|
introRenderer.enabled = true;
|
|
director.Play();
|
|
animation.enabled = true;
|
|
}
|
|
;
|
|
//Disable the intro Canvas object if intro is disabled
|
|
if (!ShouldPlayIntro)
|
|
{
|
|
director.Stop();
|
|
introRenderer.enabled = false;
|
|
animation.enabled = false;
|
|
|
|
|
|
}
|
|
;
|
|
|
|
|
|
|
|
}
|
|
void OnPlayableDirectorStopped(PlayableDirector aDirector)
|
|
{
|
|
// Disable the introsequence gameobject when intro is finished playing
|
|
introRenderer.enabled = false;
|
|
|
|
}
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
}
|