using System;
using UnityEngine;
using XGame.Framework.Asset;
using XGame.Framework.Utils;
namespace XGame.Framework
{
///
/// 入口
///
internal static class Entrance
{
///
/// 程序入口
///
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
internal static void Access()
{
Profiler.BeginSample(typeof(Entrance), "Log.Initialize");
Log.Initialize();
Profiler.EndSample();
var async = AssetManager.Init();
async.On(_ =>
{
IsInvalid(errorCode =>
{
if (errorCode != 0)
{
return;
}
Profiler.BeginSample(typeof(Entrance), "AppManager.Initialize");
AppManager.Initialize();
Profiler.EndSample();
});
});
}
private static void IsInvalid(Action callback)
{
var loadAsync = XGameConfig.LoadAsync();
loadAsync.On(_ =>
{
var config = loadAsync.Result;
if (config == null)
{
Log.Error($"Entrance error: 找不到 XGameConfig.asset.");
callback(-1);
return;
}
AppManager.IsSessionDebug = config.isSessionDebug;
var launchSceneName = config.launchSceneName;
var gameLogicTypeName = config.gameLogicTypeName;
XGameConfig.Unload(config);
if (string.IsNullOrEmpty(launchSceneName))
{
Log.Error($"Entrance error: XGameConfig.asset 没有设置启动场景.");
callback(-2);
return;
}
if (!UnityEngine.SceneManagement.SceneManager.GetActiveScene().name.Equals(launchSceneName))
{
Log.Error($"Entrance error: XGameConfig.asset 启动场景没有激活.");
callback(-3);
return;
}
if (string.IsNullOrEmpty(gameLogicTypeName))
{
Log.Error($"Entrance error: XGameConfig.asset 没有设置启动脚本.");
callback(-4);
return;
}
if (Type.GetType(gameLogicTypeName) == null)
{
Log.Error($"Entrance error: XGameConfig.asset 找不到启动脚本. Type:{gameLogicTypeName}");
callback(-5);
return;
}
AppManager.GameLogicTypeName = gameLogicTypeName;
//var assembly = System.Reflection.Assembly.Load(config.launchAssemblyName);
//assembly.GetType(gameLogicTypeName);
callback(0);
});
}
}
}