Advertisement
Muk99

DevelopmentBuildOnly

Mar 31st, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3.  
  4. namespace Sonar.Misc {
  5.     public class DevelopmentBuildOnly : MonoBehaviour {
  6.  
  7.         public Text consoleText;
  8.         public bool logStack;
  9.  
  10.         public Color errorColor;
  11.         public Color warningColor;
  12.  
  13. #if DEBUG
  14.         [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
  15.         private static void Init() {
  16.             var instance = FindObjectOfType<DevelopmentBuildOnly>();
  17.             Application.logMessageReceived += (message, stack, type) => {
  18.                 var color = Color.white;
  19.  
  20.                 switch(type) {
  21.                     case LogType.Assert:
  22.                     case LogType.Error:
  23.                     case LogType.Exception:
  24.                         color = instance.errorColor;
  25.                         break;
  26.  
  27.                     case LogType.Warning:
  28.                         color = instance.warningColor;
  29.                         break;
  30.                 }
  31.  
  32.                 if(instance.logStack)
  33.                     instance.consoleText.text += string.Format("<color=#{3}>{0}: {1} at {2}\n\n</color>", type, message, stack, ColorUtility.ToHtmlStringRGB(color));
  34.                 else
  35.                     instance.consoleText.text += string.Format("<color=#{2}>{0}: {1}\n\n</color>", type, message, ColorUtility.ToHtmlStringRGB(color));
  36.             };
  37.         }
  38. #endif
  39.  
  40. #if !DEBUG
  41.         private void Start() {
  42.             Destroy(gameObject);
  43.         }
  44. #endif
  45.  
  46.         public void ResetData() {
  47.             PlayerPrefs.DeleteAll();
  48.         }
  49.  
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement