1、在Quality(质量)设置里把帧数设定关闭,之后才能在代码中修改游戏运行的帧数
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上
运行游戏,即可以Game视图中看到当前的FPS
同时可修改targetFrameRate变量来观看结果
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
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)