全球优质服务器购买

为用户应用推荐适合的服务器,针对需求定制,将质量做到更好

香港服务器

香港CN2优化带宽,国内访问快

CPU:I3-2120(2核心4线程)

内存:4G DDR3内存

硬盘:1T HDD

带宽:10M优化、10M国际

IP数:1个

价格:699/月

美国服务器

美国洛杉矶高性价比服务器

CPU:I3-2120(2核心4线程)

内存:4G DDR3内存

硬盘:1T HDD

带宽:30M优化/100M普通

IP数:1个(10G防护)

价格:499/月

香港站群服务器

香港多IP站群服务器租用

CPU:E3-1230V2(4核

内存:8G DDR3内存

硬盘:240G SSD/1T SATA

带宽:10M优化

IP数:125个IP(1/2C)

价格:1099/月

美国站群服务器

美国多IP站群服务器租用

CPU:E3-1230V2(4核)

内存:16G DDR3内存

硬盘:1T HDD/240G SSD

带宽:30M优化/100M普通

IP数:125个IP(1/2C)

价格:999/月

  •  

一、前言

今天分享,如何添加自定义菜单栏,效果如下图所示。

第一种,在Component组件菜单下面:
【Unity3D日常开发】AddComponentMenu添加菜单命令_unity
第二种,添加到编辑器的菜单栏下:

【Unity3D日常开发】AddComponentMenu添加菜单命令_自定义菜单_02

二、添加组件菜单

有两个重载函数:
【Unity3D日常开发】AddComponentMenu添加菜单命令_自定义_03
第一种,不带参数实现:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

[AddComponentMenu("Tools/自定义菜单")]
public class addTest : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

第二种,使用参数:

menuName:菜单名
order:排序

public AddComponentMenu(string menuName, int order);

比如说,我在Tools菜单下有很多个子菜单,但是为了控制它们之间的排序情况,就可以使用order参数,如下所示:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

[AddComponentMenu("Tools/自定义菜单1",1)]
public class addTest : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

[AddComponentMenu("Tools/自定义菜单2",2)]
public class addTest2 : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

这样,自定义菜单1就会一直排在自定义菜单2的前面了。
【Unity3D日常开发】AddComponentMenu添加菜单命令_自定义_04

三、添加菜单栏菜单

代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

public class addTest : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    [MenuItem("Tools/菜单栏菜单")]
    static void Test()
    {

    }
}

【Unity3D日常开发】AddComponentMenu添加菜单命令_自定义菜单_02

当然,这个也可以使用priority参数排序优先级。
isValidateFunction验证函数: 如果isValidateFunction为 true,它将表示一个验证 函数,并在系统调用具有相同 itemName 的菜单函数之前进行调用。
【Unity3D日常开发】AddComponentMenu添加菜单命令_菜单栏_06
这里就不演示了,有需要可以验证一下。

 

内容来源于网络如有侵权请私信删除

推荐文章