Unity 经典教程 Editor扩展之ContextMenu的使用

 时间:2024-10-14 19:59:45

Unity 经典教程 Editor扩展之ContextMenu的使用。主要介踏群拆虮绍在脚本中使用ContextMenu给指定的函数滤鲇魍童设置在“Inspector”中,选中该脚本右键可以执行该函数的功能,本节简单通过使用ContextMenu设计右键执行一个打印函数的案例,具体如下:

Unity 经典教程 Editor扩展之ContextMenu的使用

工具/原料

Unity

Unity Editor

一、基本概念

1、ContextMenu:Adds the function to the context menu of the component.In the inspector of the attached script. When the user selects the context menu, the function will be executedThis is most useful for automatically setting up scene data from the script. The function has to be non-static.

二、具体操作

1、打开Unity,新建一个空工程,Unity界面如下图

Unity 经典教程 Editor扩展之ContextMenu的使用

2、在工程里面新建一个及哦啊本,可以命名为“ContextMenuTest”,具体如下图

Unity 经典教程 Editor扩展之ContextMenu的使用

3、选中“ContextMenuTest”脚本,双击脚本或者右键“Open C# Project”打开脚本,具体如下图

Unity 经典教程 Editor扩展之ContextMenu的使用

4、在打开的脚本中进行代码编辑,给一个函数设置为“ContextMenu”功能,然后让该函数有个打印功能即可,具体如下图

Unity 经典教程 Editor扩展之ContextMenu的使用

5、脚本编译正确之后,回到Unity界面,新建一个“GameObject”,然后把脚本“ContextMenuT髫潋啜缅est”赋给“GameObject”,在“Inspector”中右键脚本即可看到“Print Info”,具体如下图

Unity 经典教程 Editor扩展之ContextMenu的使用

6、然后,单击“Print Info”即可在非运行状态下,即可以在“Console”看到函数结果,具体如下图

Unity 经典教程 Editor扩展之ContextMenu的使用

7、到此,《Unity 经典教程 Editor扩展之ContextMenu的使用》讲解结束,谢谢

  • cocos如何动态改变预制图片大小
  • eclipse如何导入Android项目?
  • 如何下载eclipse安装
  • Blend for Visual studio如何更改启动选项
  • Unity怎么添加和移除事件侦听
  • 热门搜索
    喜欢的反义词是什么 过期的牛奶有什么用 授信是什么意思 伤官是什么意思 朱军怎么了出什么事了 浅绿色配什么颜色好看 人为什么会打嗝 cp是什么 结婚三年是什么婚 皮肤黑的人适合穿什么颜色的衣服