130 lines
4.8 KiB
C#
130 lines
4.8 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using DefaultNamespace;
|
||
using DefaultNamespace.ProcessMode;
|
||
using Framework.ProcessMode;
|
||
using MotionFramework;
|
||
using RenderHeads.Media.AVProVideo;
|
||
using UnityEngine;
|
||
|
||
public class VideoPlayProcessManager : MonoBehaviour
|
||
{
|
||
[Header("视频播放组件")] public GameObject play;
|
||
public MediaPlayer mediaPlayer;
|
||
|
||
[Header("视频文件配置")] private string videoPath1 = "XX公司库存组成分析-金额汇总及透视表制作.mp4";
|
||
|
||
private string videoPath2 = "分析全市库存500138347物料号的柱上断路器总库存-透视表制作.mp4";
|
||
|
||
public void Start()
|
||
{
|
||
MotionEngine.GetModule<ProcessManager>().OnLastActionStartEvent += OnLastActionStartEvent;
|
||
Debug.Log("VideoPlayProcessManager: 已注册所有模式最后动作开始事件监听");
|
||
}
|
||
|
||
private void OnLastActionStartEvent(ProcessStepDescription action)
|
||
{
|
||
// 检查当前模式是否为教学模式或课程预览模式
|
||
if (MotionEngine.GetModule<ProcessManager>()._currentMode == ProcessMode.课程预览 ||
|
||
MotionEngine.GetModule<ProcessManager>()._currentMode == ProcessMode.教学模式)
|
||
{
|
||
string examName = MotionEngine.GetModule<GlobalDataStorage>().ExamName;
|
||
Debug.Log($"VideoPlayProcessManager: 检测到所有模式最后动作开始,当前题目:{examName},动作:{action.Title}");
|
||
|
||
if (examName == "XX公司库存组成分析")
|
||
{
|
||
Debug.Log("VideoPlayProcessManager: 开始播放XX公司库存组成分析视频");
|
||
PlayVideo(videoPath1);
|
||
}
|
||
else if (examName == "分析全市库存500138347物料号的一二次融合成套柱上断路器总库存")
|
||
{
|
||
Debug.Log("VideoPlayProcessManager: 开始播放柱上断路器总库存分析视频");
|
||
PlayVideo(videoPath2);
|
||
}
|
||
else
|
||
{
|
||
Debug.LogWarning($"VideoPlayProcessManager: 未找到题目 '{examName}' 对应的视频配置");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Debug.Log($"VideoPlayProcessManager: 检测到最后动作开始,但当前模式为 {MotionEngine.GetModule<ProcessManager>()._currentMode},不播放视频");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 播放指定路径的视频
|
||
/// </summary>
|
||
/// <param name="videoPath">视频文件路径(相对于StreamingAssets文件夹)</param>
|
||
private void PlayVideo(string videoPath)
|
||
{
|
||
if (mediaPlayer == null)
|
||
{
|
||
Debug.LogError("VideoPlayProcessManager: MediaPlayer组件未设置");
|
||
return;
|
||
}
|
||
|
||
if (play == null)
|
||
{
|
||
Debug.LogError("VideoPlayProcessManager: 视频显示GameObject未设置");
|
||
return;
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(videoPath))
|
||
{
|
||
Debug.LogError("VideoPlayProcessManager: 视频路径为空");
|
||
return;
|
||
}
|
||
|
||
try
|
||
{
|
||
// 显示视频GameObject
|
||
play.SetActive(true);
|
||
Debug.Log($"VideoPlayProcessManager: 显示视频GameObject");
|
||
|
||
// 构建完整的视频路径
|
||
string fullVideoPath = System.IO.Path.Combine(Application.streamingAssetsPath, videoPath);
|
||
Debug.Log($"VideoPlayProcessManager: 完整视频路径:{fullVideoPath}");
|
||
|
||
// 检查视频文件是否存在
|
||
if (!System.IO.File.Exists(fullVideoPath))
|
||
{
|
||
Debug.LogError($"VideoPlayProcessManager: 视频文件不存在:{fullVideoPath}");
|
||
return;
|
||
}
|
||
|
||
// 停止当前播放(如果有)
|
||
mediaPlayer.Stop();
|
||
|
||
// 打开新的视频文件,不自动播放
|
||
bool openResult = mediaPlayer.OpenMedia(RenderHeads.Media.AVProVideo.MediaPathType.RelativeToStreamingAssetsFolder, fullVideoPath, true);
|
||
|
||
if (openResult)
|
||
{
|
||
Debug.Log($"VideoPlayProcessManager: 成功打开视频文件:{videoPath}");
|
||
|
||
// 从头开始播放
|
||
mediaPlayer.Play();
|
||
Debug.Log("VideoPlayProcessManager: 开始播放视频");
|
||
}
|
||
else
|
||
{
|
||
Debug.LogError($"VideoPlayProcessManager: 打开视频文件失败:{videoPath}");
|
||
}
|
||
}
|
||
catch (System.Exception ex)
|
||
{
|
||
Debug.LogError($"VideoPlayProcessManager: 播放视频时发生异常:{ex.Message}");
|
||
}
|
||
}
|
||
|
||
private void OnDestroy()
|
||
{
|
||
// 取消事件监听
|
||
if (MotionEngine.GetModule<ProcessManager>() != null)
|
||
{
|
||
MotionEngine.GetModule<ProcessManager>().OnLastActionStartEvent -= OnLastActionStartEvent;
|
||
}
|
||
}
|
||
} |