/// <summary> /// 整个游戏的启动器 /// </summary> /// <param name="mainProjectTypes">游戏逻辑域传过来的所有type</param> static public void Start(Type[] mainProjectTypes = null, Type[] hotfixTypes = null) { //UI组件类型注册 List <Type> types = new List <Type>(); types.AddRange(typeof(Button).Assembly.GetTypes()); //Unity types.AddRange(typeof(IButton).Assembly.GetTypes()); //BDFramework.Core types.AddRange(mainProjectTypes); //游戏业务逻辑 if (Application.isEditor) { types = types.Distinct().ToList(); } //ui类型 var uitype = typeof(UIBehaviour); for (int i = 0; i < types.Count; i++) { var type = types[i]; //注册所有uiComponent bool ret = type.IsSubclassOf(uitype); if (ret) { if (!ILRuntimeHelper.UIComponentTypes.ContainsKey(type.Name)) { //因为Attribute typeof(Type)后无法获取fullname ILRuntimeHelper.UIComponentTypes[type.FullName] = type; } else { BDebug.LogError("有重名UI组件,请注意" + type.FullName); } } } //执行主工程逻辑 BDebug.Log("主工程Instance初始化...", "red"); ManagerInstHelper.Load(mainProjectTypes); //执行热更逻辑 if (hotfixTypes != null) { TriggerHotFixGameStart(hotfixTypes); //获取管理器列表,开始工作 BDebug.Log("热更Instance初始化...", "red"); var hotfixMgrList = ILRuntimeManagerInstHelper.LoadManagerInstance(hotfixTypes); //启动热更管理器 foreach (var hotfixMgr in hotfixMgrList) { hotfixMgr.Start(); } } else { //热更逻辑为空,触发主工程的GameStart TriggerHotFixGameStart(mainProjectTypes); //启动著工程的管理器 ManagerInstHelper.Start(); } }
/// <summary> /// 初始化框架编辑器 /// </summary> static public void InitEditorEnvironment() { //是否为batchmode if (Application.isBatchMode) { Debug.Log("BDFramework version:" + BDLauncher.Version); } //只有在非Playing的时候才初始化 if (EditorApplication.isPlayingOrWillChangePlaymode || IsInited) { return; } try { //BD初始化 //BApplication.Init(); //BDEditor初始化 BDEditorApplication.Init(); //加载主工程的DLL Type var assemblyPath = BApplication.Library + "/ScriptAssemblies/Assembly-CSharp.dll"; var editorAssemlyPath = BApplication.Library + "/ScriptAssemblies/Assembly-CSharp-Editor.dll"; if (File.Exists(assemblyPath) && File.Exists(editorAssemlyPath)) { var gAssembly = Assembly.LoadFile(assemblyPath); var eAssemlby = Assembly.LoadFile(editorAssemlyPath); Types = CollectTypes(gAssembly, eAssemlby).ToArray(); } //编辑器下加载初始化 BResources.Init(AssetLoadPathType.Editor); //编辑器下管理器注册 ManagerInstHelper.Load(Types); //Editor的管理器初始化 BDFrameworkPipelineHelper.Init(); //调试器启动 DebuggerServerProcessManager.Inst.Start(); //Pipeline初始化 HotfixPipelineTools.Init(); //编辑器初始化 InitEditorTask(); //编辑器任务 EditorTaskInstance.OnUnityLoadOrCodeRecompiled(); //编辑器http服务 InitEditorHttpServer(); //最后,完成初始化 IsInited = true; // Debug.Log("框架编辑器环境初始化成功!"); } catch (Exception e) { Debug.LogError("框架编辑器环境初始化失败!"); Debug.LogError(e); throw; } }