Files
TaiWan/Assets/Roaming/Scripts/Show/VideoShow.cs

121 lines
3.4 KiB
C#
Raw Normal View History

2025-10-31 15:20:38 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
//[RequireComponent(typeof(VideoPlayer))]
public class VideoShow : BaseShow
{
public static VideoPlayer vpPlaying;
/// <summary>
/// <20><>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
VideoPlayer vp;
/// <summary>
/// <20><>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><D5B9><EFBFBD><EFBFBD>
/// </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;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾCoverͼƬ
if (!info.AutoPlay && !string.IsNullOrEmpty(info.ImageName))
{
StartCoroutine(ImageLoader<Material>.LoadImage(CommonData.ImageFullPath + info.ImageName, renderer.sharedMaterial));
}
if (info.Clickable)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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);
}
}
}
}
}
}