Skip to content

Instantly share code, notes, and snippets.

@v01pe
Created December 1, 2016 15:39
Show Gist options
  • Save v01pe/b6e5f33bd6f64deeb75204b4656d0d59 to your computer and use it in GitHub Desktop.
Save v01pe/b6e5f33bd6f64deeb75204b4656d0d59 to your computer and use it in GitHub Desktop.
In Unity add a menu item that toggles between dynamic and the default profiler sample size.
using UnityEngine;
using UnityEditor;
[InitializeOnLoad]
public static class DebugMenu
{
private static int defaultMaxNumberOfSamplesPerFrame = -1;
private static bool dynamicProfilerSamplesSize = false;
private const string toggleDynamicProfilerSamplesSizeName = "Debug/Dynamic Profiler Sample Size";
static DebugMenu()
{
if (defaultMaxNumberOfSamplesPerFrame == -1)
defaultMaxNumberOfSamplesPerFrame = Profiler.maxNumberOfSamplesPerFrame;
}
[MenuItem(toggleDynamicProfilerSamplesSizeName)]
public static void ToggleDynamicProfilerSamplesSize()
{
dynamicProfilerSamplesSize = !dynamicProfilerSamplesSize;
Menu.SetChecked(toggleDynamicProfilerSamplesSizeName, dynamicProfilerSamplesSize);
Profiler.maxNumberOfSamplesPerFrame = dynamicProfilerSamplesSize ? -1 : defaultMaxNumberOfSamplesPerFrame;
if (dynamicProfilerSamplesSize)
Debug.LogWarning("Profiler sample size is set to dynamic");
else
Debug.Log("Profiler sample size has been set back to " + defaultMaxNumberOfSamplesPerFrame);
}
}
@v01pe
Copy link
Author

v01pe commented Dec 1, 2016

Drop this file in a folder called Editor within your Assets folder. You'll find the new item in the menu at Debug -> Dynamic Profiler Sample Size

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment