using GameFramework.Fsm; using GameFramework.Procedure; using GameFramework.Resource; //using HybridCLR; using System.Collections.Generic; using UnityEngine; using UnityGameFramework.Runtime; namespace GFMain { public class ProcedureBusiness : GameFramework.Procedure.ProcedureBase { protected override void OnInit(IFsm procedureOwner) { base.OnInit(procedureOwner); } protected override void OnEnter(IFsm procedureOwner) { base.OnEnter(procedureOwner); BetterStreamingAssets.Initialize(); #if !UNITY_EDITOR //LoadMetadataForAOTAssemblies(); //MainEntry.Resource.LoadBinary("Assets/_ProjectWuJiang/ProjectWuJiang.dll.bytes", new LoadBinaryCallbacks(OnLoadSuccess, OnLoadFailed)); InitBusiness(); #else InitBusiness(); #endif } /// /// 为aot assembly加载原始metadata, 这个代码放aot或者热更新都行。 /// 一旦加载后,如果AOT泛型函数对应native实现不存在,则自动替换为解释模式执行 /// private static void LoadMetadataForAOTAssemblies() { //List aotMetaAssemblyFiles = new List() //{ // "mscorlib.dll", // "System.dll", // "System.Core.dll", //}; ///// 注意,补充元数据是给AOT dll补充元数据,而不是给热更新dll补充元数据。 ///// 热更新dll不缺元数据,不需要补充,如果调用LoadMetadataForAOTAssembly会返回错误 //HomologousImageMode mode = HomologousImageMode.SuperSet; //foreach (var aotDllName in aotMetaAssemblyFiles) //{ // byte[] dllBytes = BetterStreamingAssets.ReadAllBytes("_MetadataForAOTAssemblies/" + aotDllName + ".bytes"); // // 加载assembly对应的dll,会自动为它hook。一旦aot泛型函数的native函数不存在,用解释器版本代码 // LoadImageErrorCode err = RuntimeApi.LoadMetadataForAOTAssembly(dllBytes, mode); // Debug.Log($"LoadMetadataForAOTAssembly:{aotDllName}. mode:{mode} ret:{err}"); //} } private void OnLoadFailed(string binaryAssetName, LoadResourceStatus status, string errorMessage, object userData) { Log.Error(errorMessage); MainEntry.CommonUI.messageBox.ShowMessage("123"); } private void OnLoadSuccess(string binaryAssetName, byte[] binaryBytes, float duration, object userData) { System.Reflection.Assembly.Load(binaryBytes); Debug.Log(binaryAssetName); InitBusiness(); } private void InitBusiness() { MainEntry.Resource.LoadAsset("Assets/_DTYJ/Scripts/Main/__Main__.prefab", new LoadAssetCallbacks( (assetName, asset, duration, userData) => {//success Object.Instantiate(asset as GameObject).name = "__Main__"; }, (assetName, asset, duration, userData) => {//failure })); } protected override void OnUpdate(IFsm procedureOwner, float elapseSeconds, float realElapseSeconds) { base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds); } } }