J.K*_*orn 3 c# unity-game-engine
从昨天起,我的统一游戏在Android设备上锁定了30fps.之前它像150fps ..我禁用了v-sync.这是我昨天添加的唯一脚本:
public static class SaveLoadProgress {
public static void Save()
{
LevelManager levelManager = GameObject.Find ("GameManager").GetComponent<LevelManager> ();
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Create (Application.persistentDataPath + "/savedProgress.1912");
bf.Serialize(file, levelManager.levelReached);
file.Close();
}
public static void Load()
{
LevelManager levelManager = GameObject.Find ("GameManager").GetComponent<LevelManager> ();
if(File.Exists(Application.persistentDataPath + "/savedProgress.1912"))
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/savedProgress.1912", FileMode.Open);
levelManager.levelReached = (int)bf.Deserialize(file);
file.Close();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我不这可能是问题所在.我把它添加到了GameManager:
void Awake()
{
Application.targetFrameRate = -1;
QualitySettings.vSyncCount = 0;
}
Run Code Online (Sandbox Code Playgroud)
分析器显示:
我应该怎么做才能从30fps解锁?
根据当前平台,默认情况下,unity会锁定特定值的fps.文档说Android的默认值为30,大多数Android设备都使用它.它还说:
默认的targetFrameRate是一个特殊值-1,表示游戏应以平台的默认帧速率呈现.
正如文章中所述,移动设备为30.
此外,在编辑器中运行游戏时,你可以拥有尽可能多的fps,它可能是150或更多,但是超过60(iPhone和一些Andoids的最大值)是非常糟糕的做法.如果你有超过60 fps你实际上看不出差异,因为设备的显示实际上不能渲染每秒超过60帧,但它需要电池和CPU资源和所有这些计算(额外的60+ fps)是无用的甚至不好
要使你的fps超过30,你可以像在代码中那样将它设置为60:
Application.targetFrameRate = 60;
Run Code Online (Sandbox Code Playgroud)
此外,v-sync主要不适用于移动设备,因此您无需为此烦恼.
| 归档时间: |
|
| 查看次数: |
10278 次 |
| 最近记录: |