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

using UnityEngine;

using System.Collections;

using UnityEditor;

using System.IO;

public class assetPack : Editor

{

[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()

{

Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);

foreach(Object obj in selection)

{

string path1 = AssetDatabase.GetAssetPath(obj);

FileStream fs = new FileStream(path1, FileMode.Open, FileAccess.ReadWrite);

byte[] buff = new byte[fs.Length];

fs.Read(buff, 0, (int)fs.Length);

string password = "llh";

packXor(buff, buff.Length, password);

Debug.Log("filelength:" + buff.Length);

fs.Close();

string BinPath = path1.Substring(0, path1.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  ,这样就打包加密好了

即打包AssetBundle之后加密再重新打包AssetBundle(能否直接加密打包?显然是不行的,加载资源时,LoadBundle会通过解密之后的字节重新创建AssetBundle,所以必须先打包出AssetBundle)

加载打包资源

using UnityEngine;

using System.Collections;

public class loadnew : MonoBehaviour

{

public string filename = "My Resource";

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;

GameObject obj =  (GameObject)Instantiate(bundle.mainAsset);

//obj.SetActive (true);

}

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 ="llh";

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()

{

}

}

转载于:https://blog.51cto.com/568464209/1741922

unity3d 资源打包加密相关推荐

  1. cef对本地web资源打包加密

    转载请说明原出处,谢谢~~:https://blog.csdn.net/zhuhongshu/article/details/81484159 cef中最简单的打开页面方法是指定一个url或者本地路径 ...

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

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

  3. GameFramework框架详解之 资源打包和加密

    一.Resource Builder编辑器面板 我们根据GameFramework的demo:Star Force 进行拆解GF的资源打包和加密逻辑 参数: productName:产品名称. com ...

  4. Unity3D手游开发日记(10) - 资源打包的一些思考

    Unity的资源打包,如果要做完美,其实是很复杂的.那么为什么资源要打包呢,因为我们要做资源更新.没办法啊. 在我看来,完美的资源打包至少有以下几个方面要处理好: 1) 资源分类设计合理.控制包粒度, ...

  5. Unity资源打包之Assetbundle

    本文原创版权归 csdn janeky 所有,转载请详细注明原创作者及出处,以示尊重! 作者:janeky 原文:http://blog.csdn.net/janeky/article/details ...

  6. Unity资源打包(一):AssetBundle使用-2020更新

    正所谓:自古套路得人心,学会AssetBundle开发,成就更精简游戏包. 欢迎关注公众号:雷潮课堂 ###AssetBundle打包 一.课程内容 1-1游戏套路 1-2什么是AssetBundle ...

  7. AssetBundle 资源打包 加载 卸载

    1 给要打包的资源设置标记,表示对应的包名: 2 Unity5 AssetBundle不需要我们来管理引用关系了 3 可以使用代码批量设置包名 AssetImporter ai = AssetImpo ...

  8. [Unity3d]制作打包并载入AssetBundle

    通常在游戏执行过程中,并不希望一次将全部的资源都载入.而是在资源被使用的时候载入,以免占用过多的存储空间.所以我们可能会尽量规划好不同功能的场景,在需要的时候才载入场景并释放掉前个场景中不需要的资源. ...

  9. 一键自动发布ipa(更新svn,拷贝资源,压缩资源,加密图片资源,加密数据文件,加密lua脚本,编译代码,ipa签名,上传ftp)...

    一键自动发布ipa(更新svn,拷贝资源,压缩资源,加密图片资源,加密数据文件,加密lua脚本,编译代码,ipa签名,上传ftp) 程序员的生活要一切自动化,更要幸福^_^. 转载请注明出处http: ...

最新文章

  1. 使用overlap-add方法计算两个信号的卷积示例(在频域计算卷积)
  2. 用Jquery控制文本框只能输入数字和字母及jquery自定义方法$.fn
  3. JQUERY GET
  4. centos 安装 图像识别工具 tesseract-ocr 流程
  5. 1043 输出PATest (20分)_23行代码满分
  6. 关于COMMIT WORK and COMMIT WORK AND WAIT在SAT中的讨论
  7. windows为什么把linux打败了,快二十年了,人们为什么还是没有抛弃 Windows 转向 Linux?...
  8. Android人脸识别开发入门--基于虹软免费SDK实现
  9. 苹果推送watchOS 5.3.2更新:用户无需升级至iOS13也可使用
  10. error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏 E:\OCX
  11. Docker备份镜像和重新载入镜像
  12. 蓝桥杯真题 杨辉三角形 C++
  13. mc全国计算机一级考试,全国计算机等级考试一级模拟试题04
  14. 【无标题】种草推广如何精准引流 KOL达人与内容要用好
  15. 物联网跟人的神经网络相似通过各种信息传感设备
  16. python 有限域函数库_python – Sympy:在有限域中求解矩阵
  17. 【调参15】如何配置神经网络的学习率
  18. 手写楚列斯基分解(楚列斯基因子分解) Matlab代码
  19. matlab gui invalid handle无效axes guidat handles等等
  20. 魔兽显血改键工具的脱壳和修改

热门文章

  1. 菜鸟编译OPenJDK全过程记录
  2. Jquery遮罩插件,想罩哪就罩哪!
  3. [探讨java深入的不变模式] java中String类的用法
  4. system进程总是100%
  5. python点击按钮弹出新窗口_PyQt5点击button如何弹出新窗口?
  6. python加密解密算法_Python基于DES算法加密解密实例
  7. HDFS-HA的配置-----自动Failover
  8. android4以上版本读写外置sd卡报错的解决办法
  9. 为什么你的缓存更新策略是先更新数据库后删除缓存,讲讲其他的情况有什么问题?...
  10. 阻塞与非阻塞 异步 与同步