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

相关内容

热门资讯

第5分钟解说!胡莱三国辅助工具... 第5分钟解说!胡莱三国辅助工具(外挂透视)原来有挂下载(分析开挂安装);胡莱三国辅助工具AI智能教程...
技法外挂!wepoker有透视... 技法外挂!wepoker有透视功能吗,大菠萝手游辅助,技巧教程(有挂规律)-哔哩哔哩;无需打开直接搜...
九分钟领会!闲逸510k辅助软... 九分钟领会!闲逸510k辅助软件,约局吧破解器,我来教教你(存在有挂)-哔哩哔哩;相信小伙伴都知道这...
4分钟得知!新道游透视脚本免费... 4分钟得知!新道游透视脚本免费下载(外挂)原来真的有挂平台(传授开挂插件);1.新道游透视脚本免费下...
方针外挂!德普之星透视辅助软件... 方针外挂!德普之星透视辅助软件下载,xpoker辅助怎么用,系统教程(新版有挂)-哔哩哔哩>>您好:...
5分钟领会!蜜瓜大厅辅助免费下... 5分钟领会!蜜瓜大厅辅助免费下载,德普之星辅助工具如何打开,可靠教程(有挂方略)-哔哩哔哩;1.蜜瓜...
两分钟透视!九神大厅辅助(外挂... 两分钟透视!九神大厅辅助(外挂透视)原来真的有挂插件(曝光开挂软件);1、点击下载安装,九神大厅辅助...
总结外挂!约局吧辅助脚本,we... 总结外挂!约局吧辅助脚本,wepoker私人局透视教程,细节方法(有挂技术)-哔哩哔哩 >>您好:软...
第4分钟精通!德普之星透视辅助... 第4分钟精通!德普之星透视辅助,hhpoker有透视功能吗,解密教程(存在有挂)-哔哩哔哩相信很多朋...
7分钟普及!小闲辅助软件(外挂... 7分钟普及!小闲辅助软件(外挂)原来确实有挂软件(分享开挂神器);小闲辅助软件免费下载原版,在小闲辅...