Unity 开发模式中常常需要log一些信息,但是在正式发布时又想将其全部关闭,如果有很多log,那一个一个的去关闭就未免显得有点繁琐。通过一个开关,来控制log 是否输入更简便一些。如果在看log信息时想更精准定位到是哪一行代码则需要把log输出的订成dll。
可把此脚本制成dll:
using UnityEngine;
using System.Collections;
namespace Logger
{
public class LogManager : MonoBehaviour
{
public static bool EnableLog;
public static void Log (string message)
{
if (EnableLog) {
Debug.Log (message);
}
}
}
}
dll 下载地址:http://download.csdn.net/download/fucun1984686003/10221525
dll 需要放在Plugins文件夹下。
下面是调用方法:
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour
{
// Use this for initialization
void Start ()
{
Logger.LogManager.EnableLog = true;
Logger.LogManager.Log ("hello !");
}
// Update is called once per frame
void Update ()
{
}
}
正式发布时需要把 Logger.LogManager.EnableLog改为false。