废话不说,直接带码!
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
public class MenuTools : MonoBehaviour
{
private const string rootDir = "Tools/日志开关(目前在运行状态要在打开一次)";
private const string channelLxf = rootDir + "/LXF";
private const string channelLog = rootDir + "/默认日志";
private const string channelModule = rootDir + "/模块";
private const string channelNetWork = rootDir + "/网络";
private const string channelBattle = rootDir + "/战斗数据";
private const string channelResource = rootDir + "/资源";
private const string channelAttribute = rootDir + "/属性";
private const string channelProcess = rootDir + "/游戏流程";
private const string channelAlert = rootDir + "/报错";
private const string channelFile = rootDir + "/写文件";
/// <summary> 设置开关 </summary>
/// <param name="path"></param>
/// <param name="def"></param>
private static void SetFlag(string path, MaskDef def)
{
bool flag = Menu.GetChecked(path);
if (flag)
{
LLog.Mask = BitMask.Disable(LLog.Mask, def);
Menu.SetChecked(path, false);
}
else
{
LLog.Mask = BitMask.Enable(LLog.Mask, def);
Menu.SetChecked(path, true);
}
}
#region 开发人员
[MenuItem(channelJc)]
static void ChannelJc()
{
SetFlag(channelJc, MaskDef.Jc);
}
[MenuItem(channelJc, true)]
static bool ChannelJcCheck()
{
Menu.SetChecked(channelJc, LLog.IsEnabled(MaskDef.Jc));
return true;
}
//-----------------------------------------------------------------//
[MenuItem(channelLxf)]
static void ChannelLxf()
{
SetFlag(channelLxf, MaskDef.Lxf);
}
[MenuItem(channelLxf, true)]
static bool ChannelLxfCheck()
{
Menu.SetChecked(channelLxf, LLog.IsEnabled(MaskDef.Lxf));
return true;
}
#endregion
#region 系统日志
//-----------------------------------------------------------------//
[MenuItem(channelLog, false, 20)]
static void ChannelLog()
{
SetFlag(channelLog, MaskDef.Log);
}
[MenuItem(channelLog, true)]
static bool ChannelLogCheck()
{
Menu.SetChecked(channelLog, LLog.IsEnabled(MaskDef.Log));
return true;
}
//-----------------------------------------------------------------//
[MenuItem(channelModule, false, 20)]
static void ChannelModule()
{
SetFlag(channelModule, MaskDef.Module);
}
[MenuItem(channelModule, true)]
static bool ChannelModuleCheck()
{
Menu.SetChecked(channelModule, LLog.IsEnabled(MaskDef.Module));
return true;
}
//-----------------------------------------------------------------//
[MenuItem(channelNetWork, false, 20)]
static void ChannelNetWork()
{
SetFlag(channelNetWork, MaskDef.NetWork);
}
[MenuItem(channelNetWork, true)]
static bool ChannelNetWorkCheck()
{
Menu.SetChecked(channelNetWork, LLog.IsEnabled(MaskDef.NetWork));
return true;
}
//-----------------------------------------------------------------//
[MenuItem(channelBattle, false, 20)]
static void ChannelBattle()
{
SetFlag(channelBattle, MaskDef.Battle);
}
[MenuItem(channelBattle, true)]
static bool ChannelBattleCheck()
{
Menu.SetChecked(channelBattle, LLog.IsEnabled(MaskDef.Battle));
return true;
}
//-----------------------------------------------------------------//
[MenuItem(channelResource, false, 20)]
static void ChannelResource()
{
SetFlag(channelResource, MaskDef.Resource);
}
[MenuItem(channelResource, true)]
static bool ChannelResourceCheck()
{
Menu.SetChecked(channelResource, LLog.IsEnabled(MaskDef.Resource));
return true;
}
//-----------------------------------------------------------------//
[MenuItem(channelAttribute, false, 20)]
static void ChannelAttribute()
{
SetFlag(channelAttribute, MaskDef.Attribute);
}
[MenuItem(channelAttribute, true)]
static bool ChannelAttributeCheck()
{
Menu.SetChecked(channelAttribute, LLog.IsEnabled(MaskDef.Attribute));
return true;
}
//-----------------------------------------------------------------//
[MenuItem(channelProcess, false, 20)]
static void ChannelProcess()
{
SetFlag(channelProcess, MaskDef.Process);
}
[MenuItem(channelProcess, true)]
static bool ChannelProcessCheck()
{
Menu.SetChecked(channelProcess, LLog.IsEnabled(MaskDef.Process));
return true;
}
//-----------------------------------------------------------------//
[MenuItem(channelAlert, false, 20)]
static void ChannelAlert()
{
SetFlag(channelAlert, MaskDef.Alert);
}
[MenuItem(channelAlert, true)]
static bool ChannelAlertCheck()
{
Menu.SetChecked(channelAlert, LLog.IsEnabled(MaskDef.Alert));
return true;
}
//-----------------------------------------------------------------//
[MenuItem(channelFile, false, 20)]
static void ChannelFile()
{
SetFlag(channelFile, MaskDef.File);
}
[MenuItem(channelFile, true)]
static bool ChannelFileCheck()
{
Menu.SetChecked(channelFile, LLog.IsEnabled(MaskDef.File));
return true;
}
#endregion
}
#endif
使用:
private float index = 0;
void Update()
{
index += Time.deltaTime;
if (index > 2)
{
index = 0;
LLog.Log("123123");
LLog.Log("123123123", LLog.LogColor.Yellow);
LLog.Alert("警告");
LLog.AllPlatform("所有平台");
LLog.Attribute("属性");
LLog.Battle("战斗数据");
LLog.Error("错误");
LLog.Module("模块");
LLog.Process("游戏流程");
LLog.NetWork("网络");
LLog.Resource("资源");
LLog.Jc.Log("jc");
LLog.Lxf.Log("lxf");
}
}
后续会写把LOG输出到屏幕上,及在屏幕上控制过滤!!