TheStable/Assets/AVProVideo/Runtime/Scripts/Components/MediaPlayer_EditorPlayPause.cs
Jamie Greunbaum ef9ccfef19 - Added trees outside the stable.
- Added a video player with horse songs preloaded.
- Adjusted post-processing to be less harsh outdoors, and more visible indoors.
2025-05-03 01:57:06 -04:00

83 lines
2.0 KiB
C#

using UnityEngine;
#if UNITY_EDITOR
//-----------------------------------------------------------------------------
// Copyright 2015-2022 RenderHeads Ltd. All rights reserved.
//-----------------------------------------------------------------------------
namespace RenderHeads.Media.AVProVideo
{
public partial class MediaPlayer : MonoBehaviour
{
#region Play/Pause Support for Unity Editor
// This code handles the pause/play buttons in the editor
private static void SetupEditorPlayPauseSupport()
{
#if UNITY_2017_2_OR_NEWER
UnityEditor.EditorApplication.pauseStateChanged -= OnUnityPauseModeChanged;
UnityEditor.EditorApplication.pauseStateChanged += OnUnityPauseModeChanged;
#else
UnityEditor.EditorApplication.playmodeStateChanged -= OnUnityPlayModeChanged;
UnityEditor.EditorApplication.playmodeStateChanged += OnUnityPlayModeChanged;
#endif
}
#if UNITY_2017_2_OR_NEWER
private static void OnUnityPauseModeChanged(UnityEditor.PauseState state)
{
OnUnityPlayModeChanged();
}
#endif
private static void OnUnityPlayModeChanged()
{
if (UnityEditor.EditorApplication.isPlaying)
{
bool isPaused = UnityEditor.EditorApplication.isPaused;
MediaPlayer[] players = Resources.FindObjectsOfTypeAll<MediaPlayer>();
foreach (MediaPlayer player in players)
{
if (isPaused)
{
player.EditorPause();
}
else
{
player.EditorUnpause();
}
}
}
}
private void EditorPause()
{
if (this.isActiveAndEnabled)
{
if (_controlInterface != null && _controlInterface.IsPlaying())
{
_wasPlayingOnPause = true;
_controlInterface.Pause();
}
StopRenderCoroutine();
}
}
private void EditorUnpause()
{
if (this.isActiveAndEnabled)
{
if (_controlInterface != null && _wasPlayingOnPause)
{
_autoPlayOnStart = true;
_wasPlayingOnPause = false;
_autoPlayOnStartTriggered = false;
}
StartRenderCoroutine();
}
}
#endregion // Play/Pause Support for Unity Editor
}
}
#endif