例如,做一个这样的开关:勾选时,显示Log;不勾选时,不显示Log。
image.png
勾选时
image.png
不勾选时
image.png
#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace GM
{
public class GMTools
{
private const string ShowLogMenuPath = "Tools/GM/显示Log";
[MenuItem("Tools/GM/显示Log")]
public static void ShowLogTool()
{
Menu.SetChecked(ShowLogMenuPath, !Menu.GetChecked(ShowLogMenuPath));
}
public static bool ShouldShowLog{ get { return Menu.GetChecked(ShowLogMenuPath); } }
}
}
#endif
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (UnityEngine.Input.GetKeyDown(KeyCode.Space))
{
ShowLog("显示log111");
Debug.Log("显示log222");
}
}
public void ShowLog(string str)
{
#if UNITY_EDITOR
if (GM.GMTools.ShouldShowLog)
{
Debug.Log(str);
}
}
#endif
}
网友评论