Menu学习
本文由博主(YinaPan)原创,转载请注明出处:http://www.cnblogs.com/YinaPan/p/Unity_Menu.html
using UnityEditor;
using UnityEngine;
public class Menu : MonoBehaviour { // Add a menu item named "Do Something" to MyMenu in the menu bar.
[MenuItem ("MyMenu/Do Something")]
static void DoSomething () {
Debug.Log ("Doing Something...");
} // Validated menu item.
// Add a menu item named "Log Selected Transform Name" to MyMenu in the menu bar.
// We use a second function to validate the menu item
// so it will only be enabled if we have a transform selected.
[MenuItem ("MyMenu/Log Selected Transform Name")]
static void LogSelectedTransformName ()
{
Debug.Log ("Selected Transform is on " + Selection.activeTransform.gameObject.name + ".");
} // Validate the menu item defined by the function above.
// The menu item will be disabled if this function returns false.
[MenuItem ("MyMenu/Log Selected Transform Name", true)]
static bool ValidateLogSelectedTransformName () {
// Return false if no transform is selected.
return Selection.activeTransform != null;
} // Add a menu item named "Do Something with a Shortcut Key" to MyMenu in the menu bar
// and give it a shortcut (ctrl-g on Windows, cmd-g on OS X).
[MenuItem ("MyMenu/Do Something with a Shortcut Key %g")]
static void DoSomethingWithAShortcutKey () {
Debug.Log ("Doing something with a Shortcut Key...");
} // Add a menu item called "Double Mass" to a Rigidbody's context menu.
[MenuItem ("CONTEXT/Rigidbody/Double Mass")]
static void DoubleMass (MenuCommand command) {
Rigidbody body = (Rigidbody)command.context;
body.mass = body.mass * ;
Debug.Log ("Doubled Rigidbody's Mass to " + body.mass + " from Context Menu.");
} // Add a menu item to create custom GameObjects.
// Priority 1 ensures it is grouped with the other menu items of the same kind
// and propagated to the hierarchy dropdown and hierarch context menus.
[MenuItem("GameObject/MyCategory/Custom Game Object", false, )]
static void CreateCustomGameObject(MenuCommand menuCommand) {
// Create a custom game object
GameObject go = new GameObject("Custom Game Object");
// Ensure it gets reparented if this was a context click (otherwise does nothing)
GameObjectUtility.SetParentAndAlign(go, menuCommand.context as GameObject);
// Register the creation in the undo system
Undo.RegisterCreatedObjectUndo(go, "Create " + go.name);
Selection.activeObject = go;
}
}

Menu学习的更多相关文章
- 【转】 Pro Android学习笔记(三三):Menu(4):Alternative菜单
目录(?)[-] 什么是Alternative menu替代菜单 小例子说明 Alternative menu代码 关于Category和规范代码写法 关于flags 多个匹配的itemId等参数 什 ...
- 值得 Web 开发人员学习的20个 jQuery 实例教程
这篇文章挑选了20个优秀的 jQuery 实例教程,这些 jQuery 教程将帮助你把你的网站提升到一个更高的水平.其中,既有网站中常用功能的的解决方案,也有极具吸引力的亮点功能的实现方法,相信通过对 ...
- Android -- Options Menu,Context Menu,Popup Menu
Options Menu 创建选项菜单的步骤: 1. ...
- [转载-仅为个人学习所用]Stack Menu
http://code4app.com/ios/51fa7d7e6803fa2710000006 我有个很牛的同学朋友同事舍友···他技术牛人,写的博客都是原创,粉丝无数,说实话我真的挺妒嫉的,试过为 ...
- Editor Scripting学习笔记之Menu Item
主要用到: MenuItem属性 MenuCommand参数 可能用到: EditorApplication类 Selection类 GameObjectUtility类 FileUtil类 Undo ...
- Android学习笔记——Menu(三)
知识点 今天继续昨天没有讲完的Menu的学习,主要是Popup Menu的学习. Popup Menu(弹出式菜单) 弹出式菜单是一种固定在View上的菜单模型.主要用于以下三种情况: 为特定的内容提 ...
- Android学习笔记——Menu(二)
知识点: 这次将继续上一篇文章没有讲完的Menu的学习,上下文菜单(Context menu)和弹出菜单(Popup menu). 上下文菜单 上下文菜单提供对UI界面上的特定项或上下文框架的操作,就 ...
- 【转】 Pro Android学习笔记(三四):Menu(5):动态菜单
目录(?)[-] OptionsMenu的创建方式 如何再次创建OptionsMenu 每次访问都重新填充菜单项 OptionsMenu的创建方式 OptionMenu在第一次访问该菜单时调用,只调用 ...
- 【转】 Pro Android学习笔记(三五):Menu(6):XML方式 & PopUp菜单
目录(?)[-] 利用XML创建菜单 XML的有关属性 onClick事件 Pop-up菜单 利用XML创建菜单 在代码中对每个菜单项进行设置,繁琐且修改不灵活,不能适配多国语言的要求,可以利用资源进 ...
随机推荐
- 《30天自制操作系统》读书笔记(2)hello, world
让系统跑起来 要写一个操作系统,我们首先要有一个储存系统的介质,原版书似乎是06年出版的,可惜那时候没有电脑,没想到作者用的还是软盘,现在的电脑谁有软驱?不得已我使用一张128M的SD卡来代替,而事实 ...
- 用C#实现网络爬虫(一)
网络爬虫在信息检索与处理中有很大的作用,是收集网络信息的重要工具. 接下来就介绍一下爬虫的简单实现. 爬虫的工作流程如下 爬虫自指定的URL地址开始下载网络资源,直到该地址和所有子地址的指定资源都下载 ...
- 一步一步学习SignalR进行实时通信_7_非代理
原文:一步一步学习SignalR进行实时通信_7_非代理 一步一步学习SignalR进行实时通信\_7_非代理 SignalR 一步一步学习SignalR进行实时通信_7_非代理 前言 代理与非代理 ...
- COJ 1008 WZJ的数据结构(八) 树上操作
传送门:http://oj.cnuschool.org.cn/oj/home/problem.htm?problemID=986 WZJ的数据结构(八) 难度级别:E: 运行时间限制:3000ms: ...
- BZOJ2324: [ZJOI2011]营救皮卡丘
2324: [ZJOI2011]营救皮卡丘 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 1359 Solved: 522[Submit][Stat ...
- SQL 2008 如何配置远程连接
初次接触sql2008 相比05 改观还是挺大的 在配置方面 如何打开"远程连接" 成了最棘手的 到网上找了大半天资料 依然云里雾里 参考网上的众多资料 结合本人的实际经 ...
- Java---多线程的加强(1)
简单应用: 首先来看一个简单的例子: 两个线程,分别实现对1-100内的奇数,偶数的输出. 第一种方法:通过接口 MyRun类: package thread.hello; /** * 通过实现Run ...
- Foundation Data Structure
LinkedList : /** * 考虑的比较的周全,并且包含了全部的情况,代码也不乱<b></b> * * @param index * 插入的位置 * @param c ...
- unittest笔记
学习资料: 官网: https://docs.python.org/2.7/library/unittest.html IBM Python自动单元测试框架: http://www.ibm.com/d ...
- SWOT分析法
SWOT(Strengths Weakness Opportunity Threats)分析法,又称为态势分析法或优劣势分析法,用来确定企业自身的竞争优势(strength).竞争劣势(weaknes ...