Unity3D LuaBundleLoader(基于cslua)
说明:异步加载lua的bundle,会优先加载cache目录下bundle(一般更新的资源都在cache下)
using System;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using LuaInterface; public class LuaBundleLoader : MonoBehaviour { public delegate void DelegateLoading(int idx, int total, string bundleName, string path);
public delegate void DelegateLoadOver(); //正在加载中回掉
public DelegateLoading OnLoading; //加载完成回掉
public DelegateLoadOver OnLoadOver; //总共要加载的bundle个数
private int mTotalBundleCount = 0; //当前已加载的bundle个数
private int mBundleCount = 0; #if UNITY_5
public void LoadBundle(string dir, string bundleName)
{
StartCoroutine(LoadBundles(dir, bundleName));
}
#else
public void LoadBundle(string dir, List<string> bundleList)
{
StartCoroutine(LoadBundles(dir, bundleList));
}
#endif
IEnumerator CoLoadBundle(string name, string path)
{
using (WWW www = new WWW(path))
{
if (www == null)
{
Debugger.LogError(name + " bundle not exists");
yield break;
} yield return www; if (www.error != null)
{
Debugger.LogError(string.Format("Read {0} failed: {1}", path, www.error));
yield break;
} mBundleCount++;
LuaFileUtils.Instance.AddSearchBundle(name, www.assetBundle); try
{
if (null != OnLoading)
{
OnLoading(mBundleCount, mTotalBundleCount, name, path);
}
}
catch (Exception e)
{
Debug.LogError(e.Message);
} www.Dispose();
}
} #if UNITY_5
private IEnumerator LoadBundles(string dir,string bundleName)
#else
public IEnumerator LoadBundles(string dir, List<string> bundleList)
#endif
{
var cachePath = Application.temporaryCachePath.Replace('\\', '/');
var streamingPath = Application.streamingAssetsPath.Replace('\\', '/'); List<string> list = new List<string>(); #if UNITY_5 var bundlePath = cachePath+"/"+dir+"/"+bundleName;
if (!File.Exists(bundlePath))
{
bundlePath = streamingPath + "/" + dir + "/" + bundleName;
}
else
{
#if UNITY_ANDROID && !UNITY_EDITOR
bundlePath = "file:///" + bundlePath;
#endif
}
#if UNITY_ANDROID && !UNITY_EDITOR #else
bundlePath = "file:///" + bundlePath;
#endif
using (WWW www = new WWW(bundlePath))
{
yield return www; AssetBundleManifest manifest = (AssetBundleManifest)www.assetBundle.LoadAsset("AssetBundleManifest");
list = new List<string>(manifest.GetAllAssetBundles());
//www.assetBundle.Unload(true);
www.Dispose();
}
#else
list = bundleList;
#endif
mTotalBundleCount = list.Count; for (int i = 0; i < list.Count; i++)
{
string str = list[i]; string path =cachePath+"/"+dir+"/"+str;
if (!File.Exists(path))
{
path = streamingPath + "/" + dir + "/" + str;
}
else
{
#if UNITY_ANDROID && !UNITY_EDITOR
path = "file:///" + path;
#endif
}
#if UNITY_ANDROID && !UNITY_EDITOR #else
path = "file:///" + path;
#endif
string name = Path.GetFileNameWithoutExtension(str);
StartCoroutine(CoLoadBundle(name, path));
} yield return StartCoroutine(CheckLoadFinish());
} IEnumerator CheckLoadFinish()
{
while (mBundleCount < mTotalBundleCount)
{
yield return null;
} if (null != OnLoadOver)
{
try
{
OnLoadOver();
}
catch (Exception e)
{
Debug.LogError(e.Message);
} }
} }
使用代码
var loader = GetComponent<LuaBundleLoader>();
if (null == loader)
{
loader = gameObject.AddComponent<LuaBundleLoader>();
} loader.OnLoading = (idx, total, bundleName, path) =>
{
Debug.Log(path+" ok");
}; loader.OnLoadOver = OnBundleLoadOver; loader.LoadBundle(LuaConst.osDir, LuaConst.osDir);
Unity3D LuaBundleLoader(基于cslua)的更多相关文章
- Thinking in Unity3D:基于物理着色(PBS)的材质系统
关于<Thinking in Unity3D> 笔者在研究和使用Unity3D的过程中,获得了一些Unity3D方面的信息,同时也感叹Unity3D设计之精妙.不得不说,笔者最近几年的引擎 ...
- Unity3D LuaComponent(基于ulua)
LuaComponent可以支持配一个需要执行在这个gameObject上的lua脚本,并且每个gameObject上的lua都是一个实例 using UnityEngine; using LuaIn ...
- Thinking in Unity3D
关于<Thinking in Unity3D> 笔者在研究和使用Unity3D的过程中,获得了一些Unity3D方面的信息,同时也感叹Unity3D设计之精妙.不得不说,笔者最近几年的引擎 ...
- Unity3D游戏开发初探—1.跨平台的游戏引擎让.NET程序员新生
一.Unity3D平台简介 Unity是由Unity Technologies开发的一个让轻松创建诸如三维视频游戏.建筑可视化.实时三维动画等类型互动内容的多平台的综合型游戏开发工具,是一个全面整合的 ...
- 【Unity3D】AR应用中,关于东南西北方位的判断。
这篇文章的应用场景是这样子的: 首先我们要做的是一个带有LBS定位服务(比如高德地图.百度地图等)AR功能,在这个场景中,会有一些地图上的”点“(如派出所.学校)是我们需要显示在我们的AR镜头上的,如 ...
- Unity3D 装备系统学习Inventory Pro 2.1.2 总结
前言 写在最前面,本文未必适合纯新手,但有一些C#开发经验的还是可以看懂的,虽然本人也是一位Unity3D新人,但是本文只是自己在学习Inventory Pro的学习总结,而不是教程,本人觉得要读懂理 ...
- 在Unity3D的网络游戏中实现资源动态加载
用Unity3D制作基于web的网络游戏,不可避免的会用到一个技术-资源动态加载.比如想加载一个大场景的资源,不应该在游戏的开始让用户长时间等待全部资源的加载完毕.应该优先加载用户附近的场景资源,在游 ...
- PureMVC和Unity3D的UGUI制作一个简单的员工管理系统实例
前言: 1.关于PureMVC: MVC框架在很多项目当中拥有广泛的应用,很多时候做项目前人开坑开了一半就消失了,后人为了填补各种的坑就遭殃的不得了.嘛,程序猿大家都不喜欢像文案策划一样组织文字写东西 ...
- (转)在Unity3D的网络游戏中实现资源动态加载
原文:http://zijan.iteye.com/blog/911102 用Unity3D制作基于web的网络游戏,不可避免的会用到一个技术-资源动态加载.比如想加载一个大场景的资源,不应该在游戏的 ...
随机推荐
- JAVA IDE IntelliJ IDEA使用简介(一)—之界面元素
(注:简介基于IDEA的版本为:11.0,下载地址:http://www.jetbrains.com/idea/) 打开IDEA,(当第一次打开的时候出现的是一个欢迎页面,随便创建一个project来 ...
- Golang友团无闻Go语言Web基础视频教程
教程内容:GO语言资料Golang友团无闻Go语言编程基础Golang友团无闻Go语言Web基础教程 Go语言Web基础教程列表:[Go Web基础]12Go Web 扩展学习.mp4[Go Web基 ...
- JS获取屏幕高度(转)
IE中: document.body.clientWidth ==> BODY对象宽度 document.body.clientHeight ==> BODY对象高度 document.d ...
- 让游戏以高性能GPU(独立显卡)运行
在EXE中导出全局变量: N卡: extern "C" { __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001 ...
- 终于等到你---订餐系统之负载均衡(nginx+memcached+ftp上传图片+iis)
又见毕业 对面工商大学的毕业生叕在拍毕业照了,一个个脸上都挂满了笑容,也许是满意自己四年的修行,也许是期待步入繁华的社会... 恰逢其时的连绵细雨与满天柳絮,似乎也是在映衬他们心中那些离别的忧伤,与对 ...
- ConvertHelper 通用类
public class ConvertHelper<T> where T : new() { private static Dictionary<Type, List<IPr ...
- APP
第一天 1.环境初步搭建 SmartSniff fiddler ddms AntiDroid Android Killer 百度方法 http://jingyan.baidu.com/article/ ...
- 使用CocoaPods开发并打包静态库
Cocoapods作为OS X和iOS开发平台的类库管理工具,已经非常完善和强大.通常我们用pod来管理第三方开源类库,但我们也极有可能会开发一个用pod管理依赖关系的静态类库给其他人使用,而又不愿意 ...
- phpexcel导入数据提示失败
phpexcel导入excel时明明只有几行数据,却提示506行失败,原来是excel中有506行"无效数据"(看起来是空的,但是和没有数据不一样).
- 《CSS权威指南》基础复习+查漏补缺
前几天被朋友问到几个CSS问题,讲道理么,接触CSS是从大一开始的,也算有3年半了,总是觉得自己对css算是熟悉的了.然而还是被几个问题弄的"一脸懵逼"... 然后又是刚入职新公司 ...