12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using System;
- using UnityEngine;
- using XGame.Framework.Asset;
- using XGame.Framework.Utils;
- namespace XGame.Framework
- {
- /// <summary>
- /// 入口
- /// </summary>
- internal static class Entrance
- {
- /// <summary>
- /// 程序入口
- /// </summary>
- [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<int> 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);
- });
-
- }
- }
- }
|