Stratasys-450mc-VR/Assets/Scripts/Managers/VideoManager.cs
2023-11-01 10:51:29 -04:00

56 lines
1.5 KiB
C#
Executable File

using SO;
using SO.Channels;
using UnityEngine;
using UnityEngine.Video;
namespace Managers
{
public class VideoManager : MonoBehaviour
{
[SerializeField] private VideoPlayer videoPlayer;
[SerializeField] private StepChangeChannelSO stepChangeChannel;
[SerializeField] private SimpleChannelSO playChannel;
[SerializeField] private SimpleChannelSO stopChannel;
[SerializeField] private SimpleChannelSO videoChannel;
private void OnEnable()
{
stepChangeChannel.OnStepChanged += OnStepChanged;
playChannel.OnEventRaised += Play;
stopChannel.OnEventRaised += Stop;
videoChannel.OnEventRaised += VideoPanelEnabled;
}
private void OnDisable()
{
stepChangeChannel.OnStepChanged -= OnStepChanged;
playChannel.OnEventRaised -= Play;
stopChannel.OnEventRaised -= Stop;
videoChannel.OnEventRaised -= VideoPanelEnabled;
}
private void OnStepChanged(StepSO step)
{
videoPlayer.clip = step.Video;
videoPlayer.Play();
}
private void VideoPanelEnabled()
{
Play();
}
private void Play()
{
Stop();
videoPlayer.Play();
}
private void Stop()
{
videoPlayer.Stop();
videoPlayer.frame = 0;
}
}
}