feat: MCP Unity 场景优化 — 完整交互体系搭建
- 删除重复 Ground - 创建 [Managers] 空物体,挂载 GameManager + StepManager + ExperimentFlowCoordinator + AudioManager - Main Camera 挂载 InteractionSystem - 伤者 InjectedPerson 下创建 5 个交互子物体 (InjuryVisual/Swelling/Pain/VitalSigns/Neuro) - 创建绑带位置、踝关节、衬垫、夹板位置等空物体 - 道具摆放到位:伤者(2,0.05,5) 施救者(3,0,5) 鞋(2.7,0.15,5.5) 绷带/夹板/急救箱在旁 - InjuryLeg Tag 修正,Ground Tag 修正 - 全部新脚本同步导入 (ExperimentTypes/StepData/ExperimentConfig/StepManager/GameManager/ExperimentFlowCoordinator/InteractionSystem/DraggableObject/HighlightEffect/UIManager/ExamPopup/ScoreDisplay/VideoController/AudioManager/CharacterAnimController/StepAnimationHandler) - 旧脚本 (ExperimentController/ConfigLoader/AnimationController/HUDController/VideoPlayerController/PopupSystem/ModeSelectionUI) 全部兼容修复或 stub - 编译通过,0 错误 - Canvas 挂载 UIManager
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Video;
|
||||
|
||||
/// <summary>
|
||||
/// 画中画视频控制器:用 VideoPlayer 渲染到 RenderTexture,再赋给 RawImage。
|
||||
/// 挂在包含 RawImage 和 VideoPlayer 的 GameObject 上。
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(RawImage))]
|
||||
public class VideoController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private VideoPlayer _videoPlayer;
|
||||
[SerializeField] private RawImage _rawImage;
|
||||
|
||||
private RenderTexture _renderTexture;
|
||||
private bool _isPlaying;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (_rawImage == null) _rawImage = GetComponent<RawImage>();
|
||||
if (_videoPlayer == null) _videoPlayer = GetComponentInChildren<VideoPlayer>();
|
||||
|
||||
if (_videoPlayer != null)
|
||||
{
|
||||
_videoPlayer.loopPointReached += OnVideoEnd;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>播放指定视频文件(StreamingAssets/Videos/ 下)</summary>
|
||||
public void PlayVideo(string fileName)
|
||||
{
|
||||
if (_videoPlayer == null) return;
|
||||
|
||||
string path = System.IO.Path.Combine(Application.streamingAssetsPath, "Videos", fileName);
|
||||
_videoPlayer.url = path;
|
||||
|
||||
// 创建 RenderTexture
|
||||
if (_renderTexture == null)
|
||||
{
|
||||
int w = _videoPlayer.targetTexture != null ? _videoPlayer.targetTexture.width : 640;
|
||||
int h = _videoPlayer.targetTexture != null ? _videoPlayer.targetTexture.height : 360;
|
||||
_renderTexture = new RenderTexture(w, h, 0);
|
||||
_videoPlayer.targetTexture = _renderTexture;
|
||||
if (_rawImage != null) _rawImage.texture = _renderTexture;
|
||||
}
|
||||
|
||||
_videoPlayer.Play();
|
||||
_isPlaying = true;
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void StopVideo()
|
||||
{
|
||||
if (_videoPlayer != null) _videoPlayer.Stop();
|
||||
_isPlaying = false;
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void PauseVideo()
|
||||
{
|
||||
if (_videoPlayer != null) _videoPlayer.Pause();
|
||||
}
|
||||
|
||||
public void ResumeVideo()
|
||||
{
|
||||
if (_videoPlayer != null) _videoPlayer.Play();
|
||||
}
|
||||
|
||||
private void OnVideoEnd(VideoPlayer vp)
|
||||
{
|
||||
// 真人演示视频播完自动循环
|
||||
vp.Play();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (_renderTexture != null)
|
||||
{
|
||||
_renderTexture.Release();
|
||||
Destroy(_renderTexture);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user