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

相关内容

热门资讯

玩家必看教程外挂工具!微扑克多... 玩家必看教程外挂工具!微扑克多功能外挂工具,微扑克果然是真的有外挂工具1、玩家可以在微扑克线上大神俱...
分享个大家透视挂,白金岛十胡卡... 分享个大家透视挂,白金岛十胡卡多功能透视挂脚本,一两棋牌是有透视挂揭幕;白金岛十胡卡辅助器安装最新版...
玩家科普开挂技巧!微乐小程序免... 玩家科普开挂技巧!微乐小程序免费黑科技,微乐福州麻将开挂多功能方式APP1、下载好微乐小程序免费黑科...
实测教程辅助器工具!WePoK... 实测教程辅助器工具!WePoKer多功能辅助器工具,WePoKer原来是真的有辅助器工具1、打开软件...
细节揭秘透视,牛气冲天多功能透... 细节揭秘透视,牛气冲天多功能透视助手,友间十三张有透视解密;大家肯定在之前友间十三张或者友间十三张中...
重大通报透视挂技巧!微乐小程序... 重大通报透视挂技巧!微乐小程序免费黑科技,微乐保皇透视挂多功能模板APP该软件可以轻松地帮助玩家将微...
分享开挂内幕透视挂教程!wpk... 分享开挂内幕透视挂教程!wpk多功能透视挂教程,wpk本来是有透视挂教程1)wpk有没有挂:进一步探...
关于辅助,家乡广西GL4多功能... 【福星临门,好运相随】;关于辅助,家乡广西GL4多功能辅助教程,新卡农是有辅助总结;暗藏猫腻,小编详...
大家学习交流辅助脚本!微乐小程... 大家学习交流辅助脚本!微乐小程序黑科技免费工具,微乐苏州麻将辅助多功能大纲APP1、打开软件启动之后...
玩家必备攻略外挂软件!德扑之星... 玩家必备攻略外挂软件!德扑之星多功能外挂软件,德扑之星果然是有外挂软件1、操作简单,无需德扑之星手机...