Forked from dj-kusuha/CaptureScreenshotFromEditor.cs
Created
November 17, 2018 16:48
-
-
Save nkjzm/24079d260b712787985253c7d4aa2a7c to your computer and use it in GitHub Desktop.
Unityエディタ上からGameビューのスクリーンショットを撮るEditor拡張。
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; | |
namespace djkusuha.Utility | |
{ | |
/// <summary> | |
/// Unityエディタ上からGameビューのスクリーンショットを撮るEditor拡張 | |
/// </summary> | |
public class CaptureScreenshotFromEditor : Editor | |
{ | |
/// <summary> | |
/// キャプチャを撮る | |
/// </summary> | |
/// <remarks> | |
/// Edit > CaptureScreenshot に追加。 | |
/// HotKeyは Ctrl + Shift + F12。 | |
/// </remarks> | |
[MenuItem("Edit/CaptureScreenshot #%F12")] | |
private static void CaptureScreenshot() | |
{ | |
// 現在時刻からファイル名を決定 | |
var filename = System.DateTime.Now.ToString("yyyyMMdd-HHmmss") + ".png"; | |
// キャプチャを撮る | |
#if UNITY_2017_1_OR_NEWER | |
ScreenCapture.CaptureScreenshot(filename); // ← GameViewにフォーカスがない場合、この時点では撮られない | |
#else | |
Application.CaptureScreenshot(filename); // ← GameViewにフォーカスがない場合、この時点では撮られない | |
#endif | |
// GameViewを取得してくる | |
var assembly = typeof(EditorWindow).Assembly; | |
var type = assembly.GetType("UnityEditor.GameView"); | |
var gameview = EditorWindow.GetWindow(type); | |
// GameViewを再描画 | |
gameview.Repaint(); | |
Debug.Log("ScreenShot: " + filename); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment