加载assetbundle协程并获取返回参数的程序举例
2017-07-24 10:43
537 查看
using System; using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; public class sample : MonoBehaviour { void Start() { var cache = LoadAssetBundle("csvconfig.assetbundle", "CsvConfig"); while (cache.MoveNext()) { }//执行到结束 //显示字典内容 foreach (var dict in cache.Current as Dictionary<string, TextReader>) { Debug.Log(dict.Key); } } #region 加载资源协程 static IEnumerator LoadAssetBundle(string abName, string keyword) { var cache = new Dictionary<string, TextReader>(); var wwwPath = string.Empty; #if UNITY_EDITOR_WIN wwwPath = string.Format("file://{0}/", Application.streamingAssetsPath); #else wwwPath = string.Format("jar:file://{0}!/assets/", Application.dataPath); #endif var loader = new WWW(wwwPath + abName); yield return new WaitUntil(() => loader.isDone); if (loader.error != null) yield break; var item = AssetBundle.LoadFromMemory(loader.bytes); var allAssetNames = item.GetAllAssetNames(); var allAssets = item.LoadAllAssets<TextAsset>(); for (var i = 0; i < allAssets.Length; i++) { var path = allAssetNames[i]; keyword = keyword.ToLower(); path = path.ToLower(); path = path.Substring(path.LastIndexOf(keyword, StringComparison.Ordinal) + keyword.Length); path = path.Replace('\\', '_'); path = path.Replace('/', '_'); path = path.Trim('_'); var keyName = path.Substring(0, path.LastIndexOf('.')); cache.Add(keyName, new StringReader(allAssets[i].text)); //Debug.Log("正在加载:" + keyName); } item.Unload(true); loader.Dispose(); Debug.Log("加载资源包[" + abName + "]完成,共计:" + cache.Count); yield return cache; } #endregion }
相关文章推荐
- phonegap js端调用Java端函数及获取返回参数
- 在简单控制台程序中获取并使用参数
- unity动态加载之AssetBundle原理
- LAST_DAY(date) 获取一个日期或日期时间值,返回该月最后一天对应的值。若参数无效,则返回NULL。
- [Unity3d]安卓无法加载assetbundle的问题
- 如何获取 程序加载后的内存起始地址
- Unity5 AssetBundle打包加载及服务器加载
- Unity 编辑器环境下不能正确加载Android Assetbundle 中的 Shader
- unity AssetBundle 加载资源 笔记
- VC的控制台程序,如何获取输入参数和环境变量
- Spring 框架下,用数组作为参数 传入到 存储过程,或存储过程返回动态数组到java程序 ,BLOB等大对象类似
- BT源代码学习心得(二):程序运行参数的获取
- Assetbundle创建与加载
- WorldWind学习总结【二】-程序启动时的相关参数获取方法
- AssetBundle(2)AssetBundle的加载和使用
- 程序向 shell脚本传递参数且获取shell的输出
- 关于ExecuteNonQuery执行存储过程的返回值 、、实例讲解存储过程的返回值与传出参数、、、C#获取存储过程的 Return返回值和Output输出参数值
- BT源代码学习心得(二):程序运行参数的获取 -- 转贴自 wolfenstein (NeverSayNever)
- Unity5.4 AssetBundle的完整项目源码(包括打包和加载)
- [C]通过XMLHTTP获取CGI/PHP等程序的返回值