1、assetbundle资源加密方式(unity Plus和unity Pro支持)
针对Unity资源包-AssetBundle格式简单且容易破解的问题,Unity中国团队推出了Unity AssetBundle 加密方案
- 注意:秘钥长度为16位字符(128bit),目前AssetBundle加密需要AssetBundle为LZ4压缩格式
BuildPipeline.SetAssetBundleEncryptKey("0123456789abcdef");
- 然后指定BuildAssetBundleOptions包含:ChunkBasedCompression 和 EnableProtection即可:
BuildPipeline.BuildAssetBundles(assetbundleBuildPath, BuildAssetBundleOptions.ChunkBasedCompression | BuildAssetBundleOptions.EnableProtection, EditorUserBuildSettings.activeBuildTarget);
- 通过指定秘钥为null来清除秘钥:
BuildPipeline.SetAssetBundleEncryptKey(null);
- 加载AssetBundle:
加载AssetBundle时,先指定本次加载所使用的解密秘钥。
AssetBundle.SetAssetBundleDecryptKey(rightUserKey);
- 然后加载AssetBundle即可:
AssetBundle assetBundle = AssetBundle.LoadFromFile(GetAssetBundleFullPath());
- 通过指定秘钥为null来清楚秘钥:
AssetBundle.SetAssetBundleDecryptKey(null);
2、对于常用和序列帧的图片尽量使用图集进行管理,优点如下(unity2020.1及以后版本取消了Sprite Packer):
- 减少DrawCall,虽然新版Unity没有DrawCall显示了,但也引入了Batches和SetPass calls这两个数值,实际上都是指图片渲染的次数(这样说可能有点不严谨,但代表这个意思)。每张单独的图片占用一次渲染,假如10张小图,就10次渲染了,但如果这10张小图打到一个图集里面,那么系统只需渲染1次即可,大大减少系统负担
- 减轻IO负担,假如你每次加载图片的时候还是用Load()之类的通过操作IO读写的方式来加载的话,那么每次加载图片都需要进行一次IO读写,而使用图集之后只需一次读取图集到内存中,那么每次加载图片就只需从内存中取出,大大减轻系统负担,当然,这是舍弃内存保速度的解决方案。
- 加载图集代码如下:
public Sprite LoadSprite(string _atlasName,string _spriteName) { SpriteAtlas m_spriteAtlas = Resources.Load<SpriteAtlas>(_atlasName); tempSprite = m_spriteAtlas.GetSprite(_spriteName); return tempSprite; }
3、全新Arm Mobile Studio for Unity软件包,增强移动端性能分析
具体使用及介绍地址:https://www.bilibili.com/read/cv11833852
4、Addressable对AssetBundle进行封装,可以从本地、resourse、网络端加载
使用视频教程:https://www.bilibili.com/video/BV1N4411q7NA
文字介绍:https://www.bilibili.com/read/cv11642315
5、使用Playable API定制自己的动画系统
文字教程:https://zhuanlan.zhihu.com/p/144851154
6、ScriptableObject的介绍和使用
文字教程:https://blog.csdn.net/candycat1992/article/details/52181814