hellbound/Assets/Scripts/Core/Error.cs

78 lines
1.5 KiB
C#

//#define STRIP_ASSERTS
using System;
using System.Diagnostics;
public struct ErrorStatus
{
public int error;
public string msg;
public void Reset()
{
error = 0;
msg = "";
}
public bool IsOk()
{
return error == 0 && string.IsNullOrEmpty(msg);
}
}
public class Error
{
#if STRIP_ASSERTS
[Conditional("COND_STRIP_ASSERTS")]
public static void Assert(bool condition) {}
#else
#if !UNITY_EDITOR
[Conditional("GAME_IS_DEV")]
#endif
public static void Assert(bool condition)
{
if(!condition) throw new Exception();
}
#endif
#if STRIP_ASSERTS
[Conditional("COND_STRIP_ASSERTS")]
public static void Assert(bool condition, string fmt, params object[] vals) {}
#else
#if !UNITY_EDITOR
[Conditional("GAME_IS_DEV")]
#endif
public static void Assert(bool condition, string fmt, params object[] vals)
{
if(!condition) throw new Exception(string.Format(fmt, vals));
}
#endif
#if STRIP_ASSERTS
[Conditional("COND_STRIP_ASSERTS")]
public static void Assert(bool condition, string msg) {}
#else
#if !UNITY_EDITOR
[Conditional("GAME_IS_DEV")]
#endif
public static void Assert(bool condition, string msg)
{
if(!condition) throw new Exception(msg);
}
#endif
public static void Verify(bool condition)
{
if(!condition) throw new Exception();
}
public static void Verify(bool condition, string fmt, params object[] vals)
{
if(!condition) throw new Exception(string.Format(fmt, vals));
}
public static void Verify(bool condition, string msg)
{
if(!condition) throw new Exception(msg);
}
}