unity3d 加密资源并缓存加载
2014-05-02 12:04
701 查看
原地址:http://www.cnblogs.com/88999660/archive/2013/04/10/3011912.html
首先要鄙视下unity3d的文档编写人员极度不负责任,到发帖为止依然没有更新正确的示例代码。
把打包的文件转换成了binary文件并多加了一个字节加密。
当bytes文件生成好后再选中它,使用"Assets/Build AssetBundle From Selection - No dependency tracking"再次打包。
WWW.LoadFromCacheOrDownload的作用就是下载并缓存资源,要注意后面的版本号参数,如果替换了资源却没有更新版本号,客户端依然会加载缓存中的文件。
www.assetBundle.Load("characters",typeof(TextAsset)) as TextAsset //characters是加密文件的名字
AssetBundleCreateRequest acr = AssetBundle.CreateFromMemory(decryptedData);
这句是官网最坑爹的,AssetBundle.CreateFromMemory明明返回的是AssetBundleCreateRequest官网却写得是AssetBundle,而且AssetBundleCreateRequest是一个异步加载,必须用协程的方式加载官网也没有提到。跟多兄弟就倒在了这里
完。
首先要鄙视下unity3d的文档编写人员极度不负责任,到发帖为止依然没有更新正确的示例代码。
当bytes文件生成好后再选中它,使用"Assets/Build AssetBundle From Selection - No dependency tracking"再次打包。
using UnityEngine; using System.Collections; using System; public class WWWLoadTest : MonoBehaviour { public string BundleURL; public string AssetName; IEnumerator Start() { WWW www =WWW.LoadFromCacheOrDownload(BundleURL,2); yield return www; TextAsset txt = www.assetBundle.Load("characters",typeof(TextAsset)) as TextAsset; byte[] data = txt.bytes; byte[] decryptedData = Decryption(data); Debug.LogError("decryptedData length:"+decryptedData.Length); StartCoroutine(LoadBundle(decryptedData)); } IEnumerator LoadBundle(byte[] decryptedData){ AssetBundleCreateRequest acr = AssetBundle.CreateFromMemory(decryptedData); yield return acr; AssetBundle bundle = acr.assetBundle; Instantiate(bundle.Load(AssetName)); } byte[] Decryption(byte[] data){ byte[] tmp = new byte[data.Length-1]; for(int i=0;i<data.Length-1;i++){ tmp[i] = data[i]; } return tmp; } }
WWW.LoadFromCacheOrDownload的作用就是下载并缓存资源,要注意后面的版本号参数,如果替换了资源却没有更新版本号,客户端依然会加载缓存中的文件。
www.assetBundle.Load("characters",typeof(TextAsset)) as TextAsset //characters是加密文件的名字
AssetBundleCreateRequest acr = AssetBundle.CreateFromMemory(decryptedData);
这句是官网最坑爹的,AssetBundle.CreateFromMemory明明返回的是AssetBundleCreateRequest官网却写得是AssetBundle,而且AssetBundleCreateRequest是一个异步加载,必须用协程的方式加载官网也没有提到。跟多兄弟就倒在了这里
完。
相关文章推荐
- unity3d 加密资源并缓存加载
- unity3d加密资源并缓存加载
- unity3d 加密资源并缓存加载
- unity3d加密资源并缓存加载
- (转)unity3d加密资源并缓存加载
- u3d 加密资源并缓存加载
- unity3d进行脚本资源打包加载
- Android:手把手教你构建 Android WebView 的缓存机制 & 资源预加载方案
- ]Unity3D实现动态加载游戏资源(转)
- Cocos2dx之进度条使用,异步加载资源进缓存
- unity3d动态加载资源的2种方式
- [unity3d]从服务器端获取资源动态加载到场景
- [unity基础教程]Unity3D实现动态加载游戏资源(转)
- Unity3D Resources Load 资源加载测试
- Unity3D AssetBundles 动态加载游戏资源
- Android:手把手教你构建 WebView 的缓存机制 & 资源预加载方案
- android 网络加载图片,对图片资源进行优化,并且实现内存双缓存 + 磁盘缓存
- Unity3D研究院之异步加载游戏场景与异步加载游戏资源进度
- Unity3D的网络游戏中实现资源动态加载
- 在Unity3D的网络游戏中实现资源动态加载