Optimize WebGL build and video loading

This commit is contained in:
yangbear
2026-07-14 00:16:34 +08:00
parent ecfc382b03
commit 53f856e44e
20 changed files with 203 additions and 33 deletions
+32 -3
View File
@@ -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();
+6 -1
View File
@@ -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