目前先发布相关脚本代码,后续会对内容进行补充
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
namespace FrameWork
{
public interface IVideo
{
VideoPlayer GetVideoPlayer();
RawImage GetVideoImage();
void OnPlayVideo();
void OnPlayVideo(int index);
void OnPlayVideo(string url);
void OnPauseVideo();
void OnStopVideo();
void AddVideoUrl(string url);
void AddVideoUrls(string[] url);
void RemoveAllUrls();
void RemoveUrl(int index);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace FrameWork
{
public class VideoManager : FrameworkComponent
{
public override void Init()
{
sceneVideos = new Dictionary<string, IVideo>();
}
private Dictionary<string, IVideo> sceneVideos;
public void RegistMySelf_Video(string name, IVideo video)
{
if (sceneVideos == null)
return;
if (!sceneVideos.ContainsKey(name))
{
sceneVideos.Add(name, video);
}
else
{
Debug.Log("已添加video:" + name + " ,请检查是否重名");
}
}
public void UnRegistMySelf_Video(string name)
{
if (sceneVideos == null)
return;
if (sceneVideos.ContainsKey(name))
{
sceneVideos.Remove(name);
}
else
{
Debug.Log("未找到video:" + name);
}
}
public IVideo GetVideoComponent(string name)
{
if (sceneVideos.ContainsKey(name))
{
return sceneVideos[name];
}
Debug.Log("未找到IVideo:" + name);
return null;
}
}
}
接下来是核心代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Video;
using UnityEngine.UI;
namespace FrameWork
{
[RequireComponent(typeof(RawImage))]
public class VideoComponent : MonoBehaviour, IVideo
{
#region 内部变量
private VideoPlayer vPlayer//
;
private AudioSource source;//
private RawImage videoImage;//
private bool playOnPrepareCompleted = false;
private string videoUrlDefault;
private bool isInDrag = false;
#endregion
#region SerializeField
[SerializeField]
private List<string> videoUrlPool;
public bool playOnAwake = false;
public bool prepareOnAwake = true;
public bool isLooping = false;
public bool waitForFirstFrame = false;
public bool isStreamingAssetsPath = false;
public Graphic loadingUI;
public Graphic coverUI;
public Button playBtn;
public Button stopBtn;
public Button pauseBtn;
public Slider sliderVideo;
public Text text_Time;
public Slider sliderSource;