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 * 2; 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, 10)] 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; } }

image

转载于:https://www.cnblogs.com/YinaPan/p/Unity_Menu.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值