http://www.haogongju.net/art/1931680
首先要鄙视下unity3d的文档编写人员极度不负责任,到发帖为止依然没有更新正确的示例代码。
// Builds an asset bundle from the selected objects in the project view. |
// Once compiled go to "Menu" -> "Assets" and select one of the choices |
// to build the Asset Bundle |
public class ExportAssetBundles { |
[MenuItem("Assets/Build AssetBundle Binary file From Selection - Track dependencies ")] |
static void ExportResource () { |
string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d"); |
// Build the resource file from the active selection. |
Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets); |
BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets); |
Selection.objects = selection; |
FileStream fs = new FileStream(path,FileMode.Open,FileAccess.ReadWrite); |
byte[] buff = new byte[fs.Length+1]; |
fs.Read(buff,0,(int)fs.Length); |
string BinPath = path.Substring(0,path.LastIndexOf('.'))+".bytes"; |
// FileStream cfs = new FileStream(BinPath,FileMode.Create); |
cfs.Write(buff,0,buff.Length); |
// string AssetsPath = BinPath.Substring(BinPath.IndexOf("Assets")); |
// Object ta = AssetDatabase.LoadAssetAtPath(AssetsPath,typeof(Object)); |
// BuildPipeline.BuildAssetBundle(ta, null, path); |
[MenuItem("Assets/Build AssetBundle From Selection - No dependency tracking")] |
static void ExportResourceNoTrack () { |
string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d"); |
// Build the resource file from the active selection. |
BuildPipeline.BuildAssetBundle(Selection.activeObject, Selection.objects, path); |
把打包的文件转换成了binary文件并多加了一个字节加密。
当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 加密资源并缓存加载
原地址:http://www.cnblogs.com/88999660/archive/2013/04/10/3011912.html 首先要鄙视下unity3d的文档编写人员极度不负责任,到发帖为止 ...
- u3d 加密资源并缓存加载
// C# Example // Builds an asset bundle from the selected objects in the project view. // Once compi ...
- Unity3d Web3d资源的动态加载
Unity3d Web3d资源的动态加载 @灰太龙 参考了宣雨松的博客,原文出处http://www.xuanyusong.com/archives/2405,如果涉及到侵权,请通知我! Unity3 ...
- 【Unity3D】Unity3D之 Resources.Load 动态加载资源
[Unity3D]Unity3D之 Resources.Load 动态加载资源 1.Resources.Load:使用这种方式加载资源,首先需要下Asset目录下创建一个名为Resources的文件夹 ...
- UNITY_资源路径与加载外部文件
UNITY_资源路径与加载外部文件 https://www.tuicool.com/articles/qMNnmm6https://blog.csdn.net/appppppen/article/de ...
- HTML页面处理以及资源文件的加载
Javascript 异步加载详解 这篇文章很详细的介绍了HTML的页面处理以及资源文件的加载. 本文总结一下浏览器在 javascript 的加载方式. 关键词:异步加载(async loading ...
- Expo大作战(十三)--expo如何自定义状态了statusBar以及expo中如何处理脱机缓存加载 offline support
简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人 ...
- 下载某资源文件并加载其中的所有Prefab到场景中
using System.Collections; using System.Collections.Generic; using UnityEngine; /// <summary> / ...
- 背水一战 Windows 10 (11) - 资源: CustomResource, ResourceDictionary, 加载外部的 ResourceDictionary 文件
[源码下载] 背水一战 Windows 10 (11) - 资源: CustomResource, ResourceDictionary, 加载外部的 ResourceDictionary 文件 作者 ...
随机推荐
- python3.x 安装命令
在root下执行下面的命令即可: sudo apt-get install python3-dev build-essential libssl-dev libffi-dev libxml2 libx ...
- 孤荷凌寒自学python第六十二天学习mongoDB的基本操作并进行简单封装1
孤荷凌寒自学python第六十二天学习mongoDB的基本操作并进行简单封装1 (完整学习过程屏幕记录视频地址在文末) 今天是学习mongoDB数据库的第八天. 今天开始学习mongoDB的简单操作, ...
- crontab-用于设置周期性被执行的指令
一个很好用的工具. 参考文章: [入门] http://baike.baidu.com/view/1229061.htm [进阶] http://blog.csdn.net/tianlesoftwar ...
- Ironic-Python-Agent
Ironic-Python-Agent 在PXE部署环境中,deploy模块是通过打开一个iSCSI设备,ironic-conductro将OS的镜像文件写到iSCSI的设备,所以deploy_ram ...
- Java系列学习说明
最近要回顾以前的开发知识了,每天一个案例,争取早日成为一名合格的程序猿,现在就是猴娃子级别的.
- 团队项目-第九次scrum 会议
时间:11.5 时长:40分钟 地点:F楼1039教室 工作情况 团队成员 已完成任务 待完成任务 解小锐 完成员工commit函数的数值函数编写 完成多种招聘方式的逻辑编写 陈鑫 实现游戏的暂停功能 ...
- Mysql入门的10条语句
1.查看当前服务器下面,有那些库(database)? 答: show databases; 2.如何创建一个数据库? 答 : create database 最后面在写数据库名:分号结束 3.选择数 ...
- Dev express 笔记
1.设置treelist不同行的颜色 void treeList1_CustomDrawNodeCell(object sender, DevExpress.XtraTreeList.CustomDr ...
- 洛谷 P4514 上帝造题的七分钟 解题报告
P4514 上帝造题的七分钟 题目背景 裸体(裸题)就意味着身体(神题). 题目描述 "第一分钟,X说,要有矩阵,于是便有了一个里面写满了\(0\)的\(n \times m\)矩阵. 第二 ...
- 自动设置 rem es模块写法
export default function () { let html = document.documentElement; function onWindowResize() { if (ht ...