Skip to content

Commit

Permalink
update to latest Unity API and remove GUIText to avoid annoying warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
prime31 committed Sep 10, 2018
1 parent 9db2a65 commit c81500d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 38 deletions.
45 changes: 10 additions & 35 deletions Assets/Demo/scripts/FPSHUD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,14 @@
using System.Collections;


[RequireComponent( typeof( GUIText ) )]
public class FPSHUD : MonoBehaviour
{

// Attach this to a GUIText to make a frames/second indicator.
//
// It calculates frames/second over each updateInterval,
// so the display does not keep changing wildly.
//
// 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.

public float updateInterval = 0.5f;

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


void Awake()
Expand All @@ -33,12 +21,6 @@ void Awake()

void Start()
{
if( !GetComponent<GUIText>() )
{
Debug.Log("UtilityFramesPerSecond needs a GUIText component!");
enabled = false;
return;
}
timeleft = updateInterval;
}

Expand All @@ -52,27 +34,20 @@ void Update()
// Interval ended - update GUI text and start new interval
if( timeleft <= 0.0 )
{
// display two fractional digits (f2 format)
float fps = accum/frames;
string format = System.String.Format("{0:F2} FPS",fps);
GetComponent<GUIText>().text = format;

if( fps < 20 )
{
GetComponent<GUIText>().material.color = Color.yellow;
}
else
fps = accum/frames;
if( fps > 20 )
{
if( fps < 10 )
GetComponent<GUIText>().material.color = Color.red;
else
GetComponent<GUIText>().material.color = Color.green;

timeleft = updateInterval;
accum = 0.0F;
accum = 0.0f;
frames = 0;
}
}
}


void OnGUI()
{
GUI.Label( new Rect( 0, 0, 100, 40 ), string.Format( "{0:F2} FPS", fps ) );
}

}
7 changes: 4 additions & 3 deletions Assets/Editor/GoDummyPathEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ void OnSceneGUI()
Quaternion.identity,
handleSize,
new Vector3( 5, 0, 5 ),
Handles.SphereCap );
Handles.SphereHandleCap );
}


Expand All @@ -333,7 +333,8 @@ void OnSceneGUI()
var color = Color.red;
color.a = 0.3f;
Handles.color = color;
Handles.SphereCap( 0, _target.nodes[i], Quaternion.identity, _snapDistance * 2 );
//Handles.SphereCap( 0, _target.nodes[i], Quaternion.identity, _snapDistance * 2 );
Handles.SphereHandleCap( 0, _target.nodes[i], Quaternion.identity, 1, EventType.Repaint );
//Handles.DrawWireDisc( _target.nodes[i], Vector3.up, _snapDistance );
Handles.color = Color.white;
}
Expand Down Expand Up @@ -400,7 +401,7 @@ private void drawArrowBetweenPoints( Vector3 point1, Vector3 point2 )
// get the midpoint between the 2 points
var dir = Vector3.Lerp( point1, point2, lerpModifier );
var quat = Quaternion.LookRotation( point2 - point1 );
Handles.ArrowCap( 0, dir, quat, 25 );
Handles.ArrowHandleCap( 0, dir, quat, 25, EventType.Repaint );

Handles.color = Color.white;
}
Expand Down

0 comments on commit c81500d

Please sign in to comment.