using System; using System.Collections; using System.Reflection; using UnityEngine; using EventManager = UnityEngine.Gonbest.MagicCube.EventManager; using EventSystemHandler = UnityEngine.Gonbest.MagicCube.EventSystemHandler; using EventMessage = UnityEngine.Gonbest.MagicCube.EventMessage; using PreLoadEventDefine = UnityEngine.Gonbest.MagicCube.PreLoadEventDefine; namespace Thousandto.UpdateForm.Center { /// /// 程序集加载器 /// public class AssemblyLoader { #region //成员变量定义 //动态库文件 private static string[] _dllfiles = new string[] { "References/ThousandtoDeclare/ThousandtoDeclare.bytes", null, "References/ThousandtoCore/ThousandtoCore.bytes", "References/ThousandtoLogic/ThousandtoLogic.bytes", "References/ThousandtoUIForm/ThousandtoUIForm.bytes", null, "References/ThousandtoBase/ThousandtoBase.bytes", }; //加载dll处理的回调 private static Func _callBack = null; //逻辑程序集 private static Assembly _logicAssembly = null; //ui程序集 private static Assembly _uiAssembly = null; // private static Assembly _coreAssembly = null; #endregion #region //成员属性定义 //获取逻辑程序集 private static Assembly LogicAssembly { get { if (_logicAssembly == null) { LoadAllDll(); } return _logicAssembly; } } //获取UI的程序集 private static Assembly UIAssembly { get { if (_uiAssembly == null) { LoadAllDll(); } return _uiAssembly; } } #endregion #region //对外接口 //设置程序集加载的处理器 -- 用于给Luncher程序调用 public static void SetLoadAssemblyHandler(Func callBack) { _callBack = callBack; } //创建游戏中心的对象 public static void CreateGameCenterGo() { #if FUNCELL_UNUSED_DLL //不使用动态库的情况下使用类型直接获取. var gameStartup = typeof(Thousandto.Code.Center.GameStartup); #else var gameStartup = UIAssembly.GetType("Thousandto.Code.Center.GameStartup"); #endif System.Collections.Generic.List args = new System.Collections.Generic.List(); //fix yy //args.Add("-lang"); #if !UNITY_EDITOR || FUNCELL_LAUNCHER args.Add(UnityEngine.Gonbest.MagicCube.FLanguage.Default); #endif if (LauncherUpdate.StartupArgs != null) { args.AddRange(LauncherUpdate.StartupArgs); } gameStartup.InvokeMember("Main", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static, null, null, new object[] { args.ToArray() } ); } //进入游戏 public static IEnumerator EnterGame() { EventManager.SharedInstance.PushFixEvent(PreLoadEventDefine.EID_STEP_START, 1); yield return null; LoadAllDll(); yield return null; CreateGameCenterGo(); yield return null; } //创建游戏中心的对象 public static void CreateGameCenterGo(Action callback) { if (callback == null) { CreateGameCenterGo(); } else { callback(); } } #endregion #region//私有成员函数 //加载所有的动态库 private static void LoadAllDll() { if (_callBack != null) { //load base dll _callBack(6, _dllfiles[6]); for (int i = 0; i < _dllfiles.Length; i++) { if (i == 2) { _coreAssembly = _callBack(i, _dllfiles[i]); } else if (i == 3) { _logicAssembly = _callBack(i, _dllfiles[i]); } else if (i == 4) { _uiAssembly = _callBack(i, _dllfiles[i]); } else { _callBack(i, _dllfiles[i]); } } } else { _logicAssembly = Assembly.GetCallingAssembly(); _uiAssembly = Assembly.GetCallingAssembly(); } } #endregion } }