fps统计工具

1
#pragma strict
//////////////////////////////////////////////////////
///fps,累积方式.
//////////////////////////////////////////////////////
private var fps:int;

function Start(){
	if(!guiText){
		gameObject.AddComponent(GUIText);
	}
	transform.position = Vector3(0.9,0.14);
	guiText.material.color = Color.red;
	
	InvokeRepeating("Show",0,1);
}

function Show(){
	if(guiText){
		guiText.text = "fps:"+fps;
		fps = 0;
	}
}

function Update () {
	++fps;
}

2
private var mesh:Mesh;

/** 帧数(s) */
var showFps:boolean;
/** 顶点数(s) */
var showVps:boolean;

function Start(){
	mesh = FindObjectOfType(Mesh);
	if(!guiText)
		gameObject.AddComponent(GUIText);
	guiText.material.color = Color.red;
	guiText.transform.position = Vector3(0.8,0.14,0);
}

function LateUpdate(){
	var result:String = "";
	var time:float = Time.smoothDeltaTime;
		time = time == 0 ? 1 : time;
	if(mesh && showVps){
		var vps:int = mesh.vertexCount / time;
		result += "Vps:"+vps;
	}
	if(showFps){
		var fps:int = 1.0 / time;
		result += "Fps:"+fps;
	}
	guiText.text = result;
}

猜你喜欢

转载自superherosk123.iteye.com/blog/1402784