286 lines
6.7 KiB
C#
286 lines
6.7 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>();
|
|
|
|
|
|
|
|
//初始化
|
|
//音频播放,
|
|
//视频播放
|
|
//并给索引按钮添加事件
|
|
//初始化调用rawImage
|
|
|
|
|
|
SetMedioPlayer();
|
|
|
|
|
|
}
|
|
string FloderPath;
|
|
///视频地址设置
|
|
public void SetMedioPlayer()
|
|
{
|
|
//超索引处理,默认完成了弹出结束按钮
|
|
if (CurrentIndex< avproVideoSteps.Length)
|
|
{
|
|
|
|
|
|
|
|
switch (AppManagement.Instance._CurType)
|
|
{
|
|
|
|
case ZXK.UTility.EnumCtrl.Type.XHBY:
|
|
FloderPath = "/AVProVideo/XHBYDebugVideo/";
|
|
break;
|
|
case ZXK.UTility.EnumCtrl.Type.QDCY:
|
|
FloderPath = "/AVProVideo/QDCYDebugVideo/";
|
|
break;
|
|
case ZXK.UTility.EnumCtrl.Type.CLFJ:
|
|
FloderPath = "/AVProVideo/CLFJDebugVideo/";
|
|
break;
|
|
case ZXK.UTility.EnumCtrl.Type.ZNYD:
|
|
FloderPath = "/AVProVideo/ZNYDDebugVideo/";
|
|
break;
|
|
case ZXK.UTility.EnumCtrl.Type.BYSS:
|
|
FloderPath = "/AVProVideo/BYSSDebugVideo/";
|
|
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
|
|
{
|
|
WDebug.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.ReadyToPlay:
|
|
rawImage.gameObject.SetActive(true);
|
|
break;
|
|
|
|
case MediaPlayerEvent.EventType.Started:
|
|
print("startedEvent开始事件触发");
|
|
|
|
|
|
rawImage.gameObject.SetActive(false);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case MediaPlayerEvent.EventType.FinishedPlaying:
|
|
print("finishedEvent结束事件触发");
|
|
displayUGUI._noDefaultDisplay = false;
|
|
rawImage.gameObject.SetActive(true);
|
|
Texture2D tt = CloneTexture(mediaPlayer.ExtractFrame(null, mediaPlayer.Control.GetCurrentTimeMs() / 1000f));
|
|
rawImage.texture = tt;
|
|
// displayUGUI._mediaPlayer.Stop();
|
|
displayUGUI._defaultTexture = tt;
|
|
|
|
if (CurrentIndex < avproVideoSteps.Length)
|
|
{
|
|
avproVideoSteps[CurrentIndex].OnInitd();
|
|
}
|
|
|
|
|
|
|
|
//if (rawImage.texture != null)
|
|
//{
|
|
// Destroy(rawImage.texture);
|
|
//}
|
|
|
|
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++;
|
|
rawImage.gameObject.SetActive(true);
|
|
|
|
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("程序调试数组最后一个");
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
}
|