Table of Contents
Measure It!
Measure It! is a small C# script we use while developing in Unity. It stores various statistics and displays them on screen whether in playmode or in editor. This is especially useful for Unity Indie users who don't have access to the profiler of the Pro version.
Features
- Measure execution times in various units (Ticks, Milliseconds, Seconds) and show Min/Max/Average values
- Display variables and custom text
- Counting
- Console logging
- Toggle console output using debug groups
Usage
Measure It! stores information in slots. A case-sensitive string (slotName) is used to create and refer to slots and to display slot's values.
Profiling example
MeasureIt.Begin("Calculation time"); //do some stuff Measureit.End("Calculation time");
Counting example
MeasureIt.Count("Clicks"); Displaying custom text example MeasureIt.Set("Current event",Event.current);
Clear a slot
MeasureIt.Clear("Click"); // clear a single slot MeasureIt.Clear(); // clear all slots
Console Log
MeasureIt.Log("Hello world","aCustomDebugGroup"); // only shown if aCustomDebugGroup isn't muted!
Working with Groups
MeasureIt.MuteGroup("aCustomDebugGroup"); // mute all debug output for aCustomDebugGroup MeasureIt.UnMuteAllGroups(); // Clear list of muted Objects
Example
using UnityEngine; using System.Collections; public class ClickToMove : MonoBehaviour { void Update() { if (Input.GetMouseButtonUp(0)) { MeasureIt.Count("Clicks"); MeasureIt.End("Time between Clicks (s)"); MeasureIt.Begin("Time between Clicks (s)"); Ray r = Camera.main.ScreenPointToRay(Input.mousePosition); transform.position = r.GetPoint(-Camera.main.transform.position.z); } transform.Translate(new Vector3(10,10,10)*Time.deltaTime); } void OnGUI() { if (GUILayout.Button("Clear Time")) MeasureIt.Clear("Time between Clicks"); if (GUILayout.Button("Clear Counter")) MeasureIt.Clear("Clicks"); if (GUILayout.Button("Clear all")) MeasureIt.Clear(); GUILayout.Label("Resolution (nanoseconds): " + MeasureIt.ResolutionNs); if (MeasureIt.IsHighResolutionTimer) GUILayout.Label("HighRes-Timer!"); MeasureIt.Set("Cursor", Event.current.mousePosition); } }