Optimize WebGL build and video loading
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Video;
|
||||
|
||||
public class UIManager : MonoBehaviour
|
||||
{
|
||||
@@ -179,12 +180,40 @@ public class UIManager : MonoBehaviour
|
||||
if (_videoPanel != null)
|
||||
{
|
||||
_videoPanel.SetActive(true);
|
||||
var vp = _videoPanel.GetComponentInChildren<UnityEngine.Video.VideoPlayer>(true);
|
||||
if (vp != null) vp.Play();
|
||||
Debug.Log("UIManager: 显示并播放 VideoPanel");
|
||||
var controller = _videoPanel.GetComponent<VideoController>();
|
||||
if (controller != null)
|
||||
{
|
||||
controller.PlayVideo(fileName);
|
||||
return;
|
||||
}
|
||||
|
||||
var vp = _videoPanel.GetComponentInChildren<VideoPlayer>(true);
|
||||
if (vp != null)
|
||||
{
|
||||
ConfigureStreamingVideo(vp, fileName);
|
||||
vp.Play();
|
||||
}
|
||||
Debug.Log("UIManager: 显示并播放 VideoPanel: " + fileName);
|
||||
}
|
||||
}
|
||||
|
||||
private void ConfigureStreamingVideo(VideoPlayer vp, string fileName)
|
||||
{
|
||||
vp.source = VideoSource.Url;
|
||||
vp.url = BuildStreamingVideoUrl(fileName);
|
||||
vp.playOnAwake = false;
|
||||
vp.isLooping = true;
|
||||
vp.renderMode = VideoRenderMode.RenderTexture;
|
||||
vp.audioOutputMode = VideoAudioOutputMode.Direct;
|
||||
}
|
||||
|
||||
private string BuildStreamingVideoUrl(string fileName)
|
||||
{
|
||||
string safeName = string.IsNullOrEmpty(fileName) ? "bandage_demo.mp4" : fileName;
|
||||
string baseUrl = Application.streamingAssetsPath.TrimEnd('/');
|
||||
return baseUrl + "/Videos/" + safeName;
|
||||
}
|
||||
|
||||
public void HideVideo()
|
||||
{
|
||||
AutoFindPanels();
|
||||
|
||||
@@ -25,7 +25,10 @@ public class VideoController : MonoBehaviour
|
||||
|
||||
if (_videoPlayer != null)
|
||||
{
|
||||
_videoPlayer.source = VideoSource.Url;
|
||||
_videoPlayer.playOnAwake = false;
|
||||
_videoPlayer.isLooping = true;
|
||||
_videoPlayer.audioOutputMode = VideoAudioOutputMode.Direct;
|
||||
_videoPlayer.loopPointReached += OnVideoEnd;
|
||||
}
|
||||
|
||||
@@ -38,7 +41,9 @@ public class VideoController : MonoBehaviour
|
||||
{
|
||||
if (_videoPlayer == null) return;
|
||||
|
||||
string path = System.IO.Path.Combine(Application.streamingAssetsPath, "Videos", fileName);
|
||||
string safeName = string.IsNullOrEmpty(fileName) ? "bandage_demo.mp4" : fileName;
|
||||
string path = Application.streamingAssetsPath.TrimEnd('/') + "/Videos/" + safeName;
|
||||
_videoPlayer.source = VideoSource.Url;
|
||||
_videoPlayer.url = path;
|
||||
|
||||
// 创建 RenderTexture
|
||||
|
||||
Reference in New Issue
Block a user