unity3d 资源打包加密 整理
资源打包脚本,放到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 资源打包加密 整理的更多相关文章
- unity3d资源打包总结
http://www.manew.com/blog-33734-12973.html unity 打包的时候会把下面几个文件资源打进apk或者ipa包里面 1. Asset下的所有脚本文件 2. As ...
- plain framework 1 pak插件说明(资源压缩加密)
在互联网的发展中,资源的整理一般成了发布软件应用的迫在眉睫的一件事情,不经打包的资源往往容易暴露而且众多的文件使得拷贝等待时间变长.在这种情况下,一种应用便诞生了,其起源是源自压缩软件,这便是我们今天 ...
- Unity中资源打包成Assetsbundle的资料整理
最近在研究Unity中关于资源打包的东西,网上看了一堆资料,这里做个整合,说整合,其实也就是Ctrl-C + Ctrl-V,不是原创 首先为了尊重原创,先贴出原创者的文章地址: http://blog ...
- 跟我从零基础学习Unity3D开发--资源打包篇(AssetBundle)
好久没更新了,一直在加班敢项目进度.这里和关注我的博客的童鞋表示一下歉意!这里有我录的Unity3D从零开始的视频教程大家可以关注一下:http://www.imooc.com/view/555 视 ...
- KEngine:Unity3D资源的打包、加载、调试监控
资源模块做什么? 资源模块——ResourceModule,是KEngine中最核心的模块,其他模块基本或多或少的对它有依赖,它主要的功能是:资源打包.路径定义.资源管理.资源调试. 资源模块对Uni ...
- unity3d进行脚本资源打包加载
原地址:http://www.cnblogs.com/hisiqi/p/3204752.html 本文记录如何通过unity3d进行脚本资源打包加载 1.创建TestDll.cs文件 public c ...
- 资源 Des加密
Unity3d资源管理分析 http://blog.csdn.net/sgnyyy/article/details/39268215 打包资源 http://www.cnblogs.com/sifen ...
- Unity资源打包之Assetbundle
转 Unity资源打包之Assetbundle 本文原创版权归 csdn janeky 所有,转载请详细注明原创作者及出处,以示尊重! 作者:janeky 原文:http://blog.csdn.n ...
- Unity手游之路<十一>资源打包Assetbundle
http://blog.csdn.net/janeky/article/details/17652021 在手游的运营过程中,更新资源是比不可少的.资源管理第一步是资源打包.传统的打包可以将所有物件制 ...
随机推荐
- python用zipfile模块打包文件或是目录、解压zip文件实例
#!/usr/bin/env python # -*- coding: utf-8 -*- from zipfile import * import zipfile #解压zip文件 def unzi ...
- Java后端测试概述
[本文出自天外归云的博客园] 多种单测技术 1. 要学会Spring MVC/Boot测试中自带的mock方法. 2. 学会junit中的方法,对于注解的使用等. 3. 学会使用结合第三方Mockit ...
- 在windows下nginx+django+flup python3
1.安装python 下载最新的python版本,在本文撰写时为 python 3.4, 下载地址:https://www.python.org/ftp/python/3.4.0/python-3.4 ...
- ARKit从入门到精通(8)-ARKit捕捉平地
转载:http://blog.csdn.net/hdfqq188816190/article/details/73360287 1.1-ARKit捕捉平地实现流程介绍 1.2-完整代码 1.3-代码下 ...
- java基础篇---XML解析(一)
XML是可扩展标记语言 在XML文件中由于更多的是描述信息的内容,所以在得到一个xml文档后应该利用程序安装其中元素的定义名称去除对应的内容,这样的操作称为XML解析. 在XML解析中W3C定义SAX ...
- Mongodb 的常用方法,在可视化工具执行
查询: db.getCollection('message').find({"userId":"31257"}) 查询总数: db.getCollection( ...
- 基于opencv+Dlib的面部合成(Face Morph)
引自:http://blog.csdn.net/wangxing233/article/details/51549880 零.前言 前段时间看到文章[1]和[2],大概了解了面部合成的基本原理.这两天 ...
- IIS 7上部署PHP【后续一】
在之前成功在windows 2008+iis7环境下部署php的基础上,今天把之前的挂Q网站转移到了这个服务器下. 文件拷贝到服务器后,问题继续出现. 首先出现的问题是,Mysql的数据库名称和账户密 ...
- Activiti Modeler初探实践
以下内容对实践activiti很有用,不过我用的不是github下载的源码包编译出来的war包,不知道什么原因我打出来的包会有点问题.不过这不重要,换个地方下载来源就行,下载网址: http://dl ...
- ashx session 赋值 获取
ashx想获取session值 需要继承 IRequiresSessionState接口 ExcelHelper : IHttpHandler, IRequiresSessionState publi ...