纳金网

标题: Unity3D中显示运行帧数的代码 [打印本页]

作者: 狂风大尉    时间: 2014-6-26 20:04
标题: Unity3D中显示运行帧数的代码

  1. //创建一个js脚本,然后写好后加入到GUItext即可

  2. var updateInterval = 0.5;

  3. private var accum = 0.0; // FPS accumulated over the interval
  4. private var frames = 0; // Frames drawn over the interval
  5. private var timeleft : float; // Left time for current interval

  6. function Start()
  7. {
  8. if( !guiText )
  9. {
  10. print ("FramesPerSecond needs a GUIText component!");
  11. enabled = false;
  12. return;
  13. }
  14. timeleft = updateInterval;
  15. }

  16. function Update()
  17. {
  18. timeleft -= Time.deltaTime;
  19. accum += Time.timeScale/Time.deltaTime;
  20. ++frames;

  21. // Interval ended - update GUI text and start new interval
  22. if( timeleft <= 0.0 )
  23. {
  24. // display two fractional digits (f2 format)
  25. guiText.text = "" + (accum/frames).ToString("f2");
  26. timeleft = updateInterval;
  27. accum = 0.0;
  28. frames = 0;
  29. }
  30. }
复制代码
来源:http://www.unity3d8.com/






作者: hyui    时间: 2014-6-26 21:22
感谢分享这个!
作者: HIDEOKOJIMA    时间: 2014-6-26 22:40
感谢分享这个!
作者: wucnj    时间: 2014-6-27 13:20
感谢分享!!!
作者: wa5145416    时间: 2014-8-15 18:10
挺厉害的。。




欢迎光临 纳金网 (http://wwww.narkii.com/club/) Powered by Discuz! X2.5