xLua | xLua Framework | 2 加载
创始人
2024-11-17 14:10:07
0

0. 基础

0.1 不同加载模式 测试用

编辑器模式;打包模式;更新模式

public enum GameMode {     EditorMode,     PackageBundle,     UpdateMode, }
0.2 加载资源步骤与接口

     private void LoadAsset(string assetName, Action action) {     if (AppConst.GameMode == GameMode.EditorMode)     { #if UNITY_EDITOR         EditorLoadAsset(assetName, action); #else         Debug.LogError("Editor mode is not supported in the built version."); #endif     }     else     {         StartCoroutine(LoadBundleAsync(assetName, action));     } } 
0.3 解析版本文件

///  /// 解析版本文件 ///  public void ParseVersionFile() {     //版本文件路径     string url = Path.Combine(PathUtil.BundleResourcePath, AppConst.FileListName);     string[] data = File.ReadAllLines(url);      //解析文件信息     for (int i = 0; i < data.Length; i++)     {         string[] info = data[i].Split('|');          BundleInfo bundleinfo = new BundleInfo()         {             AssetsName = info[0],             BundleName = info[1]         };          //list特性:本质是数组但可动态扩容         bundleinfo.Dependences = new List(info.Length - 2);         for (int j = 2; j < info.Length; j++)         {             bundleinfo.Dependences.Add(info[j]);         }         m_BundleInfos.Add(bundleinfo.AssetsName, bundleinfo);     } }

1. 打包模式加载资源

递归异步加载资源:
根据资源的依赖关系递归加载所有需要的资源包,并最终加载目标资源,加载完成后调用回调函数处理加载资源。

///  /// 递归异步加载资源 ///  ///  ///  ///  IEnumerator LoadBundleAsync(string assetName, Action action = null) {     string bundleName = m_BundleInfos[assetName].BundleName;     string bundlePath = Path.Combine(PathUtil.BundleResourcePath, bundleName);     List dependences = m_BundleInfos[assetName].Dependences;     if (dependences != null && dependences.Count > 0)     {         for (int i = 0; i < dependences.Count; i++)         {             yield return LoadBundleAsync(dependences[i]);         }     }      AssetBundleCreateRequest request = AssetBundle.LoadFromFileAsync(bundlePath);     yield return request;      AssetBundleRequest bundleRequest = request.assetBundle.LoadAssetAsync(assetName);     yield return bundleRequest;      //Log     Debug.LogFormat("Package Bundle Mode Load Resource : {0}", assetName);      action?.Invoke(bundleRequest?.asset); } 

2. 编辑器模式加载资源

///  /// 编辑器模式加载资源 ///  ///  ///  #if UNITY_EDITOR void EditorLoadAsset(string assetName, Action actioin = null) {     //Log     Debug.LogFormat("Editor Mode Load Resource : {0}", assetName);      Object obj = UnityEditor.AssetDatabase.LoadAssetAtPath(assetName, typeof(Object));     if (obj == null)         Debug.LogError("Asset name is not exist" + assetName);      actioin?.Invoke(obj); } #endif 

3. 更新模式加载资源

详见3 热更新

相关内容

热门资讯

突发!hhpoker透视脚本下... 突发!hhpoker透视脚本下载,德普之星透视辅助软件下载,一贯是真的有挂(有挂教学)德普之星透视辅...
代打辅助挂!wpk俱乐部是做什... 代打辅助挂!wpk俱乐部是做什么的,德普软件,一直存在有挂(有挂神器)德普软件辅助器是一种具有地方特...
2026版教学!pokemmo... 2026版教学!pokemmo辅助器手机版下载,德普之星透视辅助,切实是有挂(有挂详细)1、该软件可...
教程辅助挂!wepoker插件... 教程辅助挂!wepoker插件辅助,德普之星私人局辅助器,果然真的有挂(今日头条)1、玩家可以在德普...
一直以来!cloudpoker... 一直以来!cloudpoker外挂,德扑之星透视软件免费入口官网,本来是真的有挂(竟然有挂)1、德扑...
做出回应!wepoker游戏安... 做出回应!wepoker游戏安装教程,智星菠萝透视,竟然存在有挂(的确有挂)亲,关键说明,智星菠萝透...
今日!wepoker免费辅助器... 今日!wepoker免费辅助器,德普之星app安卓版破解版,确实是有挂(有挂细节)1、很好的工具软件...
总结辅助挂!德普之星辅助工具如... 总结辅助挂!德普之星辅助工具如何打开,德扑之星怎么开辅助,一直真的有挂(证实有挂)1、下载好德普之星...
黑科技插件!hhpoker透视... 黑科技插件!hhpoker透视方法,德扑圈有透视吗,真是存在有挂(有挂总结)1、下载好德扑圈有透视吗...
第三方插件!wejoker辅助... 第三方插件!wejoker辅助软件,智星菠萝辅助,一直是真的有挂(有挂解密)1、全新机制【智星菠萝辅...