Files
Main/Assets/GameAssets/Resources/GameUI/Common/Utils/UIVideoPlayUtils.cs
2025-01-25 04:38:09 +08:00

87 lines
2.9 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Thousandto.Plugins.Common
{
/// <summary>
/// UI视频Utils
/// </summary>
public class UIVideoPlayUtils
{
#region//static
private static VideoRootScript script = null;
#endregion
#region//属性
public static VideoRootScript Script
{
get
{
if (script == null)
{
var go = GameObject.Find("[VideoRoot]");
if (go)
{
script = go.GetComponent<VideoRootScript>();
}
else
{
//创建videoRoot
var asset = Resources.Load("Default/System/VideoRoot");
var videoRoot = GameObject.Instantiate(asset) as GameObject;
videoRoot.name = "[VideoRoot]";
if (videoRoot != null)
{
GameObject.DontDestroyOnLoad(videoRoot);
script = videoRoot.GetComponent<VideoRootScript>();
if (script == null)
{
script = videoRoot.AddComponent<VideoRootScript>();
}
}
}
}
return script;
}
}
#endregion
#region//static方法
//准备视频
public static void PreVideo(string name, VideoRootScript.OnPreparedCall preparedCallBack = null, VideoRootScript.OnFinishCall finishCall = null, bool isShowMask = false, bool isLoop = false, VideoPlayExt extType = VideoPlayExt.Mp4)
{
if (Script != null)
Script.PrepareVideo(name, preparedCallBack, finishCall, isShowMask, isLoop, extType);
}
//播放视频
public static void PlayVideo(string name, VideoRootScript.OnPreparedCall preparedCallBack = null, VideoRootScript.OnFinishCall finishCall = null, bool isShowMask = false, bool isLoop = false, VideoPlayExt extType = VideoPlayExt.Mp4)
{
if(Script != null)
Script.Play(name, preparedCallBack, finishCall, isShowMask, isLoop, extType);
}
//停止视频播放
public static void StopVideo()
{
if(Script != null)
Script.StopVideo();
}
//判断是否正在播放视频
public static bool IsPlaying()
{
if(Script != null)
return Script.IsPlaying();
return false;
}
//设置视频depth
public static void SetDepth(float d)
{
if(Script != null)
Script.SetCamraDepth(d);
}
#endregion
}
}