121 lines
3.4 KiB
C#
121 lines
3.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Video;
|
|
|
|
//[RequireComponent(typeof(VideoPlayer))]
|
|
public class VideoShow : BaseShow
|
|
{
|
|
public static VideoPlayer vpPlaying;
|
|
|
|
/// <summary>
|
|
/// 视频播放器对象
|
|
/// </summary>
|
|
VideoPlayer vp;
|
|
|
|
/// <summary>
|
|
/// 视频播放器扩展对象
|
|
/// </summary>
|
|
VideoPlayerEx vpEx;
|
|
|
|
void Start()
|
|
{
|
|
if (info != null)
|
|
{
|
|
Renderer renderer = GetComponent<Renderer>();
|
|
if (info.PlayVideoOnObject)
|
|
{
|
|
vp = gameObject.AddComponent<VideoPlayer>();
|
|
// vp = GetComponent<VideoPlayer>();
|
|
vp.targetMaterialRenderer = renderer;
|
|
vp.playOnAwake = info.AutoPlay;
|
|
vp.isLooping = info.Loop;
|
|
vp.source = VideoSource.Url;
|
|
vp.url = CommonData.VideoFullPath + info.VideoName;
|
|
vp.renderMode = VideoRenderMode.MaterialOverride;
|
|
}
|
|
|
|
// 如果不是自动播放则显示Cover图片
|
|
if (!info.AutoPlay && !string.IsNullOrEmpty(info.ImageName))
|
|
{
|
|
StartCoroutine(ImageLoader<Material>.LoadImage(CommonData.ImageFullPath + info.ImageName, renderer.sharedMaterial));
|
|
}
|
|
|
|
if (info.Clickable)
|
|
{
|
|
// 添加碰撞器以允许单击
|
|
if (GetComponent<Collider>() == null)
|
|
{
|
|
gameObject.AddComponent<MeshCollider>();
|
|
}
|
|
}
|
|
}
|
|
|
|
vpEx = FindObjectOfType<VideoPlayerEx>();
|
|
if (vpEx != null)
|
|
{
|
|
vpEx.onVideoClosed += delegate {
|
|
BtnController.Instance.SetCanControlDelay();
|
|
|
|
// Invoke("SetControl", 0.2f);
|
|
// BaseController.CanControl = true;
|
|
// Caching.ClearCache();
|
|
};
|
|
}
|
|
}
|
|
|
|
public override void OnClick()
|
|
{
|
|
if (BaseController.CanControl)
|
|
{
|
|
Invoke("ShowVideoEx", 0.01f);
|
|
}
|
|
}
|
|
|
|
void ShowVideoEx()
|
|
{
|
|
//if (!BaseController.IsJoyStickOnControl && BaseController.CanControl && CanClick)
|
|
if (BaseController.CanControl && CanClick)
|
|
{
|
|
if (info.PlayVideoOnObject)
|
|
{
|
|
if (vp != null)
|
|
{
|
|
if (vp.isPlaying)
|
|
{
|
|
vp.Pause();
|
|
}
|
|
else
|
|
{
|
|
if (vpPlaying != null && vpPlaying.isPlaying)
|
|
{
|
|
vpPlaying.Pause();
|
|
}
|
|
vp.Play();
|
|
vpPlaying = vp;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (vpEx != null && !string.IsNullOrEmpty(info.VideoName))
|
|
{
|
|
BaseController.CanControl = false;
|
|
|
|
AudioManager.Instance.PauseBackgroundMusic();
|
|
|
|
if (H5Controller.IsMobileBroswer())
|
|
{
|
|
H5Controller.LoadVideo(info.VideoName, info.Title);
|
|
}
|
|
else
|
|
{
|
|
vpEx.ShowVideoPlayer();
|
|
vpEx.PlayVideo(info.VideoName, info.Title);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|