Created
March 8, 2014 22:41
-
-
Save fujimisakari/9440118 to your computer and use it in GitHub Desktop.
Editor拡張でショートカットキーをカスタマイズ ref: http://qiita.com/fujimisakari/items/36284ececdb06e3cdb4c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
using UnityEngine; | |
using System.Text.RegularExpressions; | |
using System.Reflection; | |
public class UnityKeyRemapEditor : EditorWindow | |
{ | |
// オブジェクトの共通Openコマンド | |
[MenuItem("KeyRemap/Open &o")] | |
static void KeyRemapOpen() | |
{ | |
foreach (var aObj in Selection.objects) | |
{ | |
var aObjPath = AssetDatabase.GetAssetPath(aObj); | |
if (Regex.IsMatch(aObjPath, @"^.*\.unity")) { EditorApplication.OpenScene(aObjPath); } | |
if (Regex.IsMatch(aObjPath, @"^.*\.cs")) { AssetDatabase.OpenAsset(aObj); } | |
if (Regex.IsMatch(aObjPath, @"^.*\.prefab")) | |
{ | |
PrefabUtility.InstantiatePrefab(aObj); | |
CommonExecuteMenuItem("Window/Hierarchy"); | |
} | |
} | |
} | |
// ゲームオブジェクト作成 | |
[MenuItem("KeyRemap/CreateGameObject &g")] | |
static void KeyRemapCreateGameObject() { CommonExecuteMenuItem("GameObject/Create Empty"); } | |
// ゲームオブジェクトの削除 | |
[MenuItem("KeyRemap/Delete &h")] | |
static void KeyRemapDelete() | |
{ | |
foreach (var aObj in Selection.objects) | |
{ | |
GameObject aGameObject = aObj as GameObject; | |
if (aGameObject) { GameObject.DestroyImmediate(aGameObject); } | |
} | |
} | |
// ゲームオブジェクトの有効、無効 | |
[MenuItem("KeyRemap/ActiveToggle &t")] | |
static void KeyRemapActiveToggle() | |
{ | |
foreach (var aObj in Selection.objects) | |
{ | |
GameObject aGameObject = aObj as GameObject; | |
if (aGameObject) { aGameObject.SetActive(!aGameObject.activeSelf); } | |
} | |
} | |
// PrefabのApply | |
[MenuItem("KeyRemap/PrefabApply &a")] | |
static void KeyRemapPrefabApply() { CommonExecuteMenuItem("GameObject/Apply Changes To Prefab"); } | |
// コンソール出力のクリア | |
[MenuItem("KeyRemap/ClearConsoleLogs &c")] | |
private static void ClearConsoleLogs() | |
{ | |
var type = Types.GetType("UnityEditorInternal.LogEntries", "UnityEditor"); | |
var info = type.GetMethod("Clear", BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance); | |
info.Invoke(null, new object[0]); | |
} | |
// 再インポート | |
[MenuItem("KeyRemap/Reimport &r")] | |
static void KeyRemapReimport() { CommonExecuteMenuItem("Assets/Reimport"); } | |
// フォーカス変更 | |
[MenuItem("KeyRemap/Scene #&s")] | |
static void KeyRemapScene() { CommonExecuteMenuItem("Window/Scene"); } | |
[MenuItem("KeyRemap/Scene #&g")] | |
static void KeyRemapGame() { CommonExecuteMenuItem("Window/Game"); } | |
[MenuItem("KeyRemap/Inspector #&i")] | |
static void KeyRemapInspector() { CommonExecuteMenuItem("Window/Inspector"); } | |
[MenuItem("KeyRemap/Hierarchy #&h")] | |
static void KeyRemapHierarchy() { CommonExecuteMenuItem("Window/Hierarchy"); } | |
[MenuItem("KeyRemap/Project #&p")] | |
static void KeyRemapProject() { CommonExecuteMenuItem("Window/Project"); } | |
[MenuItem("KeyRemap/Animation #&a")] | |
static void KeyRemapAnimation() { CommonExecuteMenuItem("Window/Animation"); } | |
[MenuItem("KeyRemap/Console #&c")] | |
static void KeyRemapConsole() { CommonExecuteMenuItem("Window/Console"); } | |
static void CommonExecuteMenuItem(string iStr) | |
{ | |
EditorApplication.ExecuteMenuItem(iStr); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment