zoukankan      html  css  js  c++  java
  • Unity中Debug打印信息的颜色设置

    为了更好的识别打印信息,这里封装了一下打印信息的工具类,虽然Unity中已经很好的识别..但是自己还是想实现新的工具类

    DebugBase脚本:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class DebugBase<T> where T :new()
    {
    	/// <summary>
    	/// 泛型单例
    	/// </summary>
    	static T instance;
    
    	public static T Instance {
    		get {
    			if (instance == null) {
    				instance = new T ();
    			}
    			return instance;
    		}
    	}
    
    	/// <summary>
    	/// 普通打印信息
    	/// </summary>
    	/// <param name="msg">Message.</param>
    	public virtual void Log (string msg)
    	{
    		if (!string.IsNullOrEmpty (msg)) {
    			Debug.Log (msg);
    		}
    	}
    
    	/// <summary>
    	/// 警告打印
    	/// </summary>
    	/// <param name="msg">Message.</param>
    	public virtual void LogWarning (string msg)
    	{
    		if (!string.IsNullOrEmpty (msg)) {
    			Debug.LogWarning (msg);
    		}
    	}
    
    	/// <summary>
    	/// 错误打印
    	/// </summary>
    	/// <param name="msg">Message.</param>
    	public virtual void LogError (string msg)
    	{
    		if (!string.IsNullOrEmpty (msg)) {
    			Debug.LogError (msg);
    		}
    	}
    }
    
    public class GameLog :DebugBase<GameLog>
    {
    	/// <summary>
    	/// 重写父类Log
    	/// </summary>
    	/// <param name="msg">Message.</param>
    	public override void Log (string msg)
    	{
    		if (!string.IsNullOrEmpty (msg)) {
    			base.Log ("*LOG*<color=white>" + msg + "</color>");
    		}
    	}
    
    	/// <summary>
    	/// 重写父类LogWarning
    	/// </summary>
    	/// <param name="msg">Message.</param>
    	public override void LogWarning (string msg)
    	{
    		if (!string.IsNullOrEmpty (msg)) {
    			base.LogWarning ("*Warning*<color=yellow>" + msg + "</color>");
    		}
    	}
    
    	/// <summary>
    	/// 重写父类LogError
    	/// </summary>
    	/// <param name="msg">Message.</param>
    	public override void LogError (string msg)
    	{
    		if (!string.IsNullOrEmpty (msg)) {
    			base.LogError ("*Error*<color=red>" + msg + "</color>");
    		}
    	}
    }
    

      Test脚本:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    
    public class Test : MonoBehaviour
    {
    	Button btn;
    
    	// Use this for initialization
    	void Start ()
    	{
    		btn = transform.Find ("Button").GetComponent <Button> ();
    		btn.onClick.AddListener (delegate() {
    			GameLog.Instance.Log ("这是一个LOG");
    			GameLog.Instance.LogWarning ("这是一个LogWarning");
    			GameLog.Instance.LogError ("这是一个LogError");
    		});
    	}
    }
    

      效果如下:

  • 相关阅读:
    Go part 7 反射,反射类型对象,反射值对象
    activemq BytesMessage || TextMessage
    Go part 6 接口,接口排序,接口嵌套组合,接口与类型转换,接口断言
    mysql 查询表的字段名称,字段类型
    冒泡(bubblesort)、选择排序、插入排序、快速排序
    用 python 写一个模拟玩家移动的示例
    day 14(作业)
    day 13
    day 12
    day 11
  • 原文地址:https://www.cnblogs.com/jbw752746541/p/9436404.html
Copyright © 2011-2022 走看看