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、...
突发!微信途游四川辅助器,一贯... 突发!微信途游四川辅助器,一贯真的有辅助下载(确实有挂)-哔哩哔哩1、完成微信途游四川辅助器有辅助插...
透视演示!uupoker有透视... 透视演示!uupoker有透视吗(透视)一直真的是有辅助工具(哔哩哔哩)1、下载好uupoker有透...
推荐一款!!微乐小程序免费黑科... 推荐一款!!微乐小程序免费黑科技(外挂),微乐南昌辅助神器其实有挂攻略一、微乐小程序免费黑科技可以开...
总结透视!智星德州可以透视吗,... 总结透视!智星德州可以透视吗,约局吧游戏挂(透视)切实是真的有辅助方法(哔哩哔哩)1、下载好智星德州...
于此同时!微乐小程序免费黑科技... 于此同时!微乐小程序免费黑科技,切实真的有辅助神器(有挂方针)-哔哩哔哩1)微乐小程序免费黑科技有没...
透视操作!werplan透视挂... 透视操作!werplan透视挂(透视)竟然是真的辅助工具(哔哩哔哩)1、上手简单,内置详细流程视频教...
技巧知识分享!微信小程序免费黑... 技巧知识分享!微信小程序免费黑科技(外挂),宁夏微乐科技辅助竟然有挂详细暗藏猫腻,小编详细说明微信小...
辅助透视!拱趴大菠萝开挂方法,... 辅助透视!拱趴大菠萝开挂方法,cloudpoker作必弊(透视)好像是真的有辅助方法(哔哩哔哩)1、...
现场直击!粤麻圈辅助器,一直是... 现场直击!粤麻圈辅助器,一直是真的辅助下载(有挂神器)-哔哩哔哩1、下载好粤麻圈辅助器正确养号方法之...