Files
adriadri6972 d3d9c5f833 upload project
2025-07-31 15:21:08 +02:00

39 lines
1.6 KiB
C#

using System;
using UnityEngine.Profiling;
namespace UnityEngine.XR.ARSubsystems
{
/// <summary>
/// An `IDisposable` [profiler](https://docs.unity3d.com/ScriptReference/Profiling.Profiler.html)
/// object that will begin a profiler sample on instantiation and end the same when disposed.
/// </summary>
/// <example>
/// <code>
/// using (new ScopedProfiler("MySample"))
/// {
/// CodeToProfile();
/// }
/// </code>
/// </example>
public struct ScopedProfiler : IDisposable
{
/// <summary>
/// Begins a new profiler sample. Same as [Profiler.BeginSample](https://docs.unity3d.com/ScriptReference/Profiling.Profiler.BeginSample.html).
/// </summary>
/// <param name="name">A string to identify the sample in the Profiler window.</param>
public ScopedProfiler(string name) => Profiler.BeginSample(name);
/// <summary>
/// Begins a new profiler sample. Same as [Profiler.BeginSample](https://docs.unity3d.com/ScriptReference/Profiling.Profiler.BeginSample.html).
/// </summary>
/// <param name="name">A string to identify the sample in the Profiler window.</param>
/// <param name="targetObject">An object that provides context to the sample.</param>
public ScopedProfiler(string name, UnityEngine.Object targetObject) => Profiler.BeginSample(name, targetObject);
/// <summary>
/// Ends the current profiling sample. Same as [Profiler.EndSample](https://docs.unity3d.com/ScriptReference/Profiling.Profiler.EndSample.html).
/// </summary>
public void Dispose() => Profiler.EndSample();
}
}