Unity3D FPS帧数修改

修改Unity的FPS

FPS是游戏运行的帧数,本文讲解如何修改Unity引擎的FPS。

步骤

1、在 Edit/Project Settings/Quality  质量设置里把帧数设定关闭,关闭之后才能在代码中修改游戏运行的帧数。

Unity3D FPS帧数修改

UpdateFrame.cs

2、在Unity中创建新脚本UpdateFrame.cs ,代码

using UnityEngine;
using System.Collections; /// <summary>
/// 功能:修改游戏FPS
/// </summary>
public class UpdateFrame : MonoBehaviour
{
//游戏的FPS,可在属性窗口中修改
public int targetFrameRate = 300; //当程序唤醒时
void Awake ()
{
//修改当前的FPS
Application.targetFrameRate = targetFrameRate;
} }

3、把该代码及ShowFPS.js绑定在层次视图的任一GameObject上

Unity3D FPS帧数修改

尝试修改

4、运行游戏,即可以Game视图中看到当前的FPSUnity3D FPS帧数修改修改targetFrameRate变量,查看FPS的变化Unity3D FPS帧数修改

ShowFPS.js

@script ExecuteInEditMode

private var gui : GUIText;

private var updateInterval = 1.0;
private var lastInterval : double; // Last interval end time
private var frames = 0; // Frames over current interval function Start()
{
lastInterval = Time.realtimeSinceStartup;
frames = 0;
} function OnDisable ()
{
if (gui)
DestroyImmediate (gui.gameObject);
} function Update()
{
#if !UNITY_FLASH
++frames;
var timeNow = Time.realtimeSinceStartup;
if (timeNow > lastInterval + updateInterval)
{
if (!gui)
{
var go : GameObject = new GameObject("FPS Display", GUIText);
go.hideFlags = HideFlags.HideAndDontSave;
go.transform.position = Vector3(0,0,0);
gui = go.guiText;
gui.pixelOffset = Vector2(5,55);
}
var fps : float = frames / (timeNow - lastInterval);
var ms : float = 1000.0f / Mathf.Max (fps, 0.00001);
gui.text = ms.ToString("f1") + "ms " + fps.ToString("f2") + "FPS";
frames = 0;
lastInterval = timeNow;
}
#endif
}
上一篇:解决springMVC文件上传报错: The current request is not a multipart request


下一篇:Linux命令 find和mv的结合使用:查找文件,移动到某个目录