307 lines
8.1 KiB
C#
307 lines
8.1 KiB
C#
using DG.Tweening;
|
|
using RenderHeads.Media.AVProVideo;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.UI;
|
|
using ZXK.BYSS;
|
|
using ZXK.Framework;
|
|
|
|
//交互物体类型
|
|
public enum BtnType { btn,dropDown,none,shouzhi}
|
|
//交互类型
|
|
public enum ClickType {
|
|
once,two}
|
|
|
|
|
|
/// <summary>
|
|
/// 总控制器
|
|
/// </summary>
|
|
public class AvproVideoController : MonoSingleton<AvproVideoController>
|
|
{
|
|
|
|
|
|
|
|
//当前索引
|
|
public int CurrentIndex;
|
|
|
|
[Header("视频组件")]
|
|
public GameObject _MediaPlayerObj;
|
|
[Header("DisPlayUI")]
|
|
public DisplayUGUI displayUGUI;
|
|
public RawImage rawImage;
|
|
private MediaPlayer mediaPlayer;
|
|
|
|
|
|
[Header("结束按钮")]
|
|
public GameObject Btn;
|
|
|
|
|
|
|
|
public Text text;
|
|
|
|
[Header("步骤")]
|
|
public AvproVideoStep[] avproVideoSteps;
|
|
|
|
[Header("当前操作步骤")]
|
|
public AvproVideoStep currentAvproVideoSteps;
|
|
|
|
|
|
private void Start()
|
|
{
|
|
mediaPlayer = _MediaPlayerObj.GetComponent<MediaPlayer>();
|
|
|
|
//设置配音
|
|
PracticeAndExamInSceneCtrl Cur_practiceAndExamInSceneCtrl = UI_Manage.Instance.GetPanel("PracticeAndExamPanel")
|
|
.GetComponent<PracticeAndExamPanel>()._CurTrainExamSceneCtrl;
|
|
if (Cur_practiceAndExamInSceneCtrl.speakManager != null)
|
|
{
|
|
Cur_practiceAndExamInSceneCtrl.speakManager.ReSetAudioCilp();
|
|
|
|
Cur_practiceAndExamInSceneCtrl.speakManager.ChangeModelAudio("程序调试");
|
|
|
|
}
|
|
|
|
//初始化
|
|
//音频播放,
|
|
//视频播放
|
|
//并给索引按钮添加事件
|
|
//初始化调用rawImage
|
|
|
|
|
|
SetMedioPlayer();
|
|
|
|
|
|
}
|
|
string FloderPath;
|
|
///视频地址设置
|
|
public void SetMedioPlayer()
|
|
{
|
|
//超索引处理,默认完成了弹出结束按钮
|
|
if (CurrentIndex< avproVideoSteps.Length)
|
|
{
|
|
|
|
//分离版本地址设定用这个
|
|
switch (AppManagement.XhbyType)
|
|
{
|
|
case XHBY_Type.PLC_KZQG:
|
|
FloderPath = "/AVProVideo/KZQGDebugVideo/";
|
|
break;
|
|
case XHBY_Type.PLC_KZZLD:
|
|
FloderPath = "/AVProVideo/KZZLDDebugVideo/";
|
|
break;
|
|
case XHBY_Type.GDCGQ:
|
|
FloderPath = "/AVProVideo/ZDSJSLDebugVideo/";
|
|
break;
|
|
case XHBY_Type.JXSWF:
|
|
FloderPath = "/AVProVideo/ZDSJSLDebugVideo/";
|
|
break;
|
|
case XHBY_Type.BYXQ:
|
|
FloderPath = "/AVProVideo/BYXQDebugVideo/";
|
|
break;
|
|
case XHBY_Type.ZDSJS:
|
|
FloderPath = "/AVProVideo/BYXQDebugVideo/";
|
|
break;
|
|
|
|
}
|
|
|
|
//switch (AppManagement.Instance._CurType)
|
|
//{
|
|
|
|
// case ZXK.UTility.EnumCtrl.Type.XHBY:
|
|
// FloderPath = "/AVProVideo/循环搬运完整版程序下载/";
|
|
// break;
|
|
// case ZXK.UTility.EnumCtrl.Type.QDCY:
|
|
// FloderPath = "/AVProVideo/气动冲压程序下载视频/";
|
|
// break;
|
|
// case ZXK.UTility.EnumCtrl.Type.CLFJ:
|
|
// FloderPath = "/AVProVideo/材料分拣程序下载视频/";
|
|
// break;
|
|
// case ZXK.UTility.EnumCtrl.Type.ZNYD:
|
|
// FloderPath = "/AVProVideo/智能运动程序下载视频/";
|
|
// break;
|
|
// case ZXK.UTility.EnumCtrl.Type.BYSS:
|
|
// FloderPath = "/AVProVideo/搬运输送程序下载视频/";
|
|
// break;
|
|
//}
|
|
|
|
//1.5设置文字
|
|
text.text = avproVideoSteps[CurrentIndex].TextStr;
|
|
|
|
|
|
|
|
//2.
|
|
//设置当前视频组
|
|
|
|
mediaPlayer.m_VideoPath = Application.streamingAssetsPath + FloderPath + avproVideoSteps[CurrentIndex].AvproVideoPath + ".mp4"; ;
|
|
//视频地址播放
|
|
|
|
|
|
mediaPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.AbsolutePathOrURL, mediaPlayer.m_VideoPath, false);
|
|
|
|
//设置承载视频播放UI
|
|
//1.开始播放视频
|
|
displayUGUI.gameObject.SetActive(true);
|
|
displayUGUI.CurrentMediaPlayer.Play();
|
|
|
|
|
|
|
|
displayUGUI._mediaPlayer.Events.RemoveAllListeners();
|
|
//注册事件
|
|
displayUGUI._mediaPlayer.Events.AddListener(OnMediaPlayerEvent);
|
|
|
|
|
|
|
|
|
|
//2.先播放音频
|
|
|
|
if (avproVideoSteps[CurrentIndex].IsPlayAudio)
|
|
{
|
|
|
|
var v = UI_Manage.Instance.GetPanel("PracticeAndExamPanel")
|
|
.GetComponent<PracticeAndExamPanel>()._CurTrainExamSceneCtrl;
|
|
|
|
|
|
|
|
v.speakManager.PlayFixedAudioCilp(avproVideoSteps[CurrentIndex].AudioClipIndex);
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("不播放音频");
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
Btn.gameObject.SetActive(true);
|
|
Btn.gameObject.GetComponent<CanvasGroup>().alpha=1;
|
|
Btn.gameObject.GetComponent<Button>().interactable = true;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
Texture2D CloneTexture(Texture2D original)
|
|
{
|
|
// 创建一个与原始纹理相同的纹理
|
|
Texture2D clone = new Texture2D(original.width, original.height);
|
|
//复制原始纹理的像素到新的纹理
|
|
clone.SetPixels(original.GetPixels());
|
|
clone.Apply();
|
|
return clone;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 侦听播放
|
|
/// </summary>
|
|
/// <param name="arg0"></param>
|
|
/// <param name="arg1"></param>
|
|
/// <param name="arg2"></param>
|
|
private void OnMediaPlayerEvent(MediaPlayer arg0, MediaPlayerEvent.EventType arg1, ErrorCode arg2)
|
|
{
|
|
switch (arg1)
|
|
{
|
|
case MediaPlayerEvent.EventType.Started:
|
|
print("startedEvent开始事件触发");
|
|
////设置承载器封面
|
|
////设置视频永远是下一个
|
|
//displayUGUI_Copy._mediaPlayer.m_VideoPath = mediaPlayer.m_VideoPath = Application.streamingAssetsPath + FloderPath + avproVideoSteps[CurrentIndex + 1].AvproVideoPath + ".mp4"; ;
|
|
//displayUGUI_Copy._mediaPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.RelativeToStreamingAssetsFolder, displayUGUI_Copy._mediaPlayer.m_VideoPath, false);
|
|
//displayUGUI_Copy._mediaPlayer.Pause();
|
|
rawImage.gameObject.SetActive(false);
|
|
|
|
break;
|
|
case MediaPlayerEvent.EventType.FinishedPlaying:
|
|
print("finishedEvent结束事件触发");
|
|
displayUGUI._mediaPlayer.Stop();
|
|
avproVideoSteps[CurrentIndex].OnInitd();
|
|
|
|
|
|
|
|
if (rawImage.texture != null)
|
|
{
|
|
Destroy(rawImage.texture);
|
|
}
|
|
|
|
|
|
Texture2D tt = CloneTexture(mediaPlayer.ExtractFrame(null, mediaPlayer.Control.GetCurrentTimeMs() / 1000f));
|
|
rawImage.texture = tt;
|
|
rawImage.gameObject.SetActive(true);
|
|
break;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 接收方法
|
|
/// </summary>
|
|
/// <param name="IsFinish"></param>
|
|
public void GetStepFuction(AvproVideoStep avproVideoStep) {
|
|
|
|
int index=-1;
|
|
for (int i = 0; i < avproVideoSteps.Length; i++)
|
|
{
|
|
if (avproVideoStep.Equals(avproVideoSteps[i]))
|
|
{
|
|
index = i;
|
|
currentAvproVideoSteps = avproVideoSteps[index];
|
|
|
|
|
|
|
|
break;
|
|
}
|
|
}
|
|
//关闭操作的UI
|
|
|
|
|
|
// displayUGUI_Copy.gameObject.SetActive(true);
|
|
|
|
currentAvproVideoSteps.OnHide();
|
|
//增加索引号
|
|
CurrentIndex++;
|
|
|
|
SetMedioPlayer();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
public Tween wait(float second) {
|
|
|
|
|
|
var tweensSequence = DOTween.Sequence();
|
|
tweensSequence.AppendInterval(second);
|
|
return tweensSequence;
|
|
}
|
|
|
|
|
|
private void Update()
|
|
{
|
|
//单元测试
|
|
if (Input.GetKeyDown(KeyCode.L))
|
|
{
|
|
if (CurrentIndex < avproVideoSteps.Length)
|
|
{
|
|
GetStepFuction(avproVideoSteps[CurrentIndex]);
|
|
SetMedioPlayer();
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("程序调试数组最后一个");
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|