Unity快捷键

using System; using UnityEngine; using System.Collections; using UnityEditor; using System.IO; using System.Text; using System.Collections.Generic; public class CustomHotKey : MonoBehaviour { [MenuItem("CustomHotKey/ToggleActivie &v")] public static void ToggleActive() { foreach (var obj in Selection.gameObjects) { Undo.RegisterCompleteObjectUndo(new UnityEngine.Object[] { obj, }, obj.name); obj.SetActive(!obj.activeSelf); } } [MenuItem("CustomHotKey/TogglePause &p")] public static void TogglePause() { EditorApplication.isPaused = !EditorApplication.isPaused; } [MenuItem("CustomHotKey/SaveProject &s")] public static void SaveAssets() { AssetDatabase.SaveAssets(); Debug.Log("Project Saved."); } [MenuItem("CustomHotKey/ApplyPrefab &a")] public static void ApplyPrefab() { foreach (var obj in Selection.gameObjects) { var prefabParent = PrefabUtility.GetPrefabParent(obj); if (prefabParent != null) PrefabUtility.ReplacePrefab(PrefabUtility.FindPrefabRoot(obj), prefabParent, ReplacePrefabOptions.ConnectToPrefab); } } [MenuItem("CustomHotKey/Open Containing Folder &o")] public static void OpenContainingFolder() { #if UNITY_EDITOR_WIN var path = Path.Combine(Path.Combine(Application.dataPath, ".."), AssetDatabase.GetAssetPath(Selection.activeObject)); ShowSelectedInExplorer.FilesOrFolders(path); #else Debug.LogWarning("not supported on current platform"); #endif } [MenuItem("CustomHotKey/Copy Hierarchy Path &i")] public static void CopyHierarchyPath() { var output = ""; foreach (var obj in Selection.gameObjects) { var line = obj.name; var parent = obj.transform.parent; while (parent) { line = parent.gameObject.name + "/" + line; parent = parent.parent; } if (output.Length > 0) output += "\n"; output += line; } // copy to clipboard TextEditor te = new TextEditor(); //te.content = new GUIContent(output); te.text = output; te.OnFocus(); te.Copy(); } [MenuItem("CustomHotKey/Copy Asset Path &t")] public static void CopyAssetPath() { StringBuilder output = new StringBuilder(); foreach (var obj in Selection.objects) { if (output.Length > 0) output.AppendLine(); output.Append(AssetDatabase.GetAssetPath(obj)); } String outputStr = output.ToString(); // copy to clipboard TextEditor te = new TextEditor(); //te.content = new GUIContent(output); te.text = outputStr; te.OnFocus(); te.Copy(); } [MenuItem("CustomHotKey/Clear Console &c")] public static void ClearConsole() { Type logEntries = System.Type.GetType("UnityEditor.LogEntries,UnityEditor.dll"); if (logEntries == null) { Debug.LogWarning("Can't find type"); return; } var method = logEntries.GetMethod("Clear", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public); if (method != null) { method.Invoke(null, null); GUIUtility.keyboardControl = 0; } else { Debug.LogWarning("Can't find methord"); return; } } [MenuItem("CustomHotKey/AddUISound (with path from clipboard) %&S")] public static void AddUISound() { String soundPath = EditorGUIUtility.systemCopyBuffer ?? ""; GameObject[] sels = Selection.gameObjects; if (sels == null) return; Boolean bRemove = String.IsNullOrEmpty(soundPath) || soundPath == " "; Int32 count = 0; foreach (GameObject sel in sels) { if (UISoundAssist.AddOrRemoveUIMainSound(sel, !bRemove, soundPath)) ++count; } if (!bRemove) { if (count > 0) Debug.LogFormat("sound event '{0}' has been added to {1} UI controls", soundPath, count); else Debug.LogWarningFormat("sound event '{0}' has not been added to any UI control", soundPath); } else { if (count > 0) Debug.LogFormat("sound event has been removed from {0} UI controls", count); else Debug.LogFormat("sound event has not been removed from any UI control"); } } [MenuItem("CustomHotKey/AddUIToggleSound (with two path from clipboard) %&T")] public static void AddUIToggleSound() { String soundPath = EditorGUIUtility.systemCopyBuffer ?? ""; GameObject[] sels = Selection.gameObjects; if (sels == null) return; Boolean bRemove = String.IsNullOrEmpty(soundPath) || soundPath == " "; Int32 count = 0; foreach (GameObject sel in sels) { if (UISoundAssist.AddOrRemoveUIToggleSound(sel, !bRemove, soundPath)) ++count; } if (!bRemove) { if (count > 0) Debug.LogFormat("sound event '{0}' has been added to {1} UI controls", soundPath, count); else Debug.LogWarningFormat("sound event '{0}' has not been added to any UI control", soundPath); } else { if (count > 0) Debug.LogFormat("sound event has been removed from {0} UI controls", count); else Debug.LogFormat("sound event has not been removed from any UI control"); } } static bool hide = true; [MenuItem("CustomHotKey/Toggle Selected wireframe &x")] public static void ToggleWireframe(){ if (Selection.activeGameObject == null) return ; Renderer[] renderers = Selection.activeGameObject.GetComponentsInChildren<Renderer>(); for( int i = 0; i < renderers.Length; i ++) { #pragma warning disable 618 EditorUtility.SetSelectedWireframeHidden(renderers[i], hide); #pragma warning restore 618 } hide = !hide; } [MenuItem("CustomHotKey/Reimport selected %&i")] public static void ReimportSelected() { var objs = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Assets); foreach (var obj in objs) { AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(obj.GetInstanceID())); } } [MenuItem("CustomHotKey/Unparent Selected #%&P")] static void UnparentSelectedObjecet() { foreach (var obj in Selection.gameObjects) { var tp = PrefabUtility.GetPrefabType(obj); if (tp == PrefabType.Prefab || tp == PrefabType.ModelPrefab) continue; Transform objT = obj.transform; if (objT != null && objT.parent != null) { Undo.SetTransformParent(objT, null, "Unparent " + obj.name); } } } [MenuItem("CustomHotKey/Restore 60 FPS #%&6")] static void Restore_60_FPS() { Application.targetFrameRate = 60; } [MenuItem("CustomHotKey/Select Objects by Clipboard #%&7")] static void SelectObjectsByClipboard() { string[] lines = GUIUtility.systemCopyBuffer.Split('\r', '\n'); List<UnityEngine.Object> objs = new List<UnityEngine.Object>(); foreach (string line in lines) { if (string.IsNullOrEmpty(line)) continue; var obj = AssetDatabase.LoadAssetAtPath(line, typeof(UnityEngine.Object)); if (obj != null) { objs.Add(obj); Debug.Log(obj.name); } } Selection.objects = objs.ToArray(); } }

__EOF__

本文作者艾孜尔江
本文链接https://www.cnblogs.com/ezhar/p/16341206.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   艾孜尔江  阅读(86)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
历史上的今天:
2020-06-04 异步处理的新原因
点击右上角即可分享
微信分享提示