Unity自定义【激活/隐藏物体】和【Apply预设】的快捷键

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

public class GameObjectAct
{
    //快捷键控制游戏对象的开关 alt + `
    [MenuItem("Tools/Custom/Active GameObject &`")]
    public static void ActiveGameObject()
    {
        GameObject go = Selection.activeGameObject;
        if (go == null) return;
        bool isActive = !go.activeSelf;
        go.SetActive(isActive);
    }


    //快捷键控制保存Prefab alt + fs
    [MenuItem("Tools/Custom/Apply GameObject &f")]
    public static void ApplyPrefab()
    {
        GameObject go = Selection.activeGameObject;
        if (go == null) return;
        PrefabType type = PrefabUtility.GetPrefabType(go);
        if (type  == PrefabType.PrefabInstance)
        {
            Object target = PrefabUtility.GetCorrespondingObjectFromSource(go);
            PrefabUtility.ReplacePrefab(go, target, ReplacePrefabOptions.ConnectToPrefab);
        }

    }
}

你可能感兴趣的:(Unity3D)