Skip to content

Instantly share code, notes, and snippets.

@anchan828
Created December 5, 2012 18:42
Show Gist options
  • Save anchan828/4218328 to your computer and use it in GitHub Desktop.
Save anchan828/4218328 to your computer and use it in GitHub Desktop.
ログをブラウザのコンソールに出す WebPlayer用
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