自动质量设置

时间:2014-01-07 17:32:27

标签: android unity3d

我现在看到很多应用程序(Android),而不是选择屏幕来选择图形级别,它只是自动执行它,我知道这是一个很大的问题,但我怎么能为我做到这一点自己的应用?我可以研究哪些链接/资源?

3 个答案:

答案 0 :(得分:2)

以下摘自GameQualitySettings.js Bootcamp demo的动态质量设置:

function AutoChooseQualityLevel ()
{
    var shaderLevel = SystemInfo.graphicsShaderLevel;
    var fillrate = SystemInfo.graphicsPixelFillrate;
    var vram = SystemInfo.graphicsMemorySize;
    var cpus = SystemInfo.processorCount;
    if (fillrate < 0)
    {
        if (shaderLevel < 10)
            fillrate = 1000;
        else if (shaderLevel < 20)
            fillrate = 1300;
        else if (shaderLevel < 30)
            fillrate = 2000;
        else
            fillrate = 3000;
        if (cpus >= 6)
            fillrate *= 3;
        else if (cpus >= 3)
            fillrate *= 2;
        if (vram >= 512)
            fillrate *= 2;
        else if (vram <= 128)
            fillrate /= 2;
    }

    var resx = Screen.width;
    var resy = Screen.height;
    var fillneed : float = (resx*resy + 400*300) * (30.0 / 1000000.0);
    var levelmult : float[] = [5.0, 30.0, 80.0, 130.0, 200.0, 320.0];

    var level = 0;
    while (level < QualityLevel.Fantastic && fillrate > fillneed * levelmult[level+1])
        ++level;

    //print (String.Format("{0}x{1} need {2} has {3} = {4} level", resx, resy, fillneed, fillrate, level));

    overallQuality = level;
    UpdateAllSettings ();
}

这段代码显然缺乏原始脚本的所有功能,但是发布完整的脚本似乎有些过分。您可以使用QualitySettings类动态控制质量。

如果您需要设置分辨率,则会询问similar question

答案 1 :(得分:0)

我不确定你的意思,但这可能是你想要的Link

答案 2 :(得分:0)

我尚未验证这种填充率计算方法仍然非常有效!

我将Unity 5+的Bootcamp AutoChooseQualityLevel转换为C#(graphicsPixelFillrate不再存在,因此我们必须使用fillrate计算)。我还尝试解码一些深奥的部分。

假定您具有一个与QualitySettings.names值匹配的eQualityLevel枚举。

eQualityLevel AutoChooseQualityLevel()
{
    Assert.IsTrue(QualitySettings.names.Length == Enum.GetNames(typeof(eQualityLevel)).Length, "Please update eQualityLevel to the new quality levels.");

    var shaderLevel = SystemInfo.graphicsShaderLevel;
    var vram = SystemInfo.graphicsMemorySize;
    var cpus = SystemInfo.processorCount;
    var fillrate = 0;
    if (shaderLevel < 10)
        fillrate = 1000;
    else if (shaderLevel < 20)
        fillrate = 1300;
    else if (shaderLevel < 30)
        fillrate = 2000;
    else
        fillrate = 3000;
    if (cpus >= 6)
        fillrate *= 3;
    else if (cpus >= 3)
        fillrate *= 2;
    if (vram >= 512)
        fillrate *= 2;
    else if (vram <= 128)
        fillrate /= 2;

    var resx = Screen.width;
    var resy = Screen.height;
    var target_fps = 30.0f;
    var fillneed = (resx*resy + 400f*300f) * (target_fps / 1000000.0f);
    // Change the values in levelmult to match the relative fill rate
    // requirements for each quality level.
    var levelmult = new float[] { 5.0f, 30.0f, 80.0f, 130.0f, 200.0f, 320.0f };

    const int max_quality = (int)eQualityLevel.Fantastic;
    var level = 0;
    while (level < max_quality && fillrate > fillneed * levelmult[level+1])
        ++level;

    var quality = (eQualityLevel)level;
    Debug.Log(string.Format("{0}x{1} need {2} has {3} = {4} level", resx, resy, fillneed, fillrate, quality.ToString()));

    return quality;
}