Unity3D之定制导航菜单栏

来源:互联网 发布:手持数据终端 编辑:程序博客网 时间:2024/04/29 15:33
Unity导航菜单栏位于游戏引擎界面的顶部,其中有很多选项且含义各不相同。Unity为开发者提供了导航菜单栏的程序接口,使用代码可以动态添加菜单栏中的选项以及子项。文章出处【狗刨学习网】。

  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEditor;

  4. public class NewBehaviourScript : MonoBehaviour
  5. {


  6.     [MenuItem("新的菜单栏/克隆选择的对象")]
  7.     static void ClothObject()
  8.     {
  9.         Instantiate(Selection.activeTransform, Vector3.zero, Quaternion.identity);//[ɪns'tænʃɪeɪt]例示
  10.     }

  11.     [MenuItem("新的菜单栏/克隆选择的对象", true)]
  12.     static bool NoClothObject()
  13.     {
  14.         return Selection.activeGameObject != null;
  15.     }


  16.     [MenuItem("新的菜单栏/删除选择的对象")]
  17.     static void RemoveObject()
  18.     {
  19.         DestroyImmediate(Selection.activeGameObject, true);
  20.     }

  21.     [MenuItem("新的菜单栏/删除选择的对象", true)]
  22.     static bool NoRemoveObject()
  23.     {
  24.         return Selection.activeGameObject != null;
  25.     }


  26.     // Use this for initialization
  27.     void Start()
  28.     {

  29.     }

  30.     // Update is called once per frame
  31.     void Update()
  32.     {

  33.     }
  34. }

二、将一个自动旋转的脚本加至“Component”菜单项中
  1. using UnityEngine;
  2. using System.Collections;

  3. /// <summary>
  4. /// 添加该脚本至“Component”菜单项中
  5. /// </summary>
  6. [AddComponentMenu("新的脚本/自动旋转")]
  7. public class _5_5 : MonoBehaviour {

  8.     // Use this for initialization
  9.     void Start () {
  10.    
  11.     }
  12.    
  13.     // Update is called once per frame
  14.     void Update () {
  15.         transform.Rotate(0.0f, Time.deltaTime * 200, 0.0f);//自身旋转
  16.     }
  17. }
0 0
原创粉丝点击