Unity导航菜单栏位于游戏引擎界面的顶部,其中有很多选项且含义各不相同。Unity为开发者提供了导航菜单栏的程序接口,使用代码可以动态添加菜单栏中的选项以及子项。文章出处【狗刨学习网】。
二、将一个自动旋转的脚本加至“Component”菜单项中
- using UnityEngine;
- using System.Collections;
- using UnityEditor;
- public class NewBehaviourScript : MonoBehaviour
- {
- [MenuItem("新的菜单栏/克隆选择的对象")]
- static void ClothObject()
- {
- Instantiate(Selection.activeTransform, Vector3.zero, Quaternion.identity);//[ɪns'tænʃɪeɪt]例示
- }
- [MenuItem("新的菜单栏/克隆选择的对象", true)]
- static bool NoClothObject()
- {
- return Selection.activeGameObject != null;
- }
- [MenuItem("新的菜单栏/删除选择的对象")]
- static void RemoveObject()
- {
- DestroyImmediate(Selection.activeGameObject, true);
- }
- [MenuItem("新的菜单栏/删除选择的对象", true)]
- static bool NoRemoveObject()
- {
- return Selection.activeGameObject != null;
- }
- // Use this for initialization
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- }
- }
二、将一个自动旋转的脚本加至“Component”菜单项中
- using UnityEngine;
- using System.Collections;
- /// <summary>
- /// 添加该脚本至“Component”菜单项中
- /// </summary>
- [AddComponentMenu("新的脚本/自动旋转")]
- public class _5_5 : MonoBehaviour {
- // Use this for initialization
- void Start () {
-
- }
-
- // Update is called once per frame
- void Update () {
- transform.Rotate(0.0f, Time.deltaTime * 200, 0.0f);//自身旋转
- }
- }