Last active
March 24, 2017 05:50
-
-
Save wotakuro/a42641e99707d4b1b624f61f75c6e1f4 to your computer and use it in GitHub Desktop.
Make inserting Profiler call to your code more easily.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
#if UNITY_5_5_OR_NEWER | |
using UnityEngine.Profiling; | |
#else | |
using UnityEngine; | |
#endif | |
/** Make inserting Profiler call to your code more easily. | |
* | |
* // use like this | |
* void Test(){ | |
* using( ProfilingUtil.Sample("TestFunction") ){ | |
* // execute Something... | |
* } | |
* } | |
* | |
*/ | |
public class ProfilingUtil : System.IDisposable { | |
public static ProfilingUtil Sample(string name) | |
{ | |
return new ProfilingUtil(name); | |
} | |
private ProfilingUtil(string name) | |
{ | |
Profiler.BeginSample(name); | |
} | |
public void Dispose() | |
{ | |
Profiler.EndSample(); | |
} | |
public static bool SampleMoveNext(string name, IEnumerator e) | |
{ | |
using (var tmp = new ProfilingUtil(name + e.ToString())) | |
{ | |
return e.MoveNext(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment