Boat Attack使用了Universal RP的许多新图形功能,可以用于探索 Universal RP 的使用方式和技巧。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

60 行
1.9 KiB

using System;
using UnityEngine.Profiling;
namespace UnityEngine.Rendering
{
public struct ProfilingSample : IDisposable
{
readonly CommandBuffer m_Cmd;
readonly string m_Name;
bool m_Disposed;
CustomSampler m_Sampler;
public ProfilingSample(CommandBuffer cmd, string name, CustomSampler sampler = null)
{
m_Cmd = cmd;
m_Name = name;
m_Disposed = false;
if (cmd != null && name != "")
cmd.BeginSample(name);
m_Sampler = sampler;
m_Sampler?.Begin();
}
// Shortcut to string.Format() using only one argument (reduces Gen0 GC pressure)
public ProfilingSample(CommandBuffer cmd, string format, object arg) : this(cmd, string.Format(format, arg))
{
}
// Shortcut to string.Format() with variable amount of arguments - for performance critical
// code you should pre-build & cache the marker name instead of using this
public ProfilingSample(CommandBuffer cmd, string format, params object[] args) : this(cmd, string.Format(format, args))
{
}
public void Dispose()
{
Dispose(true);
}
// Protected implementation of Dispose pattern.
void Dispose(bool disposing)
{
if (m_Disposed)
return;
// As this is a struct, it could have been initialized using an empty constructor so we
// need to make sure `cmd` isn't null to avoid a crash. Switching to a class would fix
// this but will generate garbage on every frame (and this struct is used quite a lot).
if (disposing)
{
if (m_Cmd != null && m_Name != "")
m_Cmd.EndSample(m_Name);
m_Sampler?.End();
}
m_Disposed = true;
}
}
}