Files
JJBB/Assets/Project/Script/GUI/Marry/MarryMovieCtr.cs

131 lines
3.5 KiB
C#
Raw Normal View History

2024-08-23 15:49:34 +08:00
using Games.Events;
using Games.Scene;
using UnityEngine;
using UnityEngine.Video;
public class MarryMovieCtr : MonoBehaviour
{
private const string _MovieURL = "/Audio/2222.mp4";
public static MarryMovieCtr Instance;
public Camera _MovieCamera;
public VideoPlayer _VideoPlayer;
private int _CurApplicationFrameRate;
private bool _IsPlayMovie;
public void Awake()
{
Instance = this;
_VideoPlayer.loopPointReached += OnReachloopPoint;
_VideoPlayer.started += OnVedioStart;
_VideoPlayer.prepareCompleted += OnPrepare;
_VideoPlayer.errorReceived += OnErrorHandle;
// var moviePath = UpdateHelper.GetLocalPathRoot() + _MovieURL;
// #if UNITY_EDITOR
// moviePath = Application.dataPath + _MovieURL;
// #endif
_VideoPlayer.url = Application.streamingAssetsPath.Open(_MovieURL);
}
private void OnEnable()
{
_VideoPlayer.gameObject.SetActive(true);
_VideoPlayer.enabled = true;
_VideoPlayer.Prepare();
}
private void OnDisable()
{
BGMusicSetting(true);
EventDispatcher.Instance.Dispatch(EventId.SceneMovie, false);
}
private void OnDestroy()
{
Instance = null;
_VideoPlayer.loopPointReached -= OnReachloopPoint;
}
public void PlayMovie(string name)
{
gameObject.SetActive(true);
var moviePath
#if UNITY_EDITOR
= Application.dataPath + name;
#else
= Application.streamingAssetsPath + name;
#endif
#if !UNITY_EDITOR && (UNITY_IOS || UNITY_IPHONE)
moviePath = "file://" + moviePath;
#endif
_VideoPlayer.url = moviePath;
PlayMovie();
}
public void PlayMovie()
{
_CurApplicationFrameRate = Application.targetFrameRate;
Application.targetFrameRate = -1;
_IsPlayMovie = true;
_VideoPlayer.Play();
BGMusicSetting(false);
}
private void InitSetting()
{
if (_VideoPlayer.renderMode != VideoRenderMode.CameraNearPlane)
_VideoPlayer.renderMode = VideoRenderMode.CameraNearPlane;
if (_VideoPlayer.targetCamera == null)
{
if (SceneLogic.CameraController)
_VideoPlayer.targetCamera = _MovieCamera;
else
Debug.LogError("SceneLogic.CameraController is null");
}
}
public void OnReachloopPoint(VideoPlayer source)
{
Application.targetFrameRate = _CurApplicationFrameRate;
//关闭界面
UIManager.CloseUI(UIInfo.MarryMovieCtr);
}
public void OnVedioStart(VideoPlayer source)
{
if (_MovieCamera)
_MovieCamera.enabled = true;
InitSetting();
EventDispatcher.Instance.Dispatch(EventId.SceneMovie, true);
}
public void OnPrepare(VideoPlayer source)
{
//if (_MovieCamera)
// _MovieCamera.enabled = true;
//InitSetting();
//HideUICamera(true);
}
public void OnErrorHandle(VideoPlayer source, string message)
{
//HideUICamera(false);
//关闭界面
UIManager.CloseUI(UIInfo.MarryMovieCtr);
}
public void BGMusicSetting(bool isOn)
{
PlayerPreferenceData.SystemMusic.Set(isOn);
PlayerPreferenceData.SystemSoundEffect.Set(isOn);
if (GameManager.gameManager.ActiveScene != null)
GameManager.gameManager.ActiveScene.SetSceneSoundEffect(isOn);
if (HitTipLogic.Instance())
HitTipLogic.Instance().RefreshVolumn();
}
}