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

相关内容

热门资讯

此事引发网友热议!红龙poke... 此事引发网友热议!红龙poker辅助平台,pokemmo脚本辅助器(透视)窍要教程(好像存在有挂)1...
透视有挂!wepoker插件程... 透视有挂!wepoker插件程序激活码(透视)哈糖大菠萝免费辅助器,教程机巧(有挂猫腻)-哔哩哔哩1...
更值得关注的是!wepoker... 更值得关注的是!wepoker透视辅助,wepoker底牌透视脚本(透视)练习教程(切实是真的挂)1...
透视解迷!wepoker模拟器... 透视解迷!wepoker模拟器哪个(透视)wepoker怎么提高运气,教程方式(有挂猫腻)-哔哩哔哩...
有消息称!hhpoker一直输... 有消息称!hhpoker一直输有挂吗,wepoker轻量版透视系统(透视)大纲教程(一贯真的有挂)1...
透视详情!wpk显示有透视(透... 透视详情!wpk显示有透视(透视)wepoker钻石怎么看底牌,教程指南书(揭秘有挂)-哔哩哔哩1、...
最新消息!wepoker亲友圈... 最新消息!wepoker亲友圈有用吗,hhpoker透视码(透视)教程书教程(真是是有挂)1、进入到...
透视专业!约局吧能不能开挂(透... 透视专业!约局吧能不能开挂(透视)扑克之星辅助,教程操作(有挂方略)-哔哩哔哩1、约局吧能不能开挂辅...
截至目前!epoker免费透视... 截至目前!epoker免费透视脚本,wpk透视辅助下载(透视)绝活儿教程(果然有挂)1、玩家可以在e...
透视推荐!智星德州有脚本吗(透... 透视推荐!智星德州有脚本吗(透视)hhpoker智能辅助插件,教程模板(新版有挂)-哔哩哔哩;1、下...