using System.Runtime.CompilerServices;
namespace UnityEngine.XR.ARFoundation
{
///
/// Use in place of Debug.Assert to conditionally generate the string for the assert message.
///
static class DebugAssert
{
public struct Message
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void WithMessage(string message)
{
Debug.Assert(false, message);
}
}
///
/// When both
/// - `UNITY_ASSERTIONS` is defined (for example, in a development build) AND
/// - is `false`
/// a new object is returned. This allows you to write code like
///
/// DebugAssert.That(foo == null)?.WithMessage($"{nameof(foo)} should be null but was {foo} instead");
///
/// Note the use of the null conditional (?.) -- this means the interpolated string in
/// is not evaluated if the assert condition passes. This can prevent the
/// creation of GC-allocated string objects when asserts are used several times per frame.
///
/// is what actually calls Debug.Assert, so make sure to provide a message.
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Message? That(bool condition)
{
#if UNITY_ASSERTIONS
if (!condition)
{
return new Message();
}
#endif
return null;
}
}
///
/// Use in place of Debug.LogWarning to conditionally generate the string for the warning message.
///
static class DebugWarn
{
public struct Message
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void WithMessage(string message)
{
Debug.LogWarning(message);
}
}
///
/// When both
/// - `DEVELOPMENT_BUILD` is defined (for example, in a development build) AND
/// - is `false`
/// a new object is returned. This allows you to write code like
///
/// DebugWarn.WhenFalse(foo == null)?.WithMessage($"{nameof(foo)} should be null but was {foo} instead");
///
/// Note the use of the null conditional (?.) -- this means the interpolated string in
/// is not evaluated if the assert condition passes. This can prevent the
/// creation of GC-allocated string objects when asserts are used several times per frame.
///
/// is what actually calls Debug.Assert, so make sure to provide a message.
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Message? WhenFalse(bool condition)
{
#if DEVELOPMENT_BUILD
if (!condition)
{
return new Message();
}
#endif
return null;
}
}
}