Unity 中 ContextMenu 的用法

在自定义脚本中的方法前加入  [ContextMenu("Execute")]  标签,然后将脚本挂载到对象上,可以再编辑模式下执行标记的方法:

自定义脚本如下:

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

public class LestContextMenu : MonoBehaviour
{
    [ContextMenu("Execute")]
    void Test()
    {
        Debug.Log("LestContextMenu");
    }
}

测试过程如下:

点击齿轮按钮后会出现 Execute ,点击之即可执行脚本中定义的方法:

原文地址:https://www.cnblogs.com/luguoshuai/p/8715876.html