找回密码
 立即注册
查看: 439|回复: 0

Unity中,设定指定Menu的状态作为功能开关

[复制链接]
发表于 2022-1-26 09:41 | 显示全部楼层 |阅读模式
例如,做一个这样的开关:勾选时,显示Log;不勾选时,不显示Log。


image.png

勾选时


image.png

不勾选时


image.png

#if UNITY_EDITORusing 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); } }    }}#endifusing 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}

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-9-22 21:26 , Processed in 0.088826 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表