【问题标题】:(UNITY3d android game) When i don't touch the screen, my fps are lower than when i touch(UNITY3d android 游戏)当我不触摸屏幕时,我的 fps 比我触摸时低
【发布时间】:2015-08-29 07:45:00
【问题描述】:

我很长一段时间以来在手机上的流畅相机(平台游戏)上遇到问题,但我报告说当我的 fps 不低于 60 时我的游戏运行良好。我注意到我的 fps 很好我触摸屏幕,但是当我不这样做时,fps 会下降到大约 58、59,之后我的相机不能顺利地跟随我的播放器。为了测试,我只用 FPSCounter 脚本创建了新场景,效果是一样的。有人可以帮我吗?我认为这是引擎设置的原因,但我无法处理它。强调文本

//---------------------------------------------
// VARIABLES
//---------------------------------------------

private float deltaTime = 0.0f;

//---------------------------------------------
// METHODS FROM SUPERCLASS
//---------------------------------------------

void Update()
{
deltaTime += (Time.deltaTime - deltaTime) * 0.1f;
}

void OnGUI()
{
GUIStyle style = new GUIStyle();
float x = Screen.width - 110;
float fps = 1.0f / deltaTime;

Rect rect = new Rect(x, 90, 100, 50);

style.fontSize = 18;
style.normal.textColor = getColor(fps);

string text = string.Format("{0:0,0.0000 FPS}",fps);
GUI.Label(rect, text, style);
}

//---------------------------------------------
// CLASS LOGIC
//---------------------------------------------

private Color getColor(float fps)
{
if (fps >= 60)
{
return Color.yellow;
}
return Color.red;
}

【问题讨论】:

    标签: android unity3d touch frame-rate


    【解决方案1】:

    您是否尝试过使用 Unity 4.6 中引入的新 UI 系统?也许这可以解决您的问题。 https://www.youtube.com/watch?v=EOX6itCuKOc

    【讨论】:

      【解决方案2】:

      如前所述,您真的应该切换到新的 UI 系统,因为旧的 GUI 系统总是一场噩梦。

      但是,如果您不想切换,请尝试在 OnGUI 之外设置更多变量。

      OnGUI 每帧调用多次,而且如此频繁地设置 GUI 样式等成本很高 - 特别是在性能已经很差的行为上。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多