Created
December 5, 2012 18:42
-
-
Save anchan828/4218328 to your computer and use it in GitHub Desktop.
ログをブラウザのコンソールに出す WebPlayer用
This file contains 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
using UnityEngine; | |
public class DebugLog : MonoBehaviour | |
{ | |
void Awake () | |
{ | |
if (Debug.isDebugBuild) | |
Application.RegisterLogCallback (Handle); | |
} | |
void Handle (string log, string stack, LogType type) | |
{ | |
Application.ExternalEval ("window.console." + GetConsoleType (type) + "('" + log + "\\n" + stack.Replace ("\n", "\\n") + "')"); | |
} | |
private string GetConsoleType (LogType type) | |
{ | |
string _type = "log"; | |
switch (type) { | |
case LogType.Warning: | |
_type = "warn"; | |
break; | |
case LogType.Error: | |
case LogType.Exception: | |
case LogType.Assert: | |
_type = "error"; | |
break; | |
default: | |
throw new UnityException (); | |
} | |
return _type; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment