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

相关内容

热门资讯

让我来分享经验!花城棋舍辅助,... 让我来分享经验!花城棋舍辅助,淘宝买wepoker透视有用吗,科技教程(有挂规律)-哔哩哔哩;花城棋...
指导大家!hhpoker辅助挂... 指导大家!hhpoker辅助挂,wepoker私人局可以透视,总是有挂(有挂头条)1、下载好脚本下载...
实测教程!上饶辅助设备出租,w... 实测教程!上饶辅助设备出租,wepoker公共底牌,大神讲解(有挂解密)-哔哩哔哩;上饶辅助设备出租...
发现一款!菠萝辅助器免费版的特... 发现一款!菠萝辅助器免费版的特点,wepoker透视有吗,其实是有挂(真实有挂)1、进入游戏-大厅左...
带你了解!麻友圈插件,wpk俱... 【福星临门,好运相随】;带你了解!麻友圈插件,wpk俱乐部怎么作弊,可靠教程(真是有挂)-哔哩哔哩;...
玩家必备教程!德州透视hhpo... 玩家必备教程!德州透视hhpoker,wpk透视是真的假的,一直存在有挂(有挂详情)1、超多福利:超...
热点讨论!广东雀神智能插件安卓... 热点讨论!广东雀神智能插件安卓包,wepoker永久免费脚本,靠谱教程(有挂方针)-哔哩哔哩是一款可...
教程辅助!来玩德州破解器,德州... 教程辅助!来玩德州破解器,德州局透视脚本下载安装最新版本,真是有挂(有挂教学)1)免费钻石:进一步探...
每日必看教程!拱趴辅助,菠萝辅... 每日必看教程!拱趴辅助,菠萝辅助器免费版的功能介绍,技巧教程(有挂猫腻)-哔哩哔哩;每日必看教程!拱...
记者揭秘!xpoker辅助控制... 记者揭秘!xpoker辅助控制,wepoker买脚本靠谱吗,真是真的是有挂(详细教程)1、操作简单,...