Unity 优化心得 (2D游戏)

    xiaoxiao2024-03-29  3

    Unity(261)2D(40)

    误区1:性能优化只是程序员的责任,与美术和策划无关。

    -技术美术和关卡设计师对于游戏性能承担着非常重要的责任

    -程序员往往无法补救由于滥用美术资源而造成的性能问题

    误区2:在制定了严格的美术规范之后,美术师就应该对一切美术问题负责,程序员不再与此有关

    -程序员应该为美术师实现完整的美术资源合法性检查工具

    -Tools speak louder than rules!

    误区3:对于程序而言,性能优化应该从GPU/Shader的执行效率入手

    -针对CPU端/游戏逻辑的性能优化往往能够取得更大的作用

    -GPU/Shader的性能优化应该放在最后进行

    原文链接:http://cl314413.blog.163.com/blog/static/190507976201292453413286/

    这里推荐使用一个优化工具BulidReqort

    上面会显示很详细的资源所占大小

    下面说说对于一些资源的优化

    图片:

    JPG图片

    一般采用自动压缩要是大小还不满足要求那么就把纹理max size 设置小一些;

    png图片:

    一般不是要求特别高清的可以使用rgba 16这个完全满足要求  比rgba32小一般  内存开销也是小一半的

    音乐:

    音乐一般采用修改采样率的办法来压缩 修改采样率为128就够了

    然后作为 2d游戏吧所有音乐都改为单声道小一半

    模型的话一半都是图片比较大把图片按照上面的改下就好

    场景参考这个可能能小一些http://www.xuanyusong.com/archives/1919

    最后附上一个修改unity导入后图片格式的代码

      using UnityEngine; using System.Collections; using UnityEditor; public class SetAssetPostprocessor : AssetPostprocessor { void OnPostprocessTexture(Texture2D texture) { string path = assetPath.ToLower(); if (path == null ||path == "" ) { return ; } TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter; if (textureImporter == null ) { return ; } textureImporter.textureType = TextureImporterType.Advanced; textureImporter.isReadable = true ; textureImporter.mipmapEnabled = false ; if (path.EndsWith( ".jpg" )) { textureImporter.npotScale = TextureImporterNPOTScale.ToNearest; textureImporter.maxTextureSize = 2048; textureImporter.textureFormat = TextureImporterFormat.AutomaticCompressed; } else { textureImporter.maxTextureSize = 2048; textureImporter.npotScale = TextureImporterNPOTScale.ToNearest; textureImporter.textureFormat = TextureImporterFormat.RGBA16; } AssetDatabase.Refresh(); } } 音乐也可以用上面的代码处理  需要把脚本放在Editor文件夹下
    转载请注明原文地址: https://ju.6miu.com/read-1287439.html
    最新回复(0)