| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using QFramework;
- using UnityEngine.Playables;
- using Sirenix.OdinInspector;
- using UnityEngine.UI;
- public class PrincipleGameLanuch : MonoBehaviour
- {
- public Button m_CloseBtn;
- [SerializeField]
- public List<PrincipleInfo> m_PrincipleInfos;
- public PlayableDirector m_PlayableDirector;
- [LabelText("单个直接播放(在只有一个的情况下使用)")]
- public bool singlePlaye;
- public bool isWaitOneFrame = true;
- /// <summary>
- /// 等待一帧防止卡顿
- /// </summary>
- public bool isWaitStartToPlay = false;
- [LabelText("字幕是否使用绝对时间")]
- [InfoBox("若字幕长时间运行出现字幕延迟问题,修改字幕使用绝对时间=true", InfoMessageType.Warning)]
- public bool isUseGlobalTimeBySubTitlesPanel = false;
- [LabelText("临时使用后续删除")]
- public float initTime = 0;
- private void Start()
- {
- isWaitOneFrame = false;
- ResKit.Init();
- foreach (var principleInfo in m_PrincipleInfos)
- {
- if (principleInfo.btn != null)
- {
- principleInfo.btn.onClick.AddListener(() => OnBtnClick(principleInfo));
- }
- }
- if (singlePlaye)
- {
- if (isWaitStartToPlay)
- {
- StartCoroutine(WaitToClick());
- }
- else
- {
- OnBtnClick(m_PrincipleInfos[0]);
- }
- }
- if (m_CloseBtn != null)
- {
- m_CloseBtn.onClick.AddListener(() => Application.Quit());
- }
- }
- IEnumerator WaitToClick()
- {
- yield return new WaitForEndOfFrame();
- OnBtnClick(m_PrincipleInfos[0]);
- }
- private void OnBtnClick(PrincipleInfo principleInfo)
- {
- if (isWaitOneFrame)
- {
- StartCoroutine(WaitOneFrame(principleInfo));
- }
- else
- {
- m_PlayableDirector.playableAsset = principleInfo.playableAsset;
- string tmpName = "原理/" + principleInfo.subTitleName;
- if (initTime == 0)
- {
- UIKit.OpenPanel<SubTitlesPanel>(new SubTitlesPanelData() { m_SubTitleName = tmpName });
- }
- else
- {
- UIKit.OpenPanel<SubTitlesPanel>(new SubTitlesPanelData() { m_SubTitleName = tmpName, initTime = initTime });
- m_PlayableDirector.time = initTime;
- }
- SubTitlesPanel.useGlobalTime = isUseGlobalTimeBySubTitlesPanel;
- m_PlayableDirector.Play();
- }
- }
- IEnumerator WaitOneFrame(PrincipleInfo principleInfo)
- {
- if (m_PlayableDirector != null)
- {
- // 停止播放
- m_PlayableDirector.Pause();
- // 重置时间到0
- m_PlayableDirector.time = 0f;
- // 重新播放
- m_PlayableDirector.Play();
- }
- yield return new WaitForEndOfFrame();
- m_PlayableDirector.playableAsset = principleInfo.playableAsset;
- string tmpName = "原理/" + principleInfo.subTitleName;
- if (initTime == 0)
- {
- UIKit.OpenPanel<SubTitlesPanel>(new SubTitlesPanelData() { m_SubTitleName = tmpName });
- }
- else
- {
- UIKit.OpenPanel<SubTitlesPanel>(new SubTitlesPanelData() { m_SubTitleName = tmpName, initTime = initTime });
- m_PlayableDirector.time = initTime;
- }
- SubTitlesPanel.useGlobalTime = isUseGlobalTimeBySubTitlesPanel;
- m_PlayableDirector.Play();
- }
- }
- [System.Serializable]
- public class PrincipleInfo
- {
- [LabelText("字幕名称")]
- public string subTitleName;
- [LabelText("playableClip")]
- public PlayableAsset playableAsset;
- [LabelText("绑定按钮")]
- public Button btn;
- }
|