playMaker

Author Topic: FPS counter  (Read 5089 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
FPS counter
« on: June 15, 2012, 03:57:16 AM »
Hi,

 following a request, please find a FPS counter. I took one from the unify wiki:

http://unifycommunity.com/wiki/index.php?title=FramesPerSecond

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2012. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Time)]
[Tooltip("It calculates frames/second over each updateInterval.It is also fairly accurate at very low FPS counts (<10)." +
"We do this not by simply counting frames per interval, but" +
"by accumulating FPS for each frame. This way we end up with" +
"correct overall FPS even if the interval renders something like 5.5 frames. " +
"credits: http://unifycommunity.com/wiki/index.php?title=FramesPerSecond")]
public class GetFPS : FsmStateAction
{

[Tooltip("Interval sampling")]
public FsmFloat updateInterval = 0.5f;

  float accum = 0f; // FPS accumulated over the interval
  int frames = 0; // Frames drawn over the interval
  float timeleft ; // Left time for current interval


[Tooltip("The current Frame per second")]
public FsmFloat FPS;

[Tooltip("The current Frame per second formated as string")]
public FsmString FPS_asString;

public override void Reset()
{
updateInterval = 0.5f;
FPS = null;
}


public override void OnUpdate()
{
   timeleft -= Time.deltaTime;
    accum += Time.timeScale/Time.deltaTime;
    ++frames;
   
    // Interval ended - update GUI text and start new interval
    if( timeleft <= 0.0 )
    {
FPS.Value = accum/frames;
FPS_asString.Value = "" + (accum/frames).ToString("f2"); // display two fractional digits (f2 format)
       
        timeleft = updateInterval.Value;
        accum = 0f;
        frames = 0;
    }
}
}
}

Bye,

 Jean

Dev_Sebas

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 398
    • View Profile
    • Blog
Re: FPS counter
« Reply #1 on: June 15, 2012, 06:45:47 AM »
Sweat thankĀ“s a lot!
Bye

Saputo

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Re: FPS counter
« Reply #2 on: March 01, 2013, 10:24:18 AM »
IS there A way to make this show up in the Conner of he Screen an be turned on and Off, If the Player wants to see it or not.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: FPS counter
« Reply #3 on: March 15, 2013, 07:41:10 AM »
Hi,

 yes, you simply inject that fps value into a guiText using:

https://hutonggames.fogbugz.com/default.asp?W220

bye,

 Jean