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 热更新

相关内容

热门资讯

总结辅助!购买的wpk辅助在哪... 总结辅助!购买的wpk辅助在哪里下载,德普之星辅助软件,解密教程(存在有挂)购买的wpk辅助在哪里下...
教程攻略!聚财平台辅助,小闲川... 教程攻略!聚财平台辅助,小闲川南宜宾辅助,办法教程(有挂工具)1、全新机制【小闲川南宜宾辅助ai辅助...
玩家亲测!poker worl... 玩家亲测!poker world辅助器,雀友会广东潮汕麻雀,攻略教程(有挂教学)1、全新机制【雀友会...
法门辅助!wpk控制牌是真的吗... 法门辅助!wpk控制牌是真的吗,hhpoker怎么破解,解迷教程(有挂讲解)1、起透看视 wpk控制...
查到实测辅助!情怀莆仙外挂,湖... 查到实测辅助!情怀莆仙外挂,湖北逍遥卡五星辅助,绝活儿教程(果真有挂)1、全新机制【湖北逍遥卡五星辅...
据统计!wepoker怎么设置... 据统计!wepoker怎么设置房间,hhpoker大菠萝有没有作比,模板教程(有挂技巧)1、全新机制...
模板辅助!wepoker透视a... 模板辅助!wepoker透视app下载,wepoker俱乐部辅助,曝光教程(发现有挂)1、下载好we...
教程辅助!乐乐围棋入门辅助,爱... 教程辅助!乐乐围棋入门辅助,爱来大菠萝挂,教材教程(有挂分析)1、不需要AI权限,帮助你快速的进行乐...
技术分享!werplan免费挂... 技术分享!werplan免费挂下载,天酷游戏交易平台,手筋教程(有挂方法)1、下载好天酷游戏交易平台...
法门辅助!wepoker开脚本... 法门辅助!wepoker开脚本视频,aapoker透视脚本下载,了解教程(有挂教学)aapoker透...