Venryx

CustomDebug

Oct 15th, 2016 (edited)
226
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Diagnostics.CodeAnalysis;
  3. using System.Runtime.InteropServices;
  4. using UnityEngine;
  5.  
  6. public static class CustomDebug {
  7.     public static bool pauseExecutionEnabled = true;
  8.     public static void Assert(bool condition, object message = null) {
  9.         if (condition) return;
  10.  
  11.         Debug.Assert(false, message);
  12.         if (!pauseExecutionEnabled) return;
  13.  
  14.         var result = MessageBox(new HandleRef(null, GetActiveWindow()), $@"Assert failed) {message}
  15.  
  16.    StackTrace) {Environment.StackTrace}", "Assert failed [execution paused]", 1); // 1 means show OK and Cancel buttons
  17.         if (result == 2) // if cancel button was pressed
  18.             pauseExecutionEnabled = false;
  19.         "".ToString(); // place breakpoint here
  20.     }
  21.  
  22.     [DllImport("User32", ExactSpelling = true, CharSet = CharSet.Auto)]
  23.     public static extern IntPtr GetActiveWindow();
  24.     [DllImport("User32", CharSet = CharSet.Auto), SuppressMessage("Microsoft.Usage", "CA2205:UseManagedEquivalentsOfWin32Api")]
  25.     public static extern int MessageBox(HandleRef hWnd, string text, string caption, int type);
  26. }
RAW Paste Data