编者注
由于UnityEditor编辑功能强大,一些调整功能,可以添加在UnityEditor当中,方便调整。
代码
在Unity项目的Assets/Editor
下的文件夹当中,可以创建C#脚本,并且被读取到,添加如下代码可以在UnityEditor菜单中添加菜单。但是必须是静态菜单
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class TestMenuItem : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
// 添加菜单
[MenuItem("Test/Test")]
static void test()
{
Debug.Log("Hello World");
}
}
示意图
错误报告
在2017.1转到2017.2发生了错误
The type or namespace name `UnityEditor' could not be found.
这个是由于UnityEditor的脚本没有存放到正确的目录结构,应当存放到Assets/Editor下