Last active
August 29, 2015 14:02
-
-
Save sassembla/cd59e9c9e0f6c4784f78 to your computer and use it in GitHub Desktop.
Simple Assertion in Unity.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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