孙广东:2015-2-7/1:19 转载请注明出处:http://blog.csdn.net/u010019717
更全的内容请看我的游戏蛮牛地址:http://www.unitymanual.com/space-uid-18602.html
先看一下效果: 告别枯燥乏味和单调吧!
其实很简单的, 就是让字符串中有Rich Text标记, 因为unity支持,所以使用就行了。
可以详细阅读如下的内容:
http://docs.unity3d.com/Manual/StyledText.html
然后我们分别在Editor编辑器和游戏中分别测试
添加代码如下:
新建“Editor” 文件夹, 添加如下两个文件。
EditorHelper.cs
using UnityEngine;
using System.Collections;
public static class EditorHelper
{
// ......
}
/// <summary>
/// 个性化的编辑器的Log输出格式化
/// </summary>
public static class EditorLog
{
public static void Log(string log)
{
Debug.Log (string.Format ("<b><color={0}><size={1}>{2}</size></color></b>", "lime", 15, log));
}
public static void LogError(string logError)
{
Debug.LogError (string.Format ("<b><color={0}><size={1}>{2}</size></color></b>", "red", 15, logError));
}
public static void LogWarning(string logWarning)
{
Debug.LogWarning (string.Format ("<b><color={0}><size={1}>{2}</size></color></b>", "yellow", 15, logWarning));
}
}MyEditor.cs
using UnityEngine;
using System.Collections;
using UnityEditor;
public class MyEditor : EditorWindow {
[MenuItem ("Game/My EditorWindow #%&a")] // 快捷键 Shift + Ctrl + Alt +A
static void Init () {
// Get existing open window or if none, make a new one:
MyEditor window = (MyEditor)EditorWindow.GetWindow (typeof (MyEditor));
}
// Use this for initialization
void OnEnable () {
EditorLog.Log ("这是Editor正常输出的测试!");
EditorLog.LogWarning ("这是Editor警告输出的测试!");
EditorLog.LogError ("这是Editor错误输出的测试!");
}
}然后我们在编辑器中点击如下菜单, 就会看到控制台的输出。
在继续编写脚本。 不放在特殊的文件夹下面。
GameHelper.cs
using UnityEngine;
using System.Collections;
public static class GameHelper
{
// ......
}
/// <summary>
/// 个性化的编辑器的Log输出格式化
/// </summary>
public static class GameLog
{
public static void Log(string log)
{
Debug.Log (string.Format ("<b><color={0}><size={1}>{2}</size></color></b>", "lime", 15, log));
}
public static void LogError(string logError)
{
Debug.LogError (string.Format ("<b><color={0}><size={1}>{2}</size></color></b>", "red", 15, logError));
}
public static void LogWarning(string logWarning)
{
Debug.LogWarning (string.Format ("<b><color={0}><size={1}>{2}</size></color></b>", "yellow", 15, logWarning));
}
}GameLogTest.cs
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class GameLogTest : MonoBehaviour {
// Use this for initialization
void Start () {
GameLog.Log ("这是Game正常输出的测试!");
GameLog.LogWarning ("这是Game警告输出的测试!");
GameLog.LogError ("这是Game错误输出的测试!");
}
// Update is called once per frame
void Update () {
}
}我们将脚本GameLogTest.cs挂到场景的任意对象上。就会看到控制台新的输出了。
OK
原文地址:http://blog.csdn.net/u010019717/article/details/43582737