You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
2.2 KiB
107 lines
2.2 KiB
3 years ago
|
using System.Threading;
|
||
|
using UnityEngine;
|
||
|
using YooAsset;
|
||
|
|
||
|
namespace ET
|
||
|
{
|
||
|
// 1 mono模式 2 ILRuntime模式 3 mono热重载模式
|
||
|
public enum CodeMode
|
||
|
{
|
||
|
Mono = 1,
|
||
|
ILRuntime = 2,
|
||
|
Reload = 3,
|
||
|
}
|
||
|
|
||
|
public class Init: MonoBehaviour
|
||
|
{
|
||
|
public CodeMode CodeMode = CodeMode.Mono;
|
||
|
public YooAssets.EPlayMode PlayMode = YooAssets.EPlayMode.EditorSimulateMode;
|
||
|
|
||
|
private void Awake()
|
||
|
{
|
||
|
#if ENABLE_IL2CPP
|
||
|
this.CodeMode = CodeMode.ILRuntime;
|
||
|
#endif
|
||
|
|
||
|
System.AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
|
||
|
{
|
||
|
Log.Error(e.ExceptionObject.ToString());
|
||
|
};
|
||
|
|
||
|
SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
|
||
|
|
||
|
DontDestroyOnLoad(gameObject);
|
||
|
|
||
|
LitJson.UnityTypeBindings.Register();
|
||
|
|
||
|
ETTask.ExceptionHandler += Log.Error;
|
||
|
|
||
|
Log.ILog = new UnityLogger();
|
||
|
|
||
|
Options.Instance = new Options();
|
||
|
|
||
|
CodeLoader.Instance.CodeMode = this.CodeMode;
|
||
|
Options.Instance.Develop = 1;
|
||
|
Options.Instance.LogLevel = 0;
|
||
|
|
||
|
FUIEntry.Init();
|
||
|
|
||
|
this.CheckUpdate().Coroutine();
|
||
|
}
|
||
|
|
||
|
// private void Start()
|
||
|
// {
|
||
|
// CodeLoader.Instance.Start();
|
||
|
// }
|
||
|
|
||
|
private async ETTask CheckUpdate()
|
||
|
{
|
||
|
if (this.PlayMode == YooAssets.EPlayMode.HostPlayMode)
|
||
|
{
|
||
|
FUICheckUpdateComponent.Init();
|
||
|
}
|
||
|
|
||
|
await YooAssetWrapper.InitializeAsync(this.PlayMode);
|
||
|
int version = await YooAssetWrapper.UpdateStaticVersion();
|
||
|
Debug.Log(version);
|
||
|
var result = await YooAssetWrapper.UpdateManifest(version);
|
||
|
|
||
|
if (!result)
|
||
|
{
|
||
|
FUICheckUpdateComponent.SetMessage("Update Manifest Failed");
|
||
|
}
|
||
|
|
||
|
YooAssetWrapper.GetDownloadSize();
|
||
|
result = await YooAssetWrapper.Download();
|
||
|
if (result)
|
||
|
{
|
||
|
if (this.PlayMode == YooAssets.EPlayMode.HostPlayMode)
|
||
|
{
|
||
|
FUICheckUpdateComponent.RemoveUI();
|
||
|
}
|
||
|
|
||
|
CodeLoader.Instance.Start();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
FUICheckUpdateComponent.SetMessage("Download Resource Failed");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void Update()
|
||
|
{
|
||
|
CodeLoader.Instance.Update?.Invoke();
|
||
|
}
|
||
|
|
||
|
private void LateUpdate()
|
||
|
{
|
||
|
CodeLoader.Instance.LateUpdate?.Invoke();
|
||
|
}
|
||
|
|
||
|
private void OnApplicationQuit()
|
||
|
{
|
||
|
CodeLoader.Instance.OnApplicationQuit();
|
||
|
CodeLoader.Instance.Dispose();
|
||
|
}
|
||
|
}
|
||
|
}
|