热门标签 | HotTags
当前位置:  开发笔记 > Android > 正文

Unity,APK资源优化

Unity,APK大小优化一个手机游戏到了开发的后期,一个最重要的步骤就是优化APK包的大小。主要优化贴图,模型,和声音。本文主要讲述如何批量优化这三种资源。对于贴图资源可以修改贴

Unity,APK大小优化
一个手机游戏到了开发的后期,一个最重要的步骤就是优化APK包的大小。主要优化贴图,模型,和声音。本文主要讲述如何批量优化这三种资源。
,".jpg"}; static string[] AudioFilter={".mp3",".ogg",".wav",".wma"}; static string[] FbxFilter={".fbx",".FBX"}; static bool Contain(string ex,string[] collection) { //Debug.Log(ex); for(int i=0;iif(collection[i]==ex) return true; } return false; } public static void GetAssetFile(string dir) { //Debug.Log(dir); foreach (string d in Directory.GetFileSystemEntries(dir)) { //Debug.Log(d); if (File.Exists(d)) { FileInfo fi = new FileInfo(d); string exten=fi.Extension; if(Contain(exten,TextureFilter)) { TextureAssetList.Add(fi.FullName); //Debug.Log(fi.FullName); }else if(Contain(exten,AudioFilter)) { AudioAssetsList.Add(fi.FullName); //Debug.Log(fi.FullName); }else if(Contain (exten,FbxFilter)) { FbxAssetsList.Add(fi.FullName); //Debug.Log(fi.FullName); } } else { DirectoryInfo d1 = new DirectoryInfo(d); if (d1.GetFiles().Length != 0) { GetAssetFile(d1.FullName);////递归 } } } } static void LogList() { for(int i=0;ifor(int i=0;ifor(int i=0;i#region Compress Assets / static void DealTexture() { for(int i=0;istring strPath=TextureAssetList[i]; CompressTexture(strPath); } } static void CompressTexture(string strPath) { int index= strPath.IndexOf("Assets"); strPath=strPath.Remove(0,index); TextureImporter tImp= (TextureImporter)TextureImporter.GetAtPath(strPath); tImp.textureFormat=TextureImporterFormat.ARGB16; //tImp.maxTextureSize=tImp.maxTextureSize/2; tImp.SetPlatformTextureSettings("Android",tImp.maxTextureSize/2,TextureImporterFormat.ARGB16); AssetDatabase.ImportAsset(strPath); } static void DealAudio() { for(int i=0;istring strPath=AudioAssetsList[i]; CompressAudio(strPath); } } static void CompressAudio(string strPath) { int index= strPath.IndexOf("Assets"); strPath=strPath.Remove(0,index); AudioImporter aImp=(AudioImporter)AudioImporter.GetAtPath(strPath); aImp.threeD=false; aImp.compressiOnBitrate=32; AssetDatabase.ImportAsset(strPath); } static void DealFbx() { for(int i=0;istring strPath=FbxAssetsList[i]; CompressFbx(strPath); } } static void CompressFbx(string strPath) { int index= strPath.IndexOf("Assets"); strPath=strPath.Remove(0,index); ModelImporter mImp=(ModelImporter)ModelImporter.GetAtPath(strPath); mImp.meshCompression=ModelImporterMeshCompression.High; mImp.animatiOnCompression=ModelImporterAnimationCompression.KeyframeReductionAndCompression; AssetDatabase.ImportAsset(strPath); } #endregion } }


推荐阅读
author-avatar
海螺里的秘密_471
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有