2025-09-09 13:11:18 +02:00
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.Playables;
|
2025-09-10 09:10:58 +02:00
|
|
|
using UnityEngine.Serialization;
|
2025-09-09 14:22:05 +02:00
|
|
|
using UnityEngine.UI;
|
2025-09-09 13:11:18 +02:00
|
|
|
|
|
|
|
|
public class IntroCinematicsPlayer : MonoBehaviour
|
|
|
|
|
{
|
2025-09-10 09:10:58 +02:00
|
|
|
[FormerlySerializedAs("ShouldPlayIntro")] public bool shouldPlayIntro;
|
|
|
|
|
private Image _introRenderer;
|
|
|
|
|
private PlayableDirector _director;
|
2025-09-09 13:11:18 +02:00
|
|
|
|
2025-09-10 09:10:58 +02:00
|
|
|
private Animator _animatorComponent;
|
2025-09-09 14:22:05 +02:00
|
|
|
|
2025-09-09 13:11:18 +02:00
|
|
|
|
|
|
|
|
void OnEnable()
|
|
|
|
|
{
|
|
|
|
|
// Get the director and subscribe to when it stops playing
|
2025-09-10 09:10:58 +02:00
|
|
|
_director = GetComponent<PlayableDirector>();
|
|
|
|
|
_introRenderer = GetComponent<Image>();
|
|
|
|
|
_director.stopped += OnPlayableDirectorStopped;
|
|
|
|
|
_animatorComponent = GetComponent<Animator>();
|
2025-09-09 13:11:18 +02:00
|
|
|
}
|
|
|
|
|
// 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
|
2025-09-10 09:10:58 +02:00
|
|
|
if (shouldPlayIntro)
|
2025-09-09 13:11:18 +02:00
|
|
|
{
|
2025-09-10 09:10:58 +02:00
|
|
|
_introRenderer.enabled = true;
|
|
|
|
|
_director.Play();
|
|
|
|
|
_animatorComponent.enabled = true;
|
2025-09-09 13:11:18 +02:00
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
//Disable the intro Canvas object if intro is disabled
|
2025-09-10 09:10:58 +02:00
|
|
|
if (!shouldPlayIntro)
|
2025-09-09 13:11:18 +02:00
|
|
|
{
|
2025-09-10 09:10:58 +02:00
|
|
|
_director.Stop();
|
|
|
|
|
_introRenderer.enabled = false;
|
|
|
|
|
_animatorComponent.enabled = false;
|
2025-09-09 14:22:05 +02:00
|
|
|
|
2025-09-09 13:11:18 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
void OnPlayableDirectorStopped(PlayableDirector aDirector)
|
|
|
|
|
{
|
|
|
|
|
// Disable the introsequence gameobject when intro is finished playing
|
2025-09-10 09:10:58 +02:00
|
|
|
_introRenderer.enabled = false;
|
2025-09-09 13:11:18 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|