Created
March 26, 2015 12:43
-
-
Save CosmoCleaner/a322f70714741d78ad00 to your computer and use it in GitHub Desktop.
LiveConsole用Hook : タグを識別して色分け例
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 CielaSpike.Unity.LiveConsole; | |
using UnityEngine; | |
[assembly: LiveConsoleHook (typeof(MyGame.ColorByTag))] | |
/// <summary> | |
/// LiveConsoleのタグに色付けするHook | |
/// </summary> | |
namespace MyGame | |
{ | |
class ColorByTag : LiveConsoleHook | |
{ | |
protected override bool IsEnabled () | |
{ | |
// true でHook有効 | |
// LiveConsoleタブウィンドウを右クリックして"Reload Hooks"すれば再読込される | |
return true; | |
} | |
protected override HookResult OnTaggingLogEntry (EntryInfo entry, out string tag, out TagColor tagColor) | |
{ | |
// EntryInfoからタグの読み取り | |
System.Text.RegularExpressions.Regex r = | |
new System.Text.RegularExpressions.Regex ( | |
@"^\[[a-zA-Z0-9!]+", | |
System.Text.RegularExpressions.RegexOptions.IgnoreCase); | |
System.Text.RegularExpressions.Match m = r.Match (entry.Content); | |
if (m.Success) { | |
tag = m.Value.Substring (1); | |
} else { | |
tag = "Log"; | |
} | |
tagColor = TagColor.Cyan; | |
switch (tag) { | |
default: | |
return HookResult.Default; | |
// 例えば通信系で色を変える | |
case "Socket": | |
tagColor = TagColor.Cyan; | |
break; | |
case "POST": | |
tagColor = TagColor.Green; | |
break; | |
case "GET": | |
tagColor = TagColor.Yellow; | |
break; | |
// 例えば単に目立たせたい | |
case "!": | |
tagColor = TagColor.Red; | |
break; | |
} | |
return HookResult.Hooked; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment