-
-
Save todorok1/332628fde71a22cb5c1adf353906683b to your computer and use it in GitHub Desktop.
ゲーミングDebug.Logのサンプルクラス
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 System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
/// <Summary> | |
/// ゲーミングデバッグ文を出力するクラスです。 | |
/// </Summary> | |
public static class GamingDebug | |
{ | |
// 現在の色のインデックスを保持します。 | |
static int currentColorIndex; | |
/// <Summary> | |
/// 同じ行内で文字の色を変化させて出力します。 | |
/// </Summary> | |
public static void OutputLine(string msg, ColorCodeHolder.ColorToneName toneName) | |
{ | |
// 文字の色を定義した配列を取得します。 | |
string[] colorCodeArray = ColorCodeHolder.GetColorToneArray(toneName); | |
System.Text.StringBuilder sb = new System.Text.StringBuilder(); | |
for (int i = 0; i < msg.Length; i++) | |
{ | |
char targetChar = msg[i]; | |
// 1文字ずつ色を変えてループするようにします。 | |
int colorIndex = i % colorCodeArray.Length; | |
string colorName = colorCodeArray[colorIndex]; | |
sb.Append(GetColorTagPrefix(colorName)) | |
.Append(targetChar) | |
.Append(GetColorTagPostfix()); | |
} | |
// タグをつけたメッセージをコンソールに出力します。 | |
Debug.Log(sb.ToString()); | |
} | |
/// <Summary> | |
/// 行ごとに文字の色を変化させて出力します。 | |
/// </Summary> | |
public static void OutputColoredLine(string msg, ColorCodeHolder.ColorToneName toneName) | |
{ | |
// 文字の色を定義した配列を取得します。 | |
string[] colorCodeArray = ColorCodeHolder.GetColorToneArray(toneName); | |
// 1文字ずつ色を変えてループするようにします。 | |
currentColorIndex = currentColorIndex % colorCodeArray.Length; | |
string colorName = colorCodeArray[currentColorIndex]; | |
string tagPrefix = GetColorTagPrefix(colorName); | |
string tagPostfix = GetColorTagPostfix(); | |
string outputMsg = $"{tagPrefix}{msg}{tagPostfix}"; | |
// タグをつけたメッセージをコンソールに出力します。 | |
Debug.Log(outputMsg); | |
currentColorIndex++; | |
} | |
/// <Summary> | |
/// 色を変更するタグの開始タグを取得します。 | |
/// </Summary> | |
static string GetColorTagPrefix(string colorName) | |
{ | |
return $"<color={colorName}>"; | |
} | |
/// <Summary> | |
/// 色を変更するタグの終了タグを取得します。 | |
/// </Summary> | |
static string GetColorTagPostfix() | |
{ | |
return $"</color>"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment