本日はMRGT枠です。
〇MRGTのスクリーンショット機能にショートカットキーを追加する
最初にMRGTのスクリーンショットがどこで実装されているかを調べました。
ここではMRGTのスクリーンショット機能はGraphicsTools/Editor/Utilities/ScreenshotUtilities.csで実装されていることがわかりました。
また、実際のキャプチャは CaptureScreenshot()で行われていますが、解像度の設定はCaptureScreenshotX()で行われています。
〇ショートカットキーの実装
ショートカットはUnityのShortcutAttributeを使用することでShortcutManagerに登録することができます。
今回はこれまでの情報を合わせてMRGTのスクリーンショット機能にショートカットキーを実装しました。
GraphicsTools/Editor/Utilities/ScreenshotUtilities.csのコードは次のようになります。
public class ScreenshotUtilities { [Shortcut("Graphics Tools/Take Screenshot 1x", KeyCode.Alpha1, ShortcutModifiers.Alt)] [MenuItem("Window/Graphics Tools/Take Screenshot/Native Resolution")] private static void CaptureScreenshot1x() { CaptureScreenshot(GetScreenshotPath(), 1); EditorUtility.RevealInFinder(GetScreenshotDirectory()); } [Shortcut("Graphics Tools/Take Screenshot 1x Alpha", KeyCode.Alpha1, ShortcutModifiers.Shift)] [MenuItem("Window/Graphics Tools/Take Screenshot/Native Resolution (Transparent Background)")] private static void CaptureScreenshot1xAlphaComposite() { CaptureScreenshot(GetScreenshotPath(), 1, true); EditorUtility.RevealInFinder(GetScreenshotDirectory()); } [Shortcut("Graphics Tools/Take Screenshot 2x", KeyCode.Alpha2, ShortcutModifiers.Alt)] [MenuItem("Window/Graphics Tools/Take Screenshot/2x Resolution")] private static void CaptureScreenshot2x() { CaptureScreenshot(GetScreenshotPath(), 2); EditorUtility.RevealInFinder(GetScreenshotDirectory()); } [Shortcut("Graphics Tools/Take Screenshot 2x Alpha", KeyCode.Alpha2, ShortcutModifiers.Shift)] [MenuItem("Window/Graphics Tools/Take Screenshot/2x Resolution (Transparent Background)")] private static void CaptureScreenshot2xAlphaComposite() { CaptureScreenshot(GetScreenshotPath(), 2, true); EditorUtility.RevealInFinder(GetScreenshotDirectory()); } [Shortcut("Graphics Tools/Take Screenshot 4x", KeyCode.Alpha4, ShortcutModifiers.Alt)] [MenuItem("Window/Graphics Tools/Take Screenshot/4x Resolution")] private static void CaptureScreenshot4x() { CaptureScreenshot(GetScreenshotPath(), 4); EditorUtility.RevealInFinder(GetScreenshotDirectory()); } [Shortcut("Graphics Tools/Take Screenshot 4x Alpha", KeyCode.Alpha4, ShortcutModifiers.Shift)] [MenuItem("Window/Graphics Tools/Take Screenshot/4x Resolution (Transparent Background)")] private static void CaptureScreenshot4xAlphaComposite() { CaptureScreenshot(GetScreenshotPath(), 4, true); EditorUtility.RevealInFinder(GetScreenshotDirectory()); } ...
Altキー+撮影したい解像度でキャプチャができ、Shiftキー+撮影したい解像度で背景のα値を除いた撮影が行えるようになりました。
以上でエディタ上および実行中にショートカットキーでスクリーンショットが撮影することができました。
〇PRの提出
とりあえず機能自体はできたので、Microsoft/MixedReality-GraphicsTools-UnityへPRを出しました。
リーダーよりのフィードバックを得て調整していきます。 github.com
本日は以上です。