Skip to content

Instantly share code, notes, and snippets.

@sassembla
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sassembla/cd59e9c9e0f6c4784f78 to your computer and use it in GitHub Desktop.
Save sassembla/cd59e9c9e0f6c4784f78 to your computer and use it in GitHub Desktop.
Simple Assertion in Unity.
static class Assertions {
/**
assert which extends bool.
usage:
(0 < transform.position.y).Assert("fall in negative.");
*/
public static void Assert (this bool condition, string reason) {
if (condition) return;
System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(true);
for (int i = 0; i < st.FrameCount; i++) {
// 1st line is about the StackTrace start line, unnecessary.
if (i < 1) continue;
var assertFaildPointDescription = st.GetFrame(i).ToString();
Debug.LogError("E:" + assertFaildPointDescription + " assert failed, reason:" + reason);
}
Debug.Break();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment