本文由博主(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学习的更多相关文章

  1. 【转】 Pro Android学习笔记(三三):Menu(4):Alternative菜单

    目录(?)[-] 什么是Alternative menu替代菜单 小例子说明 Alternative menu代码 关于Category和规范代码写法 关于flags 多个匹配的itemId等参数 什 ...

  2. 值得 Web 开发人员学习的20个 jQuery 实例教程

    这篇文章挑选了20个优秀的 jQuery 实例教程,这些 jQuery 教程将帮助你把你的网站提升到一个更高的水平.其中,既有网站中常用功能的的解决方案,也有极具吸引力的亮点功能的实现方法,相信通过对 ...

  3. Android -- Options Menu,Context Menu,Popup Menu

    Options Menu                                                                           创建选项菜单的步骤: 1. ...

  4. [转载-仅为个人学习所用]Stack Menu

    http://code4app.com/ios/51fa7d7e6803fa2710000006 我有个很牛的同学朋友同事舍友···他技术牛人,写的博客都是原创,粉丝无数,说实话我真的挺妒嫉的,试过为 ...

  5. Editor Scripting学习笔记之Menu Item

    主要用到: MenuItem属性 MenuCommand参数 可能用到: EditorApplication类 Selection类 GameObjectUtility类 FileUtil类 Undo ...

  6. Android学习笔记——Menu(三)

    知识点 今天继续昨天没有讲完的Menu的学习,主要是Popup Menu的学习. Popup Menu(弹出式菜单) 弹出式菜单是一种固定在View上的菜单模型.主要用于以下三种情况: 为特定的内容提 ...

  7. Android学习笔记——Menu(二)

    知识点: 这次将继续上一篇文章没有讲完的Menu的学习,上下文菜单(Context menu)和弹出菜单(Popup menu). 上下文菜单 上下文菜单提供对UI界面上的特定项或上下文框架的操作,就 ...

  8. 【转】 Pro Android学习笔记(三四):Menu(5):动态菜单

    目录(?)[-] OptionsMenu的创建方式 如何再次创建OptionsMenu 每次访问都重新填充菜单项 OptionsMenu的创建方式 OptionMenu在第一次访问该菜单时调用,只调用 ...

  9. 【转】 Pro Android学习笔记(三五):Menu(6):XML方式 & PopUp菜单

    目录(?)[-] 利用XML创建菜单 XML的有关属性 onClick事件 Pop-up菜单 利用XML创建菜单 在代码中对每个菜单项进行设置,繁琐且修改不灵活,不能适配多国语言的要求,可以利用资源进 ...

随机推荐

  1. 使用UIImagePickerController时3DTouch引起的Crash问题的解决--备用

    一.crash的场景 程序中用到UIImagePickerController时,如果在IPhone6S上运行APP,当forceTouch 一个图片时程序会crash,并附带如下crash mess ...

  2. j2ee爬坑行之一:web容器

    什么是容器? servlet没用main方法,它们受控于另一个java应用程序,这个应用程序就称为容器. tomcat就是这样一个容器.当web服务器得到一个指向某servlet的请求,此时服务器不是 ...

  3. Delphi COM编程学习笔记(1)

    释放接口对象,既不是调用MyObj.Free,也不是MyObj.Release;破坏对象的正确方法是将它们设置为nil:MyInterface := nil; 一个接口不能离开实现它的对象而独立存活. ...

  4. Xamarin.Forms Hello word

    创建项目 XMD1右键->添加->新建项目 MDPage:MasterDetailPage 主窗体,导航与明细的布局窗体. 指定MenuPage.xaml 作为Master <?xm ...

  5. 使用getGenericSuperclass()和getActualTypeArguments()将DAO做成泛型

    一.getGenericSuperclass()和getActualTypeArguments()基本用法: import java.lang.reflect.ParameterizedType; p ...

  6. 【HDOJ】2195 Monotone SE Min

    简单DP.将[0,1]的浮点数离散化为[0,1000]的整数.最后再除以1000^2. /* 2195 */ #include <cstdio> #include <cstring& ...

  7. 强联通 HDU 1269

    第一道强联通的题目纪念一下! 主要是模版 tarjan算法 #include <iostream> #include <cstdlib> #include <cstdio ...

  8. datagridview的数据源的操作

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  9. SherlockActivity也可以用依赖注入的方法:

    场景:     一个Activity必须继承RoboActivity才可以使用依赖注入. 若一个Activity已经继承了别的Activity了.比如SherlockActivity 如何才能使用依赖 ...

  10. java中的接口和抽象类是什么?

    抽象类与接口的区别 abstract class和interface是Java语言中对于抽象类定义进行支持的两种机制,正是由于这两种机制的存在,才赋予了Java强大的面向对象能力.abstract c ...