123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- using UnityEngine;
- using UnityEngine.UI;
- using QFramework;
- using System.IO;
- using System.Collections.Generic;
- using I2.Loc;
- using System.Collections;
- using System;
- using ChivaXR;
- using UnityEngine.Video;
- namespace QFramework
- {
- public class MattersNeedingAttentionFromData : UIPanelData
- {
- public OperationStepDataInfo operationStepDataInfo;
- /// <summary>
- /// 是否需要记录
- /// </summary>
- public bool isNeedLog;
- }
- public partial class MattersNeedingAttentionFrom : UIPanel
- {
- private float heightBasic = 295.5898f;
- protected override void OnInit(IUIData uiData = null)
- {
- mData = uiData as MattersNeedingAttentionFromData ?? new MattersNeedingAttentionFromData();
- ConfirmBtn.onClick.AddListener(OnConfirmBtnClick);
- VoiceBtn.onClick.AddListener(OnVoiceBtnClick);
- }
- protected override void OnOpen(IUIData uiData = null)
- {
- mData = uiData as MattersNeedingAttentionFromData ?? new MattersNeedingAttentionFromData();
- OperationStepDataInfo tmpOperationStepDataInfo = mData.operationStepDataInfo;
- //如果没有值则直接关掉
- if (string.IsNullOrEmpty(tmpOperationStepDataInfo.stepMattersNeedingAttention) &&
- string.IsNullOrEmpty(tmpOperationStepDataInfo.stepVideoNames) &&
- string.IsNullOrEmpty(tmpOperationStepDataInfo.stepPictureNames))
- {
- CloseSelf();
- return;
- }
- if (mData.isNeedLog)
- {
- LogSystemForm tmpLogSystemForm = UIKit.GetPanel<LogSystemForm>();
- if (tmpLogSystemForm == null)
- {
- tmpLogSystemForm = UIKit.OpenPanel<LogSystemForm>();
- }
- tmpLogSystemForm.AddCurrentStepLog("注意事项");
- }
- List<string> tmpVideoNames = tmpOperationStepDataInfo.GetVideoNames();
- //注意事项视频
- if (tmpVideoNames != null && tmpVideoNames.Count > 0)
- {
- VideoBg.gameObject.SetActive(true);
- VideoBg.url = Path.Combine(GlobalConfig.videoPath, OperateSetting.Instance.m_CourseName, tmpVideoNames[0]);
- VideoBg.Play();
- //学习模式视频播放完毕自动关闭
- if (OperateSetting.Instance.m_CurrentOperationMode == OperationMode.Learn)
- {
- VideoBg.prepareCompleted += VideoBg_prepareCompleted;
- }
- }
- else
- {
- VideoBg.gameObject.SetActive(false);
- VideoBg.url = null;
- }
- //注意事项文字
- if (!string.IsNullOrEmpty(tmpOperationStepDataInfo.stepMattersNeedingAttention))
- {
- //MattersNeedingAttentionText.text = tmpOperationStepDataInfo.stepMattersNeedingAttention;
- LocalizedString mattersNeedingAttentionText = mData.operationStepDataInfo.id + "stepMattersNeedingAttention";
- MattersNeedingAttentionText.text = mattersNeedingAttentionText;
- MattersNeedingAttentionText.gameObject.SetActive(true);
- //注意事项音频
- StartCoroutine(AudioHelper.LoadAudioClip(OperateSetting.Instance.m_CourseName, tmpOperationStepDataInfo.audioClipName + "_note", AudioType.MPEG, LoadAudioCallBack));
- }
- else
- {
- MattersNeedingAttentionText.gameObject.SetActive(false);
- }
- List<string> tmpPictureNames = tmpOperationStepDataInfo.GetPicturesNames();
- //注意事项图片
- if (tmpPictureNames != null && tmpPictureNames.Count > 0)
- {
- PictureBg.gameObject.SetActive(true);
- SetInfoOfImage(LoadHelper.LoadSprite(Path.Combine(GlobalConfig.picturePath, OperateSetting.Instance.m_CourseName, tmpPictureNames[0])));
- }
- else
- {
- PictureBg.gameObject.SetActive(false);
- }
- GetComponent<ScaleContronl>().UpdateScale();
- if (LocalizationConfig.localization)
- {
- RefrushLocalization();
- }
- //流程结束自动关闭自己
- ProcessManagement.Instance.processFinishEvent += ProcessFinsihedCloseSelf;
- }
- private void VideoBg_prepareCompleted(VideoPlayer source)
- {
- Debug.LogWarning(VideoBg.frameCount + "视频长度:" + (float)VideoBg.frameCount / VideoBg.frameRate);
- StartCoroutine(WaitTimeCallBack((float)VideoBg.frameCount / VideoBg.frameRate, CloseSelf));
- VideoBg.prepareCompleted -= VideoBg_prepareCompleted;
- }
- public void ProcessFinsihedCloseSelf()
- {
- CloseSelf();
- }
- /// <summary>
- /// 加载音频回调
- /// </summary>
- /// <param name="clip"></param>
- private void LoadAudioCallBack(AudioClip clip)
- {
- if (clip != null)
- {
- SoundManager.Instance.PlayBg(clip);
- }
- //学习模式下自动关闭注意事项
- if (OperateSetting.Instance.m_CurrentOperationMode != OperationMode.Learn) return;
- if (!ProcessManagement.Instance.autoEnterNextProcess) return;
- if (clip == null)
- {
- //音频空,等待3S,关闭注意事项
- StartCoroutine(WaitTimeCallBack(3, () =>
- {
- CloseSelf();
- }));
- }
- else
- {
- StartCoroutine(WaitTimeCallBack(clip.length, () =>
- {
- CloseSelf();
- }));
- }
- }
- IEnumerator WaitTimeCallBack(float duration, Action callBack)
- {
- yield return new WaitForSeconds(duration);
- callBack?.Invoke();
- }
- /// <summary>
- /// 设置Image信息
- /// </summary>
- /// <param name="_sprite"></param>
- private void SetInfoOfImage(Sprite _sprite)
- {
- if (_sprite == null) return;
- float width = _sprite.texture.width * CalculateScale(_sprite.texture.height);
- float height = _sprite.texture.height * CalculateScale(_sprite.texture.height);
- PictrueImage.rectTransform.sizeDelta = new Vector2(width, height);
- PictrueImage.sprite = _sprite;
- }
- protected override void OnShow()
- {
- }
- protected override void OnHide()
- {
- }
- protected override void OnClose()
- {
- SoundManager.Instance.BgVolume = 1;
- StopAllCoroutines();
- ProcessManagement.Instance.processFinishEvent -= ProcessFinsihedCloseSelf;
- }
- private void OnVoiceBtnClick()
- {
- Transform tmpVoice = VoiceBtn.transform.Find("Voice");
- Transform tmpMute = VoiceBtn.transform.Find("Mute");
- if (tmpVoice.gameObject.activeSelf)
- {
- tmpVoice.gameObject.SetActive(false);
- tmpMute.gameObject.SetActive(true);
- //AudioHelper.
- SoundManager.Instance.BgVolume = 0;
- if (VideoBg.url != null)
- {
- VideoBg.GetTargetAudioSource(0).volume = 0;
- }
- }
- else
- {
- tmpVoice.gameObject.SetActive(true);
- tmpMute.gameObject.SetActive(false);
- SoundManager.Instance.BgVolume = 1;
- if (VideoBg.url != null)
- {
- VideoBg.GetTargetAudioSource(0).volume = 1;
- }
- }
- }
- /// <summary>
- /// 确定按钮点击
- /// </summary>
- private void OnConfirmBtnClick()
- {
- SoundManager.Instance.StopBg();
- CloseSelf();
- }
- /// <summary>
- /// 计算比例,以高度为基数计算
- /// </summary>
- /// <param name="_spriteHeight"></param>
- private float CalculateScale(float _spriteHeight)
- {
- if (_spriteHeight <= heightBasic)
- {
- return 1;
- }
- else
- {
- return heightBasic / _spriteHeight;
- }
- }
- #region 多语言
- public void RefrushLocalization()
- {
- if (mData.operationStepDataInfo != null)
- {
- LocalizedString mattersNeedingAttentionText = mData.operationStepDataInfo.id + "stepMattersNeedingAttention";
- MattersNeedingAttentionText.text = mattersNeedingAttentionText;
- }
- }
- void OnEnable()
- {
- LocalizationManager.OnLocalizeEvent += LocalizationManager_OnLocalizeEvent;
- LocalizationManager_OnLocalizeEvent();
- }
- void OnDisEnable()
- {
- LocalizationManager.OnLocalizeEvent -= LocalizationManager_OnLocalizeEvent;
- }
- private void LocalizationManager_OnLocalizeEvent()
- {
- if (LocalizationConfig.localization)
- {
- RefrushLocalization();
- }
- }
- #endregion
- }
- }
|