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、约局吧脚本有用吗公共底牌简单,...
开挂透视!aapoker万能辅... 开挂透视!aapoker万能辅助器,aapoker透视脚本下载,切实是真的有辅助app(哔哩哔哩)1...
于此同时!约战武汉辅助软件,W... 于此同时!约战武汉辅助软件,WePOker有没有透视方法(透视)总是有辅助攻略(哔哩哔哩)1、操作简...
此事备受玩家关注"a... 此事备受玩家关注"aapoker万能辅助器"大菠萝789辅助器下载(好像是有辅助软件)-哔哩哔哩暗藏...
在玩家背景下!久久互娱科技,广... 在玩家背景下!久久互娱科技,广丰中至510k辅助(切实存在有挂)-哔哩哔哩1、游戏颠覆性的策略玩法,...
教你透视!wepoker有辅助... 教你透视!wepoker有辅助器吗,wepoker透视脚本视频,好像存在有辅助插件(哔哩哔哩)1、完...
长期以来!欢聚水鱼智能辅助,w... 长期以来!欢聚水鱼智能辅助,wpk显示有作必弊(透视)其实存在有辅助插件(哔哩哔哩)长期以来!欢聚水...
近年来"hhpoke... 近年来"hhpoker一直输有挂吗"有没有人wepoker(确实存在有辅助工具)-哔哩哔哩hhpok...
透视透视!德普之星app安卓版... 透视透视!德普之星app安卓版破解版,德普之星透视辅助软件,原来是真的有辅助神器(哔哩哔哩)1、用户...
据了解!大菠萝辅助器,龙岩闲游... 据了解!大菠萝辅助器,龙岩闲游安卓脚本(真是真的是有挂)-哔哩哔哩1、很好的工具软件,可以解锁游戏的...