【笔记】Unity添加组件菜单、编辑时运行、属性窗口按钮

组件菜单

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[AddComponentMenu("整理Collder")]//在菜单栏“Componment()组件”添加“整理Collder”的选项
[ExecuteInEditMode]//在编辑时运行
public class DestryCollder : MonoBehaviour {
  public GameObject Parent;
  public void GetCollder()
    {
        Parent= new GameObject();
        Parent.transform.SetParent(transform);
        Parent.name = "删除Collder";
        foreach (Collider child in GetComponentsInChildren(true)) {
            if (child.GetComponent() != null)
                child.enabled = false;
            else
                child.transform.SetParent(Parent.transform);
        }
        Parent.SetActive(false);
  }
}

修改属性窗口

using UnityEngine;
using UnityEditor;

[CustomEditor(typeof(DestryCollder))]//修改对应组件属性窗口的菜单
public class InspectorBnt : Editor
{
    public override void OnInspectorGUI()//修改UI
    {
        DrawDefaultInspector();
        DestryCollder myScript = (DestryCollder)target;
        if (GUILayout.Button("整理"))//按下按钮
        {
            myScript.GetCollder();
        }
    }
}

 

你可能感兴趣的:(【笔记】Unity添加组件菜单、编辑时运行、属性窗口按钮)