| | |
| | | {
|
| | | static LaunchStage m_CurrentStage = LaunchStage.None;
|
| | |
|
| | | static int step = 0;
|
| | | public static ProgressInfo progressInfo { get; private set; }
|
| | |
|
| | | private void Awake()
|
| | |
| | | }
|
| | |
|
| | | float timer = 0f;
|
| | | float progressRateOfIncrease = 1f;
|
| | | float originalExpectTotalTime = -1f;
|
| | | float expectTotalTime = 0f;
|
| | | public float totalTime {
|
| | | get {
|
| | | return Mathf.Lerp(originalExpectTotalTime, expectTotalTime, Mathf.Clamp01(timer / expectTotalTime));
|
| | | }
|
| | | }
|
| | |
|
| | | Queue<LaunchTask> tasks = new Queue<LaunchTask>();
|
| | | LaunchTask currentTask = null;
|
| | | bool launchComplete = false;
|
| | | float surplusProgress = 0f;
|
| | | float surplusTime = 0f;
|
| | |
|
| | | void Start()
|
| | | {
|
| | | WindowCenter.Instance.DestoryWinsByStage(WindowCenter.WindowStage.Launch);
|
| | | AssetBundleUtility.Instance.UnloadAssetBundle("builtin/prefabs", true, false);
|
| | |
|
| | | Application.backgroundLoadingPriority = ThreadPriority.High;
|
| | | SoundPlayer.Instance.PlayLoginMusic();
|
| | | Config.Instance.PreLoadConfigs();
|
| | |
| | | Config.Instance.RegisterGlobalEvent();
|
| | | PackageRegedit.Init();
|
| | | DebugUtility.Instance.CreateDebugRoot();
|
| | |
|
| | | WindowCenter.Instance.OpenFromLocal<LaunchWin>();
|
| | |
|
| | | var sdkInitedTask = new SDKInitedTask();
|
| | |
| | | tasks.Enqueue(launchFadeOutTask);
|
| | |
|
| | | CalculateExpectTotalTime();
|
| | | originalExpectTotalTime = expectTotalTime;
|
| | | }
|
| | |
|
| | | void Update()
|
| | |
| | |
|
| | | if (m_CurrentStage == LaunchStage.DownLoad)
|
| | | {
|
| | | progressInfo = new ProgressInfo(m_CurrentStage, progressInfo.totalProgress, 0f);
|
| | | progressInfo = new ProgressInfo(m_CurrentStage, 1, progressInfo.totalProgress, 0f);
|
| | | }
|
| | | else
|
| | | {
|
| | | timer += Time.deltaTime;
|
| | | var progress = progressInfo.totalProgress + progressRateOfIncrease * Time.deltaTime / totalTime;
|
| | | var progress = progressInfo.totalProgress + surplusProgress * (Time.deltaTime / surplusTime);
|
| | | progress = Mathf.Clamp(progress, 0, 0.98f);
|
| | |
|
| | | var partProgress = 0f;
|
| | | if (currentTask == null)
|
| | |
| | | }
|
| | | else
|
| | | {
|
| | | var temp = currentTask.timer / Mathf.Min(1f, currentTask.duration);
|
| | | var temp = currentTask.timer / Mathf.Min(2f, currentTask.duration);
|
| | | step = (int)temp + 1;
|
| | | partProgress = temp - (int)temp;
|
| | | }
|
| | |
|
| | | progressInfo = new ProgressInfo(m_CurrentStage, Mathf.Clamp01(progress), partProgress);
|
| | | progressInfo = new ProgressInfo(m_CurrentStage, step, Mathf.Clamp01(progress), partProgress);
|
| | | }
|
| | | }
|
| | |
|
| | | if (launchComplete)
|
| | | {
|
| | | Debug.LogFormat("启动耗时:{0}", timer);
|
| | | progressInfo = new ProgressInfo(m_CurrentStage, 1f, 1f);
|
| | | progressInfo = new ProgressInfo(m_CurrentStage, 1, 1f, 1f);
|
| | | this.enabled = false;
|
| | | StageManager.Instance.LoadLoginStage();
|
| | | }
|
| | |
| | |
|
| | | void CalculateExpectTotalTime()
|
| | | {
|
| | | var time = timer;
|
| | | foreach (var item in tasks)
|
| | | {
|
| | | time += item.expectTime;
|
| | | surplusTime = 0f;
|
| | | foreach (var item in tasks) |
| | | { |
| | | surplusTime += item.expectTime; |
| | | }
|
| | |
|
| | | expectTotalTime = time;
|
| | | if (originalExpectTotalTime <= 0f)
|
| | | {
|
| | | originalExpectTotalTime = expectTotalTime;
|
| | | }
|
| | |
|
| | | progressRateOfIncrease = (expectTotalTime - timer) / (originalExpectTotalTime - timer);
|
| | | surplusProgress = 1 - progressInfo.totalProgress;
|
| | | }
|
| | |
|
| | | public enum LaunchStage
|
| | |
| | | None = 0,
|
| | | SDKInit = 1,
|
| | | AssetCopy = 2,
|
| | | ClientVersion = 3,
|
| | | CheckAsset = 4,
|
| | | DownLoad = 5,
|
| | | AssetBundleInit = 6,
|
| | | ConfigInit = 7,
|
| | | Complete = 8,
|
| | | AssetDecompress=3,
|
| | | ClientVersion = 4,
|
| | | CheckAsset = 5,
|
| | | DownLoad = 6,
|
| | | AssetBundleInit = 7,
|
| | | ConfigInit = 8,
|
| | | Complete = 9,
|
| | | }
|
| | |
|
| | | public abstract class LaunchTask
|
| | |
| | | var memory = 2048;
|
| | | DeviceUtility.GetCpuAndMemory(out cpu, out memory);
|
| | | DebugEx.LogFormat("获得机器信息:cpu {0}----内存 {1}", cpu, memory);
|
| | | GameNotice.OpenGameNotice();
|
| | | }
|
| | |
|
| | | public override void Update()
|
| | |
| | | List<FileInfo> copyTasks = new List<FileInfo>();
|
| | |
|
| | | public override float expectTime {
|
| | | get { return LocalSave.GetFloat("AssetCopyTask_ExpectTime", 30f); }
|
| | | get { return LocalSave.GetFloat("AssetCopyTask_ExpectTime", 70f); }
|
| | | protected set { LocalSave.SetFloat("AssetCopyTask_ExpectTime", value); }
|
| | | }
|
| | |
|
| | | public override void Begin()
|
| | | {
|
| | | m_CurrentStage = LaunchStage.AssetCopy;
|
| | | duration = Mathf.Max(0.1f, expectTime);
|
| | | duration = Mathf.Max(0.5f, expectTime);
|
| | | outTime = 50f;
|
| | | #if UNITY_ANDROID
|
| | | switch (VersionConfig.Get().assetAccess)
|
| | |
| | |
|
| | | public override void Begin()
|
| | | {
|
| | | m_CurrentStage = LaunchStage.AssetCopy;
|
| | | duration = Mathf.Max(0.1f, expectTime);
|
| | | m_CurrentStage = LaunchStage.AssetDecompress;
|
| | | duration = Mathf.Max(0.5f, expectTime);
|
| | |
|
| | | if (!AssetDeCompressTask.assetDeCompressCompleted)
|
| | | {
|
| | |
| | | public override void Begin()
|
| | | {
|
| | | m_CurrentStage = LaunchStage.ClientVersion;
|
| | | duration = expectTime;
|
| | | duration = Mathf.Max(0.5f, expectTime);
|
| | |
|
| | | #if UNITY_ANDROID
|
| | | if (InGameDownTestUtility.enable || !Application.isEditor)
|
| | |
| | | public override void Begin()
|
| | | {
|
| | | m_CurrentStage = LaunchStage.CheckAsset;
|
| | | duration = Mathf.Max(0.1f, expectTime);
|
| | | duration = Mathf.Max(0.5f, expectTime);
|
| | |
|
| | | ServerListCenter.Instance.RequestJumpUrl();
|
| | | OperationLogCollect.Instance.RecordLauchEvent(2);
|
| | |
| | | {
|
| | | expectTime = timer;
|
| | | DebugEx.LogFormat("{0}执行时长:{1};", this.GetType().Name, timer);
|
| | | GameNotice.OpenGameNotice();
|
| | | }
|
| | |
|
| | | public override void Update()
|
| | |
| | | {
|
| | | m_CurrentStage = LaunchStage.DownLoad;
|
| | |
|
| | | duration = Mathf.Max(0.1f, expectTime);
|
| | | duration = Mathf.Max(0.5f, expectTime);
|
| | | if (VersionUtility.Instance.NeedDownAsset())
|
| | | {
|
| | | if (!AssetVersionUtility.priorAssetDownLoadDone)
|
| | |
| | | {
|
| | | m_CurrentStage = LaunchStage.AssetBundleInit;
|
| | |
|
| | | duration = Mathf.Max(0.1f, expectTime);
|
| | | duration = Mathf.Max(0.5f, expectTime);
|
| | | if (!AssetSource.allFromEditor)
|
| | | {
|
| | | AssetBundleUtility.Instance.Sync_LoadAll("ui/prioritywindow");
|
| | |
| | | public override void End()
|
| | | {
|
| | | expectTime = timer;
|
| | | UILoader.LoadWindowAsync("LaunchBackGroundWin", null);
|
| | | DebugEx.LogFormat("{0}执行时长:{1};", this.GetType().Name, timer);
|
| | | }
|
| | |
|
| | |
| | | public class ConfigInitTask : LaunchTask
|
| | | {
|
| | | public override float expectTime {
|
| | | get { return LocalSave.GetFloat("ConfigInitTask_ExpectTime", inferredTime); }
|
| | | get { return LocalSave.GetFloat("ConfigInitTask_ExpectTime", 10f); }
|
| | | protected set { LocalSave.SetFloat("ConfigInitTask_ExpectTime", value); }
|
| | | }
|
| | |
|
| | | float threshold = 1f;
|
| | | float inferredTime = 3f;
|
| | |
|
| | | public override void Begin()
|
| | | {
|
| | | inferredTime = LocalSave.GetFloat("AssetCopyTask_ExpectTime", 30f) / 30f * 10f;
|
| | |
|
| | | m_CurrentStage = LaunchStage.ConfigInit;
|
| | | duration = Mathf.Max(0.1f, expectTime);
|
| | | duration = Mathf.Max(0.5f, expectTime);
|
| | | threshold = Application.platform == RuntimePlatform.WindowsEditor ? 1f : 0.9f;
|
| | |
|
| | | LaunchPostProcess.Instance.Begin();
|
| | |
| | | protected set { LocalSave.SetFloat("LaunchFadeOutTask_ExpectTime", value); }
|
| | | }
|
| | |
|
| | | bool launchBackGroundLoadedOk = false;
|
| | | bool openBackGround = false;
|
| | |
|
| | | public override void Begin()
|
| | | {
|
| | | m_CurrentStage = LaunchStage.Complete;
|
| | | duration = Mathf.Max(0.1f, expectTime);
|
| | | duration = Mathf.Max(0.5f, expectTime);
|
| | |
|
| | | LuaUtility.Instance.Init();
|
| | | CSharpCallLua.Init();
|
| | | ShaderUtility.WarmUpAll();
|
| | | SpeechTranslate.Instance.RequestGetToken();
|
| | | UI3DModelExhibition.CreateStage();
|
| | |
|
| | | WindowCenter.Instance.Open<LaunchBackGroundWin>(true);
|
| | | var launchWin = WindowCenter.Instance.Get<LaunchWin>();
|
| | | if (launchWin != null)
|
| | | {
|
| | | launchWin.FadeOut();
|
| | | }
|
| | |
|
| | | UILoader.LoadWindowAsync("LaunchBackGroundWin",
|
| | | (bool ok, UnityEngine.Object @object) =>
|
| | | {
|
| | | if (ok)
|
| | | {
|
| | | launchBackGroundLoadedOk = true;
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | public override void End()
|
| | | {
|
| | | expectTime = timer;
|
| | | DebugEx.LogFormat("{0}执行时长:{1};", this.GetType().Name, timer);
|
| | | if (!openBackGround)
|
| | | {
|
| | | WindowCenter.Instance.Open<LaunchBackGroundWin>(true);
|
| | | }
|
| | |
|
| | | var launchBackGroundWin = WindowCenter.Instance.Get<LaunchBackGroundWin>();
|
| | | launchBackGroundWin.transform.SetAsFirstSibling();
|
| | |
| | | return;
|
| | | }
|
| | | timer += Time.deltaTime;
|
| | |
|
| | | if (!openBackGround)
|
| | | {
|
| | | if (launchBackGroundLoadedOk)
|
| | | {
|
| | | WindowCenter.Instance.Open<LaunchBackGroundWin>();
|
| | | openBackGround = true;
|
| | | }
|
| | | }
|
| | |
|
| | | if (timer >= expectTime)
|
| | | {
|
| | |
| | | public struct ProgressInfo
|
| | | {
|
| | | public LaunchStage stage;
|
| | | public int step;
|
| | | public float totalProgress;
|
| | | public float partProgress;
|
| | |
|
| | | public ProgressInfo(LaunchStage stage, float totalProgress, float partProgress)
|
| | | public ProgressInfo(LaunchStage stage, int step, float totalProgress, float partProgress)
|
| | | {
|
| | | this.stage = stage;
|
| | | this.step = step;
|
| | | this.totalProgress = totalProgress;
|
| | | this.partProgress = partProgress;
|
| | | }
|