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");
    		});
    	}
    }
    

      效果如下:

  • 相关阅读:
    vue element 表格错位问题
    echarts tooltip 按值的降序显示 tip 信息
    前端 玫瑰花小样式
    echarts X轴数据过多批量显示
    微信js sdk的使用初步理解
    对象 的循环嵌套
    移动端拉起电话请求
    js后加版本号
    数组排序于数组去重
    es6数组的方法
  • 原文地址:https://www.cnblogs.com/jbw752746541/p/9436404.html
Copyright © 2011-2022 走看看