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的网络游戏,不可避免的会用到一个技术-资源动态加载.比如想加载一个大场景的资源,不应该在游戏的 ...
随机推荐
- node基础13:异步流程控制
1.流程控制 因为在node中大部分的api都是异步的,比如说读取文件,如果采用回调函数的形式,很容易造成地狱回调,代码非常不容易进行维护. 因此,为了解决这个问题,有大神写了async这个中间件.极 ...
- linux-windows资源共享
先安装samba,然后 sudo mount -t cifs //192.168.1.111/Jack_Win_Share /media/ -o username=Jack,password=1,io ...
- C# Winform程序把引用的dll放到指定目录
如果项目引用了很多dll,发布的时候放同一目录会很乱,这时候可以用privatePath后面指定搜索的dll文件夹,多个用;分隔 另外,发现在配置文件夹中 configSource 也是可以指定目录的 ...
- IE9下css hack写法
ie9一出css hack也该更新,以前一直没关注,今天在内部参考群mxclion分享了IE9的css hack,拿出来也分享一下: select { background-color:red\0; ...
- 微信小程序之页面路由(九)
[未经允许,请勿以任何形式转载] 什么是路由? 我们通常理解的路由指分组数据包从源到目的地时,决定端到端路径的网络范围的进程: 借用上面的定义,我们可以理解小程序页面路由,根据路由规则(路径)从一个页 ...
- RCW 生存期控制
RCW是.net 对com的包装,比如office就是通过RCW来被.net调用的.可以百度:office pia 了解更多信息. RCW 是一个.net类. 1.关闭线程对rcw的自动清理 Syst ...
- C++标准库:std_map作为一个关联数组
摘要:std::map作为一个容器存在一个典型应用就是作为关联数组来作用.在诸如Java等等语言中,关联数组广泛存在.std::map是一个容器,在它的概念框架中存在两个词:键和值,std::map把 ...
- BZOJ 4552: [Tjoi2016&Heoi2016]排序
4552: [Tjoi2016&Heoi2016]排序 Time Limit: 60 Sec Memory Limit: 256 MBSubmit: 579 Solved: 322[Sub ...
- bzoj4591 【Shoi2015】超能粒子炮·改
由Lucas定理C(n,k)=C(n/2333,k/2333)*C(n%2333,k%2333)%2333 则ans=ΣC(n,i),(i<=k) =C(n/2333,0)*C(n%2333, ...
- BZOJ2818 Gcd
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000作者博客:http://www.cnblogs.com/ljh2000-jump/转 ...