[Unity优化]unity中的优化方法

news/2024/7/10 6:10:33 标签: 优化

1.从CPU、GPU和内存三方面进行优化:http://www.cnblogs.com/murongxiaopifu/p/4284988.html#top

2.UGUI的优化:http://www.jianshu.com/p/061e67308e5f

3.纹理压缩与OpenGL ES:http://blog.csdn.net/asd237241291/article/details/48548557            

使用平台推荐的压缩格式,比如安卓平台的ETC1和IOS平台的PVRTC


4.在UGUI中,如果UI发生重叠(即使只是重叠一部分,即使重叠的两个UI都是一样的),那么dc可能会增加!另外,文字也是占dc的!

5.去掉Mipmap以进一步降低资源包大小和内存占用


在unity中,MipMap是纹理的一个属性,如果开启,则一张1024*1024的纹理图片,它会自动生成512*512、256*256、128*128、64*64、32*32的这么多张额外的图片。主要用途是,当这个纹理离摄像机足够远时,这个纹理图片在摄像机中就会很小,这个时候为了节省性能和达到更好的显示效果,unity会自动选用之前自动生成的众多MipMap小纹理中的一张来替代最初的纹理。(即牺牲内存换取速度)

6.使用九宫格降低资源包大小


7.获取方法的执行时间(参考:http://www.xuanyusong.com/archives/4184)

using UnityEngine;
using System.Collections;
using System.Diagnostics;
using System;

public class TestTool {

    private static Stopwatch sw;

    public static void CalculateTime(Action action)
    {
        if (sw == null)
        {
            sw = new Stopwatch();
            sw.Start();
        }
        else
        {
            sw.Reset();
        }

        action();
        sw.Stop();
        UnityEngine.Debug.Log(string.Format("total: {0} ms", sw.ElapsedMilliseconds));
    }

}

using UnityEngine;
using System.Collections;

public class Test1 : MonoBehaviour {

	void Start () 
    {
        //1
        float t = Time.time;
        TestMethod();
        UnityEngine.Debug.Log(string.Format("total: {0} ms", Time.time - t));

        //2
        TestTool.CalculateTime(TestMethod);

        //3
        Profiler.BeginSample("TestMethod");
        TestMethod();
        Profiler.EndSample();
	}

    void TestMethod()
    {
        for (int i = 0; i < 1000; i++)
        {
            GameObject.CreatePrimitive(PrimitiveType.Cube);
        }
    }

}

在Profiler中找到第一帧,就可以看到耗时了。结果如下:




分析:

1.Time.time一帧更新一次

2.Stopwatch得出的时间和Profiler相近



http://www.niftyadmin.cn/n/880592.html

相关文章

[Unity优化]数据的加密与解密

原文链接&#xff1a;http://www.manew.com/forum.php?modviewthread&tid21682&_dsignf0374ae5 using UnityEngine; using System.Collections; using System.Text; using System.Security.Cryptography; using System;public class EncryptDecipherTool {//加密和解密…

[Unity优化]UGUI图集的使用

参考链接&#xff1a; http://www.xuanyusong.com/archives/3304 http://www.xuanyusong.com/archives/3315 Sprite Packer的使用&#xff1a; http://liweizhaolili.blog.163.com/blog/static/1623074420131151303310/ 关键点&#xff1a; 1.在unity5中&#xff0c;Stat…

[UnityUI]UGUI自适应

参考链接&#xff1a; http://www.jianshu.com/p/96fd1fbe8409 http://blog.sina.com.cn/s/blog_4148e8630102vji9.html http://www.xuanyusong.com/archives/3278 关键点&#xff1a; 0.自适应的测试&#xff1a;通过设置多种的屏幕大小进行测试&#xff0c;测试时最好…

[UnityUI]UGUI新手引导

相关链接&#xff1a;http://www.cnblogs.com/ybgame/p/3844315.html 效果图&#xff1a; 对于新手引导&#xff0c;主要分两种做法&#xff1a;需要使用shader的和不需要shader的&#xff0c;这里介绍的是后者 1.屏蔽点击 假如ImageA在ImageB前面&#xff0c;且ImageA完全覆…

[UnityShader2]ShaderLab基础

一.Shader 1.Shader即着色器&#xff0c;是一款运行在GPU上的程序。Shader有顶点Shader和片段Shader两个基本类型&#xff0c;顶点Shader有着可以处理、 变换&#xff0c;最终会渲染到屏幕上的网格物体的顶点位置的功能&#xff0c;但它不能生成新的顶点。 顶点Shader的输出会…

[UnityShader2]各种空间和基本光照模型

四种空间&#xff1a; 1.模型空间&#xff1a;每一个物体都有一个以它自己的中心点为原点的三维坐标空间。 a.在unity中&#xff0c;可以通过transform.worldToLocalMatrix这个矩阵的MultiplyPoint()或者MultiplyVector()方法&#xff0c;把世界坐标表达的矢量转换为此物体的…

[UnityShader2]图形学与CG基础

0.引入齐次坐标的意义&#xff1a; a.为了将空间向量与空间点进行区分&#xff0c;所以将三元数扩展到四元数&#xff0c;第四元如果是1&#xff0c;则表示点&#xff1b;如果是0&#xff0c;则表示向量。 b.使用四元数后&#xff0c;就可以通过四阶矩阵运算&#xff0c;将空…

[UnityShader2]顶点片段着色器基础

官方文档&#xff1a;http://docs.unity3d.com/Manual/SL-VertexFragmentShaderExamples.html 1.语义 SV_Traget&#xff1a;如果顶点/片段程序只输出一个值&#xff0c;那么可以使用这个 fixed4 frag (v2f i) : SV_TargetSV_POSITION&#xff1a;存储裁剪空间中的位置&#x…