资源打包脚本,放到Assets\Editor 文件夹下

using UnityEngine;
using System.Collections;
using UnityEditor;
using System.IO; public class assetPack : Editor
{ /*
[MenuItem("Custom Editor/Build AssetBundle From Selection - Track dependencies")]
static void ExportResource2()
{
// Bring up save panel
string path = EditorUtility.SaveFilePanel("Save Resource", "", "New Resource", "unity3d");
if (path.Length != 0)
{
// 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;
}
}
* */
/*
[MenuItem("Custom Editor/Build AssetBundle Complited to bytes")]
static void ExportResource5()
{
// Bring up save panel
string path = EditorUtility.SaveFilePanel("Save Resource", "", "New Resource", "unity3d");
if (path.Length != 0)
{
// 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, BuildTarget.StandaloneWindows);
Selection.objects = selection; FileStream fs = new FileStream(path, FileMode.Open, FileAccess.ReadWrite);
byte[] buff = new byte[fs.Length];
fs.Read(buff, 0, (int)fs.Length);
string password = "shanghaichaolan";
packXor(buff,buff.Length,password);
Debug.Log("filelength:"+ buff.Length);
fs.Close();
File.Delete(path); string BinPath = path.Substring(0, path.LastIndexOf('.')) + ".bytes";
FileStream cfs = new FileStream(BinPath,FileMode.Create);
cfs.Write(buff, 0, buff.Length);
Debug.Log("filelength:" + buff.Length);
buff = null;
cfs.Close(); }
}
*/ [MenuItem("Custom Editor/Save Scene2")]
static void ExportResource()
{
// Bring up save panel
string path = EditorUtility.SaveFilePanel("Save Resource", "", "New Resource", "unity3d");
if (path.Length != 0)
{
// 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;
}
} [MenuItem("Custom Editor/Make unity3d file to bytes file")]
static void ExportResourceNoTrackSS()
{
string path = EditorUtility.SaveFilePanel("Save Resource", "", "New Resource", "unity3d");
if (path.Length != 0)
{ FileStream fs = new FileStream(path, FileMode.Open, FileAccess.ReadWrite);
byte[] buff = new byte[fs.Length];
fs.Read(buff, 0, (int)fs.Length);
string password = "shanghaichaolan";
packXor(buff, buff.Length, password);
Debug.Log("filelength:" + buff.Length);
fs.Close();
File.Delete(path); string BinPath = path.Substring(0, path.LastIndexOf('.')) + ".bytes";
FileStream cfs = new FileStream(BinPath, FileMode.Create);
cfs.Write(buff, 0, buff.Length);
Debug.Log("filelength:" + buff.Length);
buff = null;
cfs.Close(); }
} static void packXor(byte[] _data, int _len, string _pstr)
{
int length = _len;
int strCount = 0; for (int i = 0; i < length; ++i)
{
if (strCount >= _pstr.Length)
strCount = 0;
_data[i] ^= (byte)_pstr[strCount++]; } } }

菜单上就会出现两个, 把要打包的资源做成Prefab,选中资源,然后菜单Custom Editor/Save Scene2  输入名字

新生成的文件,再选中新生成的文件,点击菜单Custom Editor/Make unity3d file to bytes file   输入名字

又生成了一个文件,再点击这个文件,菜单Custom Editor/Save Scene2  ,这样就打包加密好了

using UnityEngine;
using System.Collections; public class loadnew : MonoBehaviour
{
public string filename;
private string BundleURL;
private string AssetName;
void Start()
{
//StartCoroutine(loadScenee());
StartCoroutine(LoadResource());
} IEnumerator loadScenee()
{
string path;
path = "file://" + Application.dataPath + "/" + filename + ".unity3d";
Debug.Log(path);
WWW www = new WWW(path);
yield return www;
AssetBundle bundle = www.assetBundle;
//GameObject go = bundle.Load("gCube",typeof(GameObject)) as GameObject; GameObject ObjScene = Instantiate(www.assetBundle.mainAsset) as GameObject;
bundle.Unload(false); } IEnumerator LoadResource()
{
BundleURL = "file://" + Application.dataPath + "/" + filename + ".unity3d";
Debug.Log("path:" + BundleURL);
WWW m_Download = new WWW(BundleURL); yield return m_Download;
if (m_Download.error != null)
{
// Debug.LogError(m_Download.error);
Debug.LogError("Warning errow: " + "NewScene");
yield break;
} TextAsset txt = m_Download.assetBundle.Load(filename, typeof(TextAsset)) as TextAsset;
byte[] data = txt.bytes; byte[] decryptedData = Decryption(data);
Debug.Log("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.mainAsset); } byte[] Decryption(byte[] data)
{
byte[] tmp = new byte[data.Length];
for (int i = 0; i < data.Length; i++)
{
tmp[i] = data[i];
}
// shanghaichaolan
string password ="shanghaichaolan";
packXor(tmp,tmp.Length,password);
return tmp; }
static void packXor(byte[] _data, int _len, string _pstr)
{
int length = _len;
int strCount = 0; for (int i = 0; i < length; ++i)
{
if (strCount >= _pstr.Length)
strCount = 0;
_data[i] ^= (byte)_pstr[strCount++]; } } void update()
{ }
}

加载加密和不加密的资源

unity3d 资源打包加密 整理的更多相关文章

  1. unity3d资源打包总结

    http://www.manew.com/blog-33734-12973.html unity 打包的时候会把下面几个文件资源打进apk或者ipa包里面 1. Asset下的所有脚本文件 2. As ...

  2. plain framework 1 pak插件说明(资源压缩加密)

    在互联网的发展中,资源的整理一般成了发布软件应用的迫在眉睫的一件事情,不经打包的资源往往容易暴露而且众多的文件使得拷贝等待时间变长.在这种情况下,一种应用便诞生了,其起源是源自压缩软件,这便是我们今天 ...

  3. Unity中资源打包成Assetsbundle的资料整理

    最近在研究Unity中关于资源打包的东西,网上看了一堆资料,这里做个整合,说整合,其实也就是Ctrl-C + Ctrl-V,不是原创 首先为了尊重原创,先贴出原创者的文章地址: http://blog ...

  4. 跟我从零基础学习Unity3D开发--资源打包篇(AssetBundle)

    好久没更新了,一直在加班敢项目进度.这里和关注我的博客的童鞋表示一下歉意!这里有我录的Unity3D从零开始的视频教程大家可以关注一下:http://www.imooc.com/view/555  视 ...

  5. KEngine:Unity3D资源的打包、加载、调试监控

    资源模块做什么? 资源模块——ResourceModule,是KEngine中最核心的模块,其他模块基本或多或少的对它有依赖,它主要的功能是:资源打包.路径定义.资源管理.资源调试. 资源模块对Uni ...

  6. unity3d进行脚本资源打包加载

    原地址:http://www.cnblogs.com/hisiqi/p/3204752.html 本文记录如何通过unity3d进行脚本资源打包加载 1.创建TestDll.cs文件 public c ...

  7. 资源 Des加密

    Unity3d资源管理分析 http://blog.csdn.net/sgnyyy/article/details/39268215 打包资源 http://www.cnblogs.com/sifen ...

  8. Unity资源打包之Assetbundle

    转  Unity资源打包之Assetbundle 本文原创版权归 csdn janeky 所有,转载请详细注明原创作者及出处,以示尊重! 作者:janeky 原文:http://blog.csdn.n ...

  9. Unity手游之路<十一>资源打包Assetbundle

    http://blog.csdn.net/janeky/article/details/17652021 在手游的运营过程中,更新资源是比不可少的.资源管理第一步是资源打包.传统的打包可以将所有物件制 ...

随机推荐

  1. jQuery之自定义datagrid控件

    sldatagrid 效果: sldatagrid.js (function($) { function loadColumns(sldatagrid, columns) { $(sldatagrid ...

  2. 基于HTML5手机登录注册表单代码

    分享一款基于HTML5手机登录注册表单代码.这是一款鼠标点击注册登录按钮弹出表单,适合移动端使用.效果图如下: 在线预览   源码下载 实现的代码. html代码: <div class=&qu ...

  3. java基础篇---注解(Annotation)

    一.概念 Annontation是Java5开始引入的新特征.中文名称一般叫注解.它提供了一种安全的类似注释的机制,用来将任何的信息或元数据(metadata)与程序元素(类.方法.成员变量等)进行关 ...

  4. === $ spark sql 的特别的方法

    /** * Equality test. * {{{ * // Scala: * df.filter( df("colA") === df("colB") ) ...

  5. 加快Terminal的打开加载速度

    加快Terminal的打开加载速度html, body {overflow-x: initial !important;}.CodeMirror { height: auto; } .CodeMirr ...

  6. InstallShield打包,以及集成TFS、JenKins

    一. InstallShield打包脚本教程,这里面写的很详细了 [海洋女神原创]一个完整的Installshield安装程序实例—艾泽拉斯之海洋女神出品(一)---基本设置一 需要补充的是Insta ...

  7. pthread_cond_wait和pthread_cond_signal以及互斥变量的使用情况

    #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <pthread.h& ...

  8. python基础归结

    00.python程序格式 #开头的语句是注释,其他每一行都是一个语句. 语句以冒号(:)结尾时,缩进的语句视为代码块(没有C语言中{}区分代码块). 约定俗称, 4个空格缩进,Tab或空格均可以,但 ...

  9. 【html5】使用 html5 的十大原因

    你难道还没有考虑使用 html5? 当然我猜想你可能有自己的原因:它现在还没有被广泛的支持,在 ie 中不好使,或者你就是喜欢写比较严格的 xhtml 代码.html5 是 web 开发世界的一次重大 ...

  10. 【合集】TiDB 源码阅读系列文章

    [合集]TiDB 源码阅读系列文章 (一)序 (二)初识 TiDB 源码 (三)SQL 的一生 (四)INSERT 语句概览 (五)TiDB SQL Parser 的实现 (六)Select 语句概览 ...