资源打包脚本,放到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 panelstring 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 panelstring 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 panelstring 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];}//   shanghaichaolanstring 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(){}
}

加载加密和不加密的资源

原文地址:http://www.cnblogs.com/dragon2012/p/4087548.html

unity3d 资源打包加密 整理相关推荐

  1. unity3d 资源打包加密

    资源打包脚本,放到Assets\Editor 文件夹下 using UnityEngine; using System.Collections; using UnityEditor; using Sy ...

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

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

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

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

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

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

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

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

  6. Unity资源打包之Assetbundle

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

  7. Unity3d资源反编译. AssetBundle格式简析+简单应用+爬坑

    ===================  Unity3d资源反编译工具 DisUnity ================ 源码:https://github.com/ata4/disunity 需要 ...

  8. unity3d android存储文件,Unity3d资源写入Android内置存储卡

    还是在研究更新,发现如果你打算开始做一个游戏,在出来详细的策划后,接下来就是资源收集和整理,游戏更新大部分更新的都是资源, 所以应该在做游戏之前就想出一套很好的资源管理,使用,更新的方案,不能等游戏的 ...

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

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

  10. AssetBundle 资源打包 加载 卸载

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

最新文章

  1. hdu3555 Bomb 数位dp
  2. 受保护的属性无法直接读取
  3. linux 显示套接字统计信息,Linux 命令 - ss: 查看套接字统计信息
  4. 操作系统服务:其它模块
  5. 访问Internet 需要哪些步骤
  6. java 代码段 执行超时 抛异常_深入理解Java线程状态
  7. photoshop CS6 DDS插件
  8. 拦截器和过滤器的执行顺序和区别
  9. 如何下载自己喜欢的网站
  10. SSL连接是什么意思
  11. 推荐模型-序列推荐-2018:SHAN
  12. 揭秘小米造车背后的「波折」和「犹豫」
  13. LSTM之父最新长文:现代AI和深度学习发展史
  14. RabbitMQ队列、消息应答、持久化操作相关概念以及操作的详解
  15. 初识Uniprot API
  16. 台式电脑 在哪找到计算机名,win7电脑的投屏功能在哪?教你找到!
  17. C#图像处理:在图片上写字,文字位置居中问题
  18. echarts数据可视化系列:仪表盘
  19. python-docx+pandas实现word邀请函批量生成
  20. 港科夜闻|香港科大再获[商科]评审全港第一!

热门文章

  1. 【原型设计】第一节:Axure RP9 下载安装、汉化和激活使用的方法教程
  2. JavaScript怎样读取本地Excel文件
  3. 互联网大厂与编程语言
  4. MATLAB之卷积码
  5. 使用COOC软件绘制复杂网络
  6. 数据结构考研:线性表,顺序表,有序表,链表,数组的概念的区别与联系(软件工程/计算机/王道论坛)
  7. 如何Python写一个安卓APP
  8. 华为交换机双上行组网Smart-link配置指南
  9. L298N 驱动模块的应用
  10. 蓝屏代码查询器1.1.8