Unity Editor Script 指定组件右键添加功能按钮

    //在指定脚本中右键添加按钮  CONTEXT/组件名/按钮名
    [MenuItem("CONTEXT/PlayerHealth/InitHealthAndSpeed")]
    //MenuCommand : 当前右键点击的组件
    static void InitHealthAndSpeed(MenuCommand cmd)
    {
        PlayerHealth health = cmd.context as PlayerHealth;
        health.startingHealth = 200;
        Debug.Log("Init");
    }
    [MenuItem("CONTEXT/Rigidbody/Clear")]
    static void ClearMassAndGravity(MenuCommand cmd)
    {
        Rigidbody rgd = cmd.context as Rigidbody;
        rgd.mass = 0.1f;
        rgd.useGravity = false;
    }
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerHealth : MonoBehaviour
{
    public int startingHealth;
    // Start is called before the first frame update
    void Start()
    {
        
    }

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

 


版权声明:本文为Fanstasic原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。