a11e003fcd
- 加权评分系统:每步独立 ScoreWeight,满分 100,SequenceClick 按子项比例计分 - StepData 新增 DetailedContent(学习模式详细操作说明)和 SubStepCount - 伤情检查步骤扩展为 5 子项序列(视觉检查→肿胀→疼痛→生命体征→神经评估) - 夹板固定模式完整评分(选择夹板→放置衬垫→夹板固定→固定后检查) - Doc/ 文件夹归档三份文档:项目大纲、文案、评分标准 - README 更新评分权重表和夹板固定流程
84 lines
2.3 KiB
C#
84 lines
2.3 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|