using UnityEngine;
|
using System.Collections;
|
using vnxbqy.UI;
|
using System;
|
using System.Collections.Generic;
|
using System.IO;
|
|
public class Launch : MonoBehaviour
|
{
|
static int step = 0;
|
static LaunchStage m_CurrentStage = LaunchStage.None;
|
public static ProgressInfo progressInfo { get; private set; }
|
|
float timer = 0f;
|
Queue<LaunchTask> tasks = new Queue<LaunchTask>();
|
LaunchTask currentTask = null;
|
bool launchComplete = false;
|
float surplusProgress = 0f;
|
float surplusTime = 0f;
|
|
void Start()
|
{
|
System.Net.ServicePointManager.DefaultConnectionLimit = 100;//设置http最大连接数
|
Application.backgroundLoadingPriority = ThreadPriority.High;
|
ResourcesPath.Instance.Init();
|
SnxxzGame.Instance.gameObject.name = "__SnxxzGame__";
|
Screen.sleepTimeout = SleepTimeout.NeverSleep;
|
ynmbxxjUtil.Instance.Init(); //原sdk接口
|
|
var builtInAssetCopyTask = new BuiltInAssetCopyTask();
|
var initSettingTask = new InitSettingTask();
|
var sdkInitedTask = new SDKInitedTask();
|
//var assetCopyTask = new AssetCopyTask();
|
//var assetDecompressTask = new AssetDecompressTask();
|
var getVersionInfoTask = new GetVersionInfoTask();
|
var checkAssetValidTask = new CheckAssetValidTask();
|
var downLoadAssetTask = new DownLoadAssetTask();
|
var assetBundleInitTask = new AssetBundleInitTask();
|
var configInitTask = new ConfigInitTask();
|
var launchFadeOutTask = new LaunchFadeOutTask();
|
|
tasks.Enqueue(builtInAssetCopyTask);
|
tasks.Enqueue(initSettingTask);
|
|
|
if (!Application.isEditor)
|
{
|
tasks.Enqueue(sdkInitedTask);
|
}
|
|
switch (Application.platform)
|
{
|
case RuntimePlatform.OSXEditor:
|
case RuntimePlatform.WindowsEditor:
|
tasks.Enqueue(getVersionInfoTask);
|
break;
|
case RuntimePlatform.Android:
|
tasks.Enqueue(getVersionInfoTask);
|
//tasks.Enqueue(assetCopyTask);
|
//tasks.Enqueue(assetDecompressTask);
|
break;
|
case RuntimePlatform.IPhonePlayer:
|
tasks.Enqueue(getVersionInfoTask);
|
//tasks.Enqueue(assetCopyTask);
|
break;
|
case RuntimePlatform.WindowsPlayer:
|
//tasks.Enqueue(assetCopyTask);
|
tasks.Enqueue(getVersionInfoTask);
|
break;
|
}
|
|
tasks.Enqueue(checkAssetValidTask);
|
tasks.Enqueue(downLoadAssetTask);
|
tasks.Enqueue(assetBundleInitTask);
|
tasks.Enqueue(configInitTask);
|
tasks.Enqueue(launchFadeOutTask);
|
|
CalculateExpectTotalTime();
|
|
}
|
|
void Update()
|
{
|
if (!launchComplete)
|
{
|
if (currentTask == null)
|
{
|
if (tasks.Count > 0)
|
{
|
currentTask = tasks.Dequeue();
|
currentTask.Begin();
|
}
|
else
|
{
|
launchComplete = true;
|
}
|
}
|
|
if (currentTask != null)
|
{
|
currentTask.Update();
|
}
|
|
if (currentTask != null && currentTask.done)
|
{
|
currentTask.End();
|
CalculateExpectTotalTime();
|
currentTask = null;
|
}
|
|
if (m_CurrentStage == LaunchStage.DownLoad)
|
{
|
progressInfo = new ProgressInfo(m_CurrentStage, 1, progressInfo.totalProgress, 0f);
|
}
|
else
|
{
|
timer += Time.deltaTime;
|
var progress = progressInfo.totalProgress + surplusProgress * (Time.deltaTime / surplusTime);
|
progress = Mathf.Clamp(progress, 0, 0.98f);
|
|
var partProgress = 0f;
|
if (currentTask == null)
|
{
|
partProgress = 0f;
|
}
|
else
|
{
|
var temp = currentTask.timer / Mathf.Min(2f, currentTask.duration);
|
step = (int)temp + 1;
|
partProgress = temp - (int)temp;
|
}
|
|
progressInfo = new ProgressInfo(m_CurrentStage, step, Mathf.Clamp01(progress), partProgress);
|
}
|
}
|
|
if (launchComplete)
|
{
|
UnityEngine.Debug.LogFormat("启动耗时:{0}", timer);
|
progressInfo = new ProgressInfo(m_CurrentStage, 1, 1f, 1f);
|
this.enabled = false;
|
StageLoad.Instance.PushSceneLoadCommand(new StageLoad.StageLoadCommand()
|
{
|
toMapId = 1,
|
toLineId = 0,
|
needEmpty = false,
|
needLoadResource = true,
|
serverType = ServerType.Main,
|
isClientLoadMap = true
|
});
|
}
|
}
|
|
public static int GetLaunchStage()
|
{
|
return (int)m_CurrentStage;
|
}
|
|
/// <summary>
|
/// 计算总的预期时间
|
/// </summary>
|
void CalculateExpectTotalTime()
|
{
|
surplusTime = 0f;
|
foreach (var item in tasks)
|
{
|
surplusTime += item.expectTime;
|
}
|
|
surplusProgress = 1 - progressInfo.totalProgress;
|
}
|
|
public enum LaunchStage
|
{
|
None = 0,
|
SDKInit = 1,
|
AssetCopy = 2,
|
AssetDecompress = 3,
|
ClientVersion = 4,
|
CheckAsset = 5,
|
DownLoad = 6,
|
AssetBundleInit = 7,
|
ConfigInit = 8,
|
Complete = 9,
|
}
|
|
public abstract class LaunchTask
|
{
|
public float timer { get; protected set; }
|
public float duration { get; protected set; }
|
bool exceptionReported = false;
|
|
public bool done { get; protected set; }
|
public float progress { get; protected set; }
|
public virtual float expectTime { get; protected set; }
|
|
protected float outTime = 15f;
|
|
public abstract void Begin();
|
public abstract void Update();
|
public abstract void End();
|
|
public void ExceptionReport()
|
{
|
if (!exceptionReported && timer > outTime && !done)
|
{
|
var content = string.Format("任务:{0};网络状态:{1}", this.GetType().Name, Application.internetReachability);
|
exceptionReported = true;
|
}
|
}
|
|
}
|
|
public class BuiltInAssetCopyTask : LaunchTask
|
{
|
bool firstLaunch = false;
|
|
public override void Begin()
|
{
|
duration = Mathf.Max(0.2f, expectTime); //非安卓平台的时间,安卓由sdk拷贝完成回调
|
|
if (Application.isEditor)
|
{
|
EditorCopyAsset();
|
}
|
else
|
{
|
//安卓每次由sdk回调拷贝成功,其他平台由unity自己存储标记
|
switch (Application.platform)
|
{
|
case RuntimePlatform.Android:
|
AndroidCopyAsset();
|
break;
|
case RuntimePlatform.IPhonePlayer:
|
IosCopyAsset();
|
break;
|
case RuntimePlatform.WindowsPlayer:
|
StandaloneCopyAsset();
|
break;
|
}
|
}
|
|
if (!firstLaunch)
|
{
|
done = true;
|
}
|
}
|
|
public override void End()
|
{
|
if (!AssetSource.builtInFromEditor)
|
{
|
AssetBundleUtility.Instance.InitBuiltInAsset();
|
}
|
ConfigInitiator.SyncInit();
|
WindowCenter.Instance.DestoryWinsByStage(WindowCenter.WindowStage.Launch);
|
WindowCenter.Instance.OpenFromLocal<LaunchWin>();
|
Language.InitDefaultLanguage();
|
}
|
|
public override void Update()
|
{
|
if (done)
|
{
|
return;
|
}
|
if (!Application.isEditor)
|
{
|
//安卓每次由sdk回调拷贝成功,其他平台由unity自己存储标记
|
if (Application.platform == RuntimePlatform.Android)
|
{
|
AndroidWaitCopyAssetComplete();
|
}
|
else
|
{
|
if (timer > duration)
|
{
|
done = true;
|
}
|
else
|
{
|
done = false;
|
progress = timer / duration;
|
}
|
}
|
}
|
|
|
timer += Time.deltaTime;
|
}
|
|
|
private void AndroidWaitCopyAssetComplete()
|
{
|
if (!ynmbxxjUtil.Instance.AssetCopyFinished)
|
{
|
done = false;
|
progress = timer / duration;
|
}
|
else
|
{
|
done = true;
|
}
|
}
|
|
|
private void AndroidCopyAsset()
|
{
|
if (!ynmbxxjUtil.Instance.AssetCopyFinished)
|
{
|
//每次由sdk回调拷贝成功
|
firstLaunch = true;
|
DebugEx.Log("开始拷贝builtin资源");
|
ynmbxxjUtil.Instance.CopyAsset(1);
|
//ynmbxxjUtil.Instance.CopyOneAsset("builtin_assetbundle");
|
//ynmbxxjUtil.Instance.CopyOneAsset("builtin_assetbundle.manifest");
|
//ynmbxxjUtil.Instance.CopyOneAsset("builtin/musics");
|
//ynmbxxjUtil.Instance.CopyOneAsset("builtin/musics.manifest");
|
//ynmbxxjUtil.Instance.CopyOneAsset("builtin/prefabs");
|
//ynmbxxjUtil.Instance.CopyOneAsset("builtin/prefabs.manifest");
|
//ynmbxxjUtil.Instance.CopyOneAsset("builtin/sprites");
|
//ynmbxxjUtil.Instance.CopyOneAsset("builtin/sprites.manifest");
|
//ynmbxxjUtil.Instance.CopyOneAsset("builtin/animationclips");
|
//ynmbxxjUtil.Instance.CopyOneAsset("builtin/animationclips.manifest");
|
//ynmbxxjUtil.Instance.CopyOneAsset("builtin/materials");
|
//ynmbxxjUtil.Instance.CopyOneAsset("builtin/materials.manifest");
|
//ynmbxxjUtil.Instance.CopyOneAsset("builtin/scriptableobjects");
|
//ynmbxxjUtil.Instance.CopyOneAsset("builtin/scriptableobjects.manifest");
|
|
//ynmbxxjUtil.Instance.CopyOneAsset("builtin/font");
|
//ynmbxxjUtil.Instance.CopyOneAsset("builtin/font.manifest");
|
|
//foreach (var config in ConfigInitiator.builtinConfig)
|
//{
|
// ynmbxxjUtil.Instance.CopyOneAsset("config/" + config);
|
//}
|
|
//AssetDeCompressTask.Decompress(ResourcesPath.Instance.ExternalStorePath);
|
//LocalSave.SetString("BuiltInAssetCopyCompleted_Android", VersionConfig.Get().version);
|
}
|
else
|
DebugEx.Log("builtin资源已经拷贝过了");
|
}
|
|
private void IosCopyAsset()
|
{
|
if (!VersionUtility.Instance.InIosAuditTime())
|
{
|
if (!ynmbxxjUtil.builtinAssetCopyFinished)
|
{
|
firstLaunch = true;
|
var targetDirectory = ResourcesPath.Instance.ExternalStorePath;
|
if (!Directory.Exists(targetDirectory))
|
{
|
Directory.CreateDirectory(targetDirectory);
|
}
|
|
var fileNames = new List<string>();
|
//var files = new List<FileInfo>();
|
//FileExtersion.GetAllDirectoryFileInfos(StringUtility.Contact(ResourcesPath.Instance.StreamingAssetPath, "builtin"), files);
|
//foreach (var file in files)
|
//{
|
// var name = Path.GetFileName(file.FullName);
|
// fileNames.Add(StringUtility.Contact("builtin", Path.DirectorySeparatorChar, name));
|
//}
|
|
//fileNames.Add("builtin_assetbundle");
|
//fileNames.Add("builtin_assetbundle.manifest");
|
|
var configFiles = new List<FileInfo>();
|
FileExtersion.GetAllDirectoryFileInfos(StringUtility.Contact(ResourcesPath.Instance.StreamingAssetPath, "config"), configFiles);
|
foreach (var file in configFiles)
|
{
|
var name = Path.GetFileName(file.FullName);
|
fileNames.Add(StringUtility.Contact("config", Path.DirectorySeparatorChar, name));
|
}
|
|
foreach (var item in fileNames)
|
{
|
var fromPath = StringUtility.Contact(ResourcesPath.Instance.StreamingAssetPath, item);
|
var toPath = StringUtility.Contact(targetDirectory, item);
|
|
var destDirectoryName = Path.GetDirectoryName(toPath);
|
if (!Directory.Exists(destDirectoryName))
|
{
|
Directory.CreateDirectory(destDirectoryName);
|
}
|
|
File.Copy(fromPath, toPath, true);
|
}
|
|
LocalSave.SetString("BuiltInAssetCopyCompleted_IOSorStandalone", VersionConfig.Get().version);
|
}
|
}
|
}
|
|
private void StandaloneCopyAsset()
|
{
|
var targetDirectory = ResourcesPath.Instance.ExternalStorePath;
|
if (!Directory.Exists(targetDirectory))
|
{
|
Directory.CreateDirectory(targetDirectory);
|
}
|
|
var fileNames = new List<string>();
|
//var files = new List<FileInfo>();
|
//FileExtersion.GetAllDirectoryFileInfos(StringUtility.Contact(ResourcesPath.Instance.StreamingAssetPath, "builtin"), files);
|
//foreach (var file in files)
|
//{
|
// var name = Path.GetFileName(file.FullName);
|
// fileNames.Add(StringUtility.Contact("builtin", Path.DirectorySeparatorChar, name));
|
//}
|
|
//fileNames.Add("builtin_assetbundle");
|
//fileNames.Add("builtin_assetbundle.manifest");
|
|
var configFiles = new List<FileInfo>();
|
FileExtersion.GetAllDirectoryFileInfos(StringUtility.Contact(ResourcesPath.Instance.StreamingAssetPath, "config"), configFiles);
|
foreach (var file in configFiles)
|
{
|
var name = Path.GetFileName(file.FullName);
|
fileNames.Add(StringUtility.Contact("config", Path.DirectorySeparatorChar, name));
|
}
|
|
foreach (var item in fileNames)
|
{
|
var fromPath = StringUtility.Contact(ResourcesPath.Instance.StreamingAssetPath, item);
|
var toPath = StringUtility.Contact(targetDirectory, item);
|
|
if (File.Exists(toPath))
|
{
|
continue;
|
}
|
|
var destDirectoryName = Path.GetDirectoryName(toPath);
|
if (!Directory.Exists(destDirectoryName))
|
{
|
Directory.CreateDirectory(destDirectoryName);
|
}
|
|
File.Copy(fromPath, toPath, true);
|
}
|
}
|
|
private void EditorCopyAsset()
|
{
|
if (!AssetSource.allFromEditor)
|
{
|
// FileExtersion.DirectoryCopy(ResourcesPath.CONFIG_FODLER, ResourcesPath.Instance.StreamingAssetPath + "config");
|
// FileExtersion.DirectoryCopy(ResourcesPath.ResourcesOutPath + "BuiltIn", ResourcesPath.Instance.StreamingAssetPath + "builtin");
|
}
|
}
|
|
}
|
|
public class InitSettingTask : LaunchTask
|
{
|
public override float expectTime
|
{
|
get { return LocalSave.GetFloat("InitSettingTask_ExpectTime", 1f); }
|
protected set { LocalSave.SetFloat("InitSettingTask_ExpectTime", value); }
|
}
|
|
public override void Begin()
|
{
|
ShaderUtility.InitGlobalParams();
|
SoundPlayer.CreateSoundPlayer();
|
SoundPlayer.Instance.PlayLoginMusic();
|
|
SystemSetting.Instance.SetSoundVolume(SystemSetting.Instance.GetSoundVolume());
|
SystemSetting.Instance.SetSoundEffect(SystemSetting.Instance.GetSoundEffect());
|
SystemSetting.Instance.SetGameFps(SystemSetting.Instance.GetGameFps());
|
SystemSetting.Instance.LetFPSUnLimit();
|
|
DebugUtility.Instance.Init();
|
DebugUtility.Instance.CreateDebugRoot();
|
|
GameObjectPoolManager.Instance.gameObject.name = "GameObjectPool";
|
GameObjectPoolManager.Instance.Initialize();
|
|
//ExceptionCatcher.Init();
|
//ExceptionCatcher.Catch();
|
|
GlobalTimeEvent.Instance.Begin();
|
PackageRegedit.Init();
|
Clock.Init();
|
|
if (VersionConfig.Get().appId.Equals("test"))
|
{
|
SnxxzGame.Instance.gameObject.AddComponent<PocoManager>();
|
}
|
done = true;
|
}
|
|
public override void End()
|
{
|
expectTime = timer;
|
}
|
|
public override void Update()
|
{
|
timer += Time.deltaTime;
|
}
|
}
|
|
public class SDKInitedTask : LaunchTask
|
{
|
public override float expectTime
|
{
|
get { return LocalSave.GetFloat("SDKInitedTask_ExpectTime", 1f); }
|
protected set { LocalSave.SetFloat("SDKInitedTask_ExpectTime", value); }
|
}
|
|
public override void Begin()
|
{
|
m_CurrentStage = LaunchStage.SDKInit;
|
duration = Mathf.Max(0.1f, expectTime);
|
}
|
|
public override void End()
|
{
|
expectTime = timer;
|
DebugEx.LogFormat("{0}执行时长:{1};", this.GetType().Name, timer);
|
|
OperationLogCollect.Instance.RecordLauchEvent(1);
|
OperationLogCollect.Instance.RecordEvent(1);
|
|
var cpu = 2;
|
var memory = 2048;
|
DeviceUtility.GetCpuAndMemory(out cpu, out memory);
|
DebugEx.LogFormat("获得机器信息:cpu {0}----内存 {1}", cpu, memory);
|
|
}
|
|
public override void Update()
|
{
|
if (done)
|
{
|
return;
|
}
|
|
timer += Time.deltaTime;
|
if (ynmbxxjUtil.Instance.InitFinished)
|
{
|
done = true;
|
}
|
else
|
{
|
done = false;
|
progress = timer / duration;
|
}
|
|
ExceptionReport();
|
}
|
}
|
|
public class AssetCopyTask : LaunchTask
|
{
|
int completedCount = 0;
|
int totalCount = -1;
|
List<FileInfo> copyTasks = new List<FileInfo>();
|
|
public override float expectTime
|
{
|
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.5f, expectTime);
|
outTime = 50f;
|
|
if (Application.isEditor)
|
{
|
done = true;
|
}
|
else
|
{
|
switch (Application.platform)
|
{
|
case RuntimePlatform.Android:
|
AndroidCopyAsset();
|
break;
|
case RuntimePlatform.IPhonePlayer:
|
IOSCopyAsset();
|
break;
|
case RuntimePlatform.WindowsPlayer:
|
StandaloneCopyAsset();
|
break;
|
}
|
}
|
}
|
|
public override void End()
|
{
|
expectTime = timer;
|
DebugEx.LogFormat("{0}执行时长:{1};", this.GetType().Name, timer);
|
|
if (!Application.isEditor)
|
{
|
switch (Application.platform)
|
{
|
case RuntimePlatform.Android:
|
AndroidProcessCopyComplete();
|
break;
|
case RuntimePlatform.IPhonePlayer:
|
IOSProcessCopyComplete();
|
break;
|
}
|
}
|
|
}
|
|
public override void Update()
|
{
|
if (done)
|
{
|
return;
|
}
|
|
timer += Time.deltaTime;
|
|
if (!Application.isEditor)
|
{
|
switch (Application.platform)
|
{
|
case RuntimePlatform.Android:
|
AndroidWaitCopyAssetComplete();
|
break;
|
case RuntimePlatform.IPhonePlayer:
|
case RuntimePlatform.WindowsPlayer:
|
IOSorStandaloneWaitCopyAssetComplete();
|
break;
|
}
|
}
|
|
ExceptionReport();
|
}
|
|
private void AndroidCopyAsset()
|
{
|
switch (VersionConfig.Get().assetAccess)
|
{
|
case InstalledAsset.FullAsset:
|
case InstalledAsset.HalfAsset:
|
case InstalledAsset.IngoreDownLoad:
|
if (!ynmbxxjUtil.Instance.AssetCopyFinished)
|
{
|
ynmbxxjUtil.Instance.CopyAsset();
|
done = false;
|
progress = 0f;
|
}
|
else
|
{
|
done = true;
|
}
|
break;
|
case InstalledAsset.NullAsset:
|
done = true;
|
break;
|
}
|
}
|
|
private void IOSCopyAsset()
|
{
|
if (VersionUtility.Instance.versionInfo != null && VersionUtility.Instance.versionInfo.downAsset == 1)
|
{
|
switch (VersionConfig.Get().assetAccess)
|
{
|
case InstalledAsset.FullAsset:
|
case InstalledAsset.HalfAsset:
|
case InstalledAsset.IngoreDownLoad:
|
if (!ynmbxxjUtil.Instance.AssetCopyFinished)
|
{
|
copyTasks = new List<FileInfo>();
|
FileExtersion.GetAllDirectoryFileInfos(ResourcesPath.Instance.StreamingAssetPath, copyTasks);
|
|
for (var i = copyTasks.Count - 1; i >= 0; i--)
|
{
|
var fileInfo = copyTasks[i];
|
var destPath = fileInfo.FullName.Replace(ResourcesPath.Instance.StreamingAssetPath, ResourcesPath.Instance.ExternalStorePath);
|
if (File.Exists(destPath))
|
{
|
copyTasks.RemoveAt(i);
|
}
|
}
|
|
completedCount = 0;
|
totalCount = copyTasks.Count;
|
}
|
|
if (totalCount > 0)
|
{
|
done = false;
|
progress = 0f;
|
}
|
else
|
{
|
done = true;
|
}
|
break;
|
case InstalledAsset.NullAsset:
|
done = true;
|
break;
|
}
|
}
|
else
|
{
|
done = true;
|
}
|
}
|
|
private void StandaloneCopyAsset()
|
{
|
if (VersionUtility.Instance.versionInfo != null && VersionUtility.Instance.versionInfo.downAsset == 1)
|
{
|
switch (VersionConfig.Get().assetAccess)
|
{
|
case InstalledAsset.FullAsset:
|
case InstalledAsset.HalfAsset:
|
case InstalledAsset.IngoreDownLoad:
|
copyTasks = new List<FileInfo>();
|
FileExtersion.GetAllDirectoryFileInfos(ResourcesPath.Instance.StreamingAssetPath, copyTasks);
|
|
for (var i = copyTasks.Count - 1; i >= 0; i--)
|
{
|
var fileInfo = copyTasks[i];
|
var destPath = fileInfo.FullName.Replace(ResourcesPath.Instance.StreamingAssetPath, ResourcesPath.Instance.ExternalStorePath);
|
if (File.Exists(destPath))
|
{
|
copyTasks.RemoveAt(i);
|
}
|
}
|
|
completedCount = 0;
|
totalCount = copyTasks.Count;
|
|
if (totalCount > 0)
|
{
|
done = false;
|
progress = 0f;
|
}
|
else
|
{
|
done = true;
|
}
|
break;
|
case InstalledAsset.NullAsset:
|
done = true;
|
break;
|
}
|
}
|
else
|
{
|
done = true;
|
}
|
}
|
|
private void AndroidWaitCopyAssetComplete()
|
{
|
if (!ynmbxxjUtil.Instance.AssetCopyFinished)
|
{
|
done = false;
|
progress = timer / duration;
|
}
|
else
|
{
|
done = true;
|
}
|
}
|
|
private void IOSorStandaloneWaitCopyAssetComplete()
|
{
|
if (totalCount > 0)
|
{
|
if (completedCount < totalCount)
|
{
|
var fileInfo = copyTasks[0];
|
var destPath = fileInfo.FullName.Replace(ResourcesPath.Instance.StreamingAssetPath, ResourcesPath.Instance.ExternalStorePath);
|
var destDirectoryName = Path.GetDirectoryName(destPath);
|
if (!Directory.Exists(destDirectoryName))
|
{
|
Directory.CreateDirectory(destDirectoryName);
|
}
|
|
DebugEx.LogFormat("拷贝文件:{0}", fileInfo.Name);
|
File.Copy(fileInfo.FullName, destPath, true);
|
copyTasks.RemoveAt(0);
|
completedCount++;
|
|
done = false;
|
progress = (float)completedCount / totalCount;
|
}
|
else
|
{
|
done = true;
|
}
|
}
|
else
|
{
|
done = true;
|
}
|
}
|
|
private void AndroidProcessCopyComplete()
|
{
|
}
|
|
private void IOSProcessCopyComplete()
|
{
|
LocalSave.SetString("AssetCopyCompleted_IOSorStandalone", VersionConfig.Get().version);
|
}
|
|
}
|
|
public class AssetDecompressTask : LaunchTask
|
{
|
public override float expectTime
|
{
|
get { return LocalSave.GetFloat("AssetDecompressTask_ExpectTime", 5f); }
|
protected set { LocalSave.SetFloat("AssetDecompressTask_ExpectTime", value); }
|
}
|
|
AssetDeCompressTask.DecompressProgress deCompressProgress = null;
|
float waitTimer = 0f;
|
|
public override void Begin()
|
{
|
m_CurrentStage = LaunchStage.AssetDecompress;
|
duration = Mathf.Max(0.5f, expectTime);
|
|
if (!AssetDeCompressTask.assetDeCompressCompleted)
|
{
|
deCompressProgress = AssetDeCompressTask.DecompressAync(ResourcesPath.Instance.ExternalStorePath);
|
done = false;
|
}
|
else
|
{
|
done = true;
|
}
|
}
|
|
public override void End()
|
{
|
AssetDeCompressTask.assetDeCompressVersion = VersionConfig.Get().version;
|
AssetDeCompressTask.Delete7zFiles(ResourcesPath.Instance.ExternalStorePath);
|
}
|
|
public override void Update()
|
{
|
if (done)
|
{
|
return;
|
}
|
|
timer += Time.deltaTime;
|
progress = timer / duration;
|
if (deCompressProgress == null || deCompressProgress.done)
|
{
|
waitTimer += Time.deltaTime;
|
if (waitTimer > 2f)
|
{
|
done = true;
|
}
|
}
|
}
|
|
}
|
|
public class GetVersionInfoTask : LaunchTask
|
{
|
public override float expectTime
|
{
|
get { return LocalSave.GetFloat("GetVersionInfoTask_ExpectTime", 1f); }
|
protected set { LocalSave.SetFloat("GetVersionInfoTask_ExpectTime", value); }
|
}
|
|
public override void Begin()
|
{
|
m_CurrentStage = LaunchStage.ClientVersion;
|
duration = Mathf.Max(0.5f, expectTime);
|
|
if (Application.isEditor)
|
{
|
if (InGameDownTestUtility.enable)
|
{
|
VersionUtility.Instance.RequestVersionCheck();
|
done = false;
|
progress = 0f;
|
}
|
else
|
{
|
done = true;
|
}
|
}
|
else
|
{
|
if (!VersionUtility.Instance.InIosAuditTime())
|
{
|
VersionUtility.Instance.RequestVersionCheck();
|
done = false;
|
progress = 0f;
|
}
|
else
|
{
|
done = true;
|
}
|
}
|
|
}
|
|
public override void End()
|
{
|
expectTime = timer;
|
DebugEx.LogFormat("{0}执行时长:{1};", this.GetType().Name, timer);
|
}
|
|
public override void Update()
|
{
|
if (done)
|
{
|
return;
|
}
|
|
timer += Time.deltaTime;
|
if (!VersionUtility.Instance.completed)
|
{
|
done = false;
|
progress = timer / expectTime;
|
}
|
else
|
{
|
done = true;
|
}
|
|
ExceptionReport();
|
}
|
}
|
|
public class CheckAssetValidTask : LaunchTask
|
{
|
public override float expectTime
|
{
|
get { return LocalSave.GetFloat("CheckAssetValidTask_ExpectTime", 3f); }
|
protected set { LocalSave.SetFloat("CheckAssetValidTask_ExpectTime", value); }
|
}
|
|
public override void Begin()
|
{
|
m_CurrentStage = LaunchStage.CheckAsset;
|
duration = Mathf.Max(0.5f, expectTime);
|
|
ServerListCenter.Instance.RequestJumpUrl();
|
OperationLogCollect.Instance.RecordLauchEvent(2);
|
OperationLogCollect.Instance.RecordEvent(2);
|
|
if (VersionUtility.Instance.NeedDownAsset())
|
{
|
var remoteURL = StringUtility.Contact(VersionUtility.Instance.versionInfo.GetResourcesURL(VersionConfig.Get().branch), Language.fixPath, "/config/PriorBundle.txt");
|
var localURL = StringUtility.Contact(ResourcesPath.Instance.ExternalStorePath, "config/PriorBundle.txt");
|
var downloadTask = new DownloadTask(remoteURL, localURL);
|
downloadTask.BeginDownload(AssetVersionUtility.OnDownLoadPriorBundle);
|
|
//AssetVersionUtility.GetAssetVersionFile();
|
done = false;
|
progress = 0f;
|
}
|
else
|
{
|
//if (Application.isEditor)
|
// PatchLoader.InitLocalPatchAsset();
|
done = true;
|
}
|
}
|
|
public override void End()
|
{
|
expectTime = timer;
|
DebugEx.LogFormat("{0}执行时长:{1};", this.GetType().Name, timer);
|
GameNotice.OpenGameNotice();
|
}
|
|
public override void Update()
|
{
|
if (done)
|
{
|
return;
|
}
|
|
timer += Time.deltaTime;
|
if (!AssetVersionUtility.checkAssetCompleted)
|
{
|
done = false;
|
progress = timer / expectTime;
|
}
|
else
|
{
|
done = true;
|
}
|
|
ExceptionReport();
|
}
|
}
|
|
public class DownLoadAssetTask : LaunchTask
|
{
|
public override float expectTime
|
{
|
get { return LocalSave.GetFloat("DownLoadAssetTask_ExpectTime", 3f); }
|
protected set { LocalSave.SetFloat("DownLoadAssetTask_ExpectTime", value); }
|
}
|
|
public override void Begin()
|
{
|
m_CurrentStage = LaunchStage.DownLoad;
|
outTime = 9999f;
|
duration = Mathf.Max(0.5f, expectTime);
|
if (VersionUtility.Instance.NeedDownAsset())
|
{
|
if (!AssetVersionUtility.priorAssetDownLoadDone)
|
{
|
AssetVersionUtility.BeginDownLoadTask(true);
|
done = false;
|
progress = 0f;
|
}
|
else
|
{
|
done = true;
|
}
|
|
}
|
else
|
{
|
done = true;
|
}
|
}
|
|
public override void End()
|
{
|
expectTime = timer;
|
DebugEx.LogFormat("{0}执行时长:{1};", this.GetType().Name, timer);
|
if (!AssetVersionUtility.unPriorAssetDownLoadDone)
|
{
|
AssetVersionUtility.BeginDownLoadTask(false);
|
}
|
}
|
|
public override void Update()
|
{
|
if (done)
|
{
|
return;
|
}
|
|
timer += Time.deltaTime;
|
if (!AssetVersionUtility.priorAssetDownLoadDone)
|
{
|
done = false;
|
progress = 0f;
|
}
|
else
|
{
|
done = true;
|
}
|
|
ExceptionReport();
|
}
|
|
}
|
|
public class AssetBundleInitTask : LaunchTask
|
{
|
public override float expectTime
|
{
|
get { return LocalSave.GetFloat("AssetBundleInitTask_ExpectTime", 1f); }
|
protected set { LocalSave.SetFloat("AssetBundleInitTask_ExpectTime", value); }
|
}
|
|
public override void Begin()
|
{
|
m_CurrentStage = LaunchStage.AssetBundleInit;
|
|
duration = Mathf.Max(0.5f, expectTime);
|
if (!AssetSource.allFromEditor)
|
{
|
SnxxzGame.Instance.StartCoroutine(AssetBundleUtility.Instance.Initialize());
|
done = false;
|
progress = 0f;
|
}
|
else
|
{
|
done = true;
|
}
|
}
|
|
public override void End()
|
{
|
expectTime = timer;
|
UILoader.LoadWindowAsync("LaunchBackGroundWin", null);
|
DebugEx.LogFormat("{0}执行时长:{1};", this.GetType().Name, timer);
|
}
|
|
public override void Update()
|
{
|
if (done)
|
{
|
return;
|
}
|
|
if (AssetBundleUtility.Instance.initialized && AssetBundleUtility.Instance.initializedUIAssetBundle)
|
{
|
done = true;
|
}
|
else
|
{
|
done = false;
|
progress = timer / duration;
|
}
|
|
ExceptionReport();
|
}
|
}
|
|
public class ConfigInitTask : LaunchTask
|
{
|
public override float expectTime
|
{
|
get { return LocalSave.GetFloat("ConfigInitTask_ExpectTime", 10f); }
|
protected set { LocalSave.SetFloat("ConfigInitTask_ExpectTime", value); }
|
}
|
|
float threshold = 1f;
|
|
public override void Begin()
|
{
|
m_CurrentStage = LaunchStage.ConfigInit;
|
duration = Mathf.Max(0.5f, expectTime);
|
threshold = Application.platform == RuntimePlatform.WindowsEditor ? 1f : 0.9f;
|
|
LaunchPostProcess.Instance.Begin();
|
InitialFunctionConfig.Init(true); //有更新再初始化一次
|
}
|
|
public override void End()
|
{
|
expectTime = timer;
|
DebugEx.LogFormat("{0}执行时长:{1};", this.GetType().Name, timer);
|
OperationLogCollect.Instance.RecordLauchEvent(3);
|
OperationLogCollect.Instance.RecordEvent(3);
|
}
|
|
public override void Update()
|
{
|
if (done)
|
{
|
return;
|
}
|
|
timer += Time.deltaTime;
|
// if (!ConfigInitiator.IsLoginConfigInited)
|
if (!ConfigInitiator.done)
|
{
|
done = false;
|
progress = timer / duration;
|
}
|
else
|
{
|
done = true;
|
}
|
|
ExceptionReport();
|
}
|
|
}
|
|
public class LaunchFadeOutTask : LaunchTask
|
{
|
public override float expectTime
|
{
|
get { return LocalSave.GetFloat("LaunchFadeOutTask_ExpectTime", 1f); }
|
protected set { LocalSave.SetFloat("LaunchFadeOutTask_ExpectTime", value); }
|
}
|
|
public override void Begin()
|
{
|
m_CurrentStage = LaunchStage.Complete;
|
duration = 0.5f;
|
|
ShaderUtility.WarmUpAll();
|
//SpeechTranslate.Instance.RequestGetToken();
|
WindowCenter.Instance.Open<LaunchBackGroundWin>(true);
|
|
var launchWin = WindowCenter.Instance.Get<LaunchWin>();
|
if (launchWin != null)
|
{
|
launchWin.FadeOut();
|
}
|
|
try
|
{
|
LogicLauncher.LaunchStart();
|
}
|
catch (Exception e)
|
{
|
UnityEngine.Debug.LogError(e);
|
}
|
}
|
|
public override void End()
|
{
|
expectTime = timer;
|
DebugEx.LogFormat("{0}执行时长:{1};", this.GetType().Name, timer);
|
|
|
}
|
|
public override void Update()
|
{
|
if (done)
|
{
|
return;
|
}
|
timer += Time.deltaTime;
|
|
if (timer >= 0.5f)//&& ILLauncherProxy.Instance.started)
|
{
|
done = true;
|
}
|
else
|
{
|
done = false;
|
progress = Mathf.Clamp01(timer / expectTime);
|
}
|
|
ExceptionReport();
|
}
|
|
}
|
|
public class WaitTask : LaunchTask
|
{
|
public WaitTask(float seconds)
|
{
|
expectTime = Mathf.Max(0.1f, seconds);
|
}
|
|
public override void Begin()
|
{
|
}
|
|
public override void End()
|
{
|
}
|
|
public override void Update()
|
{
|
timer += Time.deltaTime;
|
|
if (timer >= expectTime)
|
{
|
done = true;
|
}
|
else
|
{
|
done = false;
|
progress = Mathf.Clamp01(timer / expectTime);
|
}
|
}
|
|
}
|
|
|
|
public struct ProgressInfo
|
{
|
public LaunchStage stage;
|
public int step;
|
public float totalProgress;
|
public float partProgress;
|
|
public ProgressInfo(LaunchStage stage, int step, float totalProgress, float partProgress)
|
{
|
this.stage = stage;
|
this.step = step;
|
this.totalProgress = totalProgress;
|
this.partProgress = partProgress;
|
}
|
|
}
|
|
}
|
|