美文网首页
【Unity】编辑器扩展自定义快捷键

【Unity】编辑器扩展自定义快捷键

作者: 木心Sepith | 来源:发表于2019-01-12 10:21 被阅读19次

    加了两个常用的快捷键,还是很有用的

    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);
            }
    
        }
    }
    
    

    相关文章

      网友评论

          本文标题:【Unity】编辑器扩展自定义快捷键

          本文链接:https://www.haomeiwen.com/subject/ramqdqtx.html