MattersNeedingAttentionFrom.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using QFramework;
  4. using System.IO;
  5. using System.Collections.Generic;
  6. using I2.Loc;
  7. using System.Collections;
  8. using System;
  9. using ChivaXR;
  10. using UnityEngine.Video;
  11. namespace QFramework
  12. {
  13. public class MattersNeedingAttentionFromData : UIPanelData
  14. {
  15. public OperationStepDataInfo operationStepDataInfo;
  16. /// <summary>
  17. /// 是否需要记录
  18. /// </summary>
  19. public bool isNeedLog;
  20. }
  21. public partial class MattersNeedingAttentionFrom : UIPanel
  22. {
  23. private float heightBasic = 295.5898f;
  24. protected override void OnInit(IUIData uiData = null)
  25. {
  26. mData = uiData as MattersNeedingAttentionFromData ?? new MattersNeedingAttentionFromData();
  27. ConfirmBtn.onClick.AddListener(OnConfirmBtnClick);
  28. VoiceBtn.onClick.AddListener(OnVoiceBtnClick);
  29. }
  30. protected override void OnOpen(IUIData uiData = null)
  31. {
  32. mData = uiData as MattersNeedingAttentionFromData ?? new MattersNeedingAttentionFromData();
  33. OperationStepDataInfo tmpOperationStepDataInfo = mData.operationStepDataInfo;
  34. //如果没有值则直接关掉
  35. if (string.IsNullOrEmpty(tmpOperationStepDataInfo.stepMattersNeedingAttention) &&
  36. string.IsNullOrEmpty(tmpOperationStepDataInfo.stepVideoNames) &&
  37. string.IsNullOrEmpty(tmpOperationStepDataInfo.stepPictureNames))
  38. {
  39. CloseSelf();
  40. return;
  41. }
  42. if (mData.isNeedLog)
  43. {
  44. LogSystemForm tmpLogSystemForm = UIKit.GetPanel<LogSystemForm>();
  45. if (tmpLogSystemForm == null)
  46. {
  47. tmpLogSystemForm = UIKit.OpenPanel<LogSystemForm>();
  48. }
  49. tmpLogSystemForm.AddCurrentStepLog("注意事项");
  50. }
  51. List<string> tmpVideoNames = tmpOperationStepDataInfo.GetVideoNames();
  52. //注意事项视频
  53. if (tmpVideoNames != null && tmpVideoNames.Count > 0)
  54. {
  55. VideoBg.gameObject.SetActive(true);
  56. VideoBg.url = Path.Combine(GlobalConfig.videoPath, OperateSetting.Instance.m_CourseName, tmpVideoNames[0]);
  57. VideoBg.Play();
  58. //学习模式视频播放完毕自动关闭
  59. if (OperateSetting.Instance.m_CurrentOperationMode == OperationMode.Learn)
  60. {
  61. VideoBg.prepareCompleted += VideoBg_prepareCompleted;
  62. }
  63. }
  64. else
  65. {
  66. VideoBg.gameObject.SetActive(false);
  67. VideoBg.url = null;
  68. }
  69. //注意事项文字
  70. if (!string.IsNullOrEmpty(tmpOperationStepDataInfo.stepMattersNeedingAttention))
  71. {
  72. //MattersNeedingAttentionText.text = tmpOperationStepDataInfo.stepMattersNeedingAttention;
  73. LocalizedString mattersNeedingAttentionText = mData.operationStepDataInfo.id + "stepMattersNeedingAttention";
  74. MattersNeedingAttentionText.text = mattersNeedingAttentionText;
  75. MattersNeedingAttentionText.gameObject.SetActive(true);
  76. //注意事项音频
  77. StartCoroutine(AudioHelper.LoadAudioClip(OperateSetting.Instance.m_CourseName, tmpOperationStepDataInfo.audioClipName + "_note", AudioType.MPEG, LoadAudioCallBack));
  78. }
  79. else
  80. {
  81. MattersNeedingAttentionText.gameObject.SetActive(false);
  82. }
  83. List<string> tmpPictureNames = tmpOperationStepDataInfo.GetPicturesNames();
  84. //注意事项图片
  85. if (tmpPictureNames != null && tmpPictureNames.Count > 0)
  86. {
  87. PictureBg.gameObject.SetActive(true);
  88. SetInfoOfImage(LoadHelper.LoadSprite(Path.Combine(GlobalConfig.picturePath, OperateSetting.Instance.m_CourseName, tmpPictureNames[0])));
  89. }
  90. else
  91. {
  92. PictureBg.gameObject.SetActive(false);
  93. }
  94. GetComponent<ScaleContronl>().UpdateScale();
  95. if (LocalizationConfig.localization)
  96. {
  97. RefrushLocalization();
  98. }
  99. //流程结束自动关闭自己
  100. ProcessManagement.Instance.processFinishEvent += ProcessFinsihedCloseSelf;
  101. }
  102. private void VideoBg_prepareCompleted(VideoPlayer source)
  103. {
  104. Debug.LogWarning(VideoBg.frameCount + "视频长度:" + (float)VideoBg.frameCount / VideoBg.frameRate);
  105. StartCoroutine(WaitTimeCallBack((float)VideoBg.frameCount / VideoBg.frameRate, CloseSelf));
  106. VideoBg.prepareCompleted -= VideoBg_prepareCompleted;
  107. }
  108. public void ProcessFinsihedCloseSelf()
  109. {
  110. CloseSelf();
  111. }
  112. /// <summary>
  113. /// 加载音频回调
  114. /// </summary>
  115. /// <param name="clip"></param>
  116. private void LoadAudioCallBack(AudioClip clip)
  117. {
  118. if (clip != null)
  119. {
  120. SoundManager.Instance.PlayBg(clip);
  121. }
  122. //学习模式下自动关闭注意事项
  123. if (OperateSetting.Instance.m_CurrentOperationMode != OperationMode.Learn) return;
  124. if (!ProcessManagement.Instance.autoEnterNextProcess) return;
  125. if (clip == null)
  126. {
  127. //音频空,等待3S,关闭注意事项
  128. StartCoroutine(WaitTimeCallBack(3, () =>
  129. {
  130. CloseSelf();
  131. }));
  132. }
  133. else
  134. {
  135. StartCoroutine(WaitTimeCallBack(clip.length, () =>
  136. {
  137. CloseSelf();
  138. }));
  139. }
  140. }
  141. IEnumerator WaitTimeCallBack(float duration, Action callBack)
  142. {
  143. yield return new WaitForSeconds(duration);
  144. callBack?.Invoke();
  145. }
  146. /// <summary>
  147. /// 设置Image信息
  148. /// </summary>
  149. /// <param name="_sprite"></param>
  150. private void SetInfoOfImage(Sprite _sprite)
  151. {
  152. if (_sprite == null) return;
  153. float width = _sprite.texture.width * CalculateScale(_sprite.texture.height);
  154. float height = _sprite.texture.height * CalculateScale(_sprite.texture.height);
  155. PictrueImage.rectTransform.sizeDelta = new Vector2(width, height);
  156. PictrueImage.sprite = _sprite;
  157. }
  158. protected override void OnShow()
  159. {
  160. }
  161. protected override void OnHide()
  162. {
  163. }
  164. protected override void OnClose()
  165. {
  166. SoundManager.Instance.BgVolume = 1;
  167. StopAllCoroutines();
  168. ProcessManagement.Instance.processFinishEvent -= ProcessFinsihedCloseSelf;
  169. }
  170. private void OnVoiceBtnClick()
  171. {
  172. Transform tmpVoice = VoiceBtn.transform.Find("Voice");
  173. Transform tmpMute = VoiceBtn.transform.Find("Mute");
  174. if (tmpVoice.gameObject.activeSelf)
  175. {
  176. tmpVoice.gameObject.SetActive(false);
  177. tmpMute.gameObject.SetActive(true);
  178. //AudioHelper.
  179. SoundManager.Instance.BgVolume = 0;
  180. if (VideoBg.url != null)
  181. {
  182. VideoBg.GetTargetAudioSource(0).volume = 0;
  183. }
  184. }
  185. else
  186. {
  187. tmpVoice.gameObject.SetActive(true);
  188. tmpMute.gameObject.SetActive(false);
  189. SoundManager.Instance.BgVolume = 1;
  190. if (VideoBg.url != null)
  191. {
  192. VideoBg.GetTargetAudioSource(0).volume = 1;
  193. }
  194. }
  195. }
  196. /// <summary>
  197. /// 确定按钮点击
  198. /// </summary>
  199. private void OnConfirmBtnClick()
  200. {
  201. SoundManager.Instance.StopBg();
  202. CloseSelf();
  203. }
  204. /// <summary>
  205. /// 计算比例,以高度为基数计算
  206. /// </summary>
  207. /// <param name="_spriteHeight"></param>
  208. private float CalculateScale(float _spriteHeight)
  209. {
  210. if (_spriteHeight <= heightBasic)
  211. {
  212. return 1;
  213. }
  214. else
  215. {
  216. return heightBasic / _spriteHeight;
  217. }
  218. }
  219. #region 多语言
  220. public void RefrushLocalization()
  221. {
  222. if (mData.operationStepDataInfo != null)
  223. {
  224. LocalizedString mattersNeedingAttentionText = mData.operationStepDataInfo.id + "stepMattersNeedingAttention";
  225. MattersNeedingAttentionText.text = mattersNeedingAttentionText;
  226. }
  227. }
  228. void OnEnable()
  229. {
  230. LocalizationManager.OnLocalizeEvent += LocalizationManager_OnLocalizeEvent;
  231. LocalizationManager_OnLocalizeEvent();
  232. }
  233. void OnDisEnable()
  234. {
  235. LocalizationManager.OnLocalizeEvent -= LocalizationManager_OnLocalizeEvent;
  236. }
  237. private void LocalizationManager_OnLocalizeEvent()
  238. {
  239. if (LocalizationConfig.localization)
  240. {
  241. RefrushLocalization();
  242. }
  243. }
  244. #endregion
  245. }
  246. }