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安装pycurl失败,及解决办法
Centos安装pycurl centos 安装pycurl yum install python-devel curl-devel pip3 install pycurl Mac(老版本)安装pyc ...
- Python爬网——获取安卓手机统计数据
[本文出自天外归云的博客园] 1. 在安卓网上对热门机型进行爬网,取前五十: # -*- coding: utf-8 -*- import requests,re from bs4 import Be ...
- iOS中大文件下载(单线程下载)
主要是需要注意,在客服端发请求给服务器的时候,在请求头里是可以设置服务器返回的数据从哪开始,到哪结束的. 当服务器响应客户端时,是可以拿到服务器返回数据具体类型以及大小的 思路: 在接收到服务器响应时 ...
- whatweb wordpress.rb
## # This file is part of WhatWeb and may be subject to # redistribution and commercial restrictions ...
- DIV+CSS兼容解决DIV最大宽度和最小宽度问题
在制作网页中,我们经常会碰到min/max-width,min/max-height在IE6底下是无效的,这也是web设计师最头疼的问题之一,以下的方法可以解决这些难题,并且比较简约.当然,如果你还有 ...
- 项目抛弃Tomcat容器,用代码启动Tomcat插件
tomato启动代码如下: package tomcat; import org.apache.catalina.connector.Connector; import org.apache.cata ...
- java中的设计模式一 装饰模式
1.装饰模式(Decorator)的定义:又名包装(Wrapper)模式,装饰模式以对客户端透明的方式扩展对象的功能,是继承关系的一个替代方案. 2.装饰模式以对客户端透明的方式动态的给一个对象附加上 ...
- PowerDesigner导入java类生成类图
1;打开PowerDesigner 2;file—>Reverse Engineer—>Object Language... 3;弹出一个对话框,在General模块下Model Name ...
- Hbase 学习(二)补充 自定义filter
本来这个内容是不单独讲的,但是因为上一个页面太大,导致Live Writer死机了,不能继续编辑了,所以就放弃了 这里要讲的是自定义filter,从FilterBase继承 public class ...
- JavaScript(九):JavaScript中的内置对象
一.对象的概念 对象是一种特殊的数据类型(object). 拥有一系列的属性和方法. 分为内置对象和自定义对象. 二.String对象 String对象用来支持对于字符串的处理. 1.属性 lengt ...