-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScreenshotCapturer.cs
73 lines (62 loc) · 2.07 KB
/
ScreenshotCapturer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System.IO;
using System.Reflection;
using UnityEditor;
using UnityEngine;
[RequireComponent(typeof(Camera))]
public class ScreenshotCapturer : MonoBehaviour
{
#if !UNITY_EDITOR
void Awake (){
Destroy(this);
}
#endif
enum Resolutions
{
OculusStoreScreenShot,
FullHD,
}
[SerializeField] Resolutions resolution;
EditorWindow GetMainGameView()
{
var T = System.Type.GetType("UnityEditor.GameView,UnityEditor");
var mainGameView = T.GetMethod("GetMainGameView", BindingFlags.NonPublic | BindingFlags.Static);
var res = mainGameView.Invoke(null, null);
return (EditorWindow) res;
}
void Start()
{
var gameView = GetMainGameView();
var prop = gameView.GetType().GetProperty("currentGameViewSize", BindingFlags.NonPublic | BindingFlags.Instance);
var gvSize = prop.GetValue(gameView, new object[0]);
var gvSizeType = gvSize.GetType();
// TODO : Free Aspect モードだと解像度が反映されない
switch (resolution)
{
case Resolutions.OculusStoreScreenShot:
gvSizeType.GetProperty("width", BindingFlags.Public | BindingFlags.Instance).SetValue(gvSize, 2560);
gvSizeType.GetProperty("height", BindingFlags.Public | BindingFlags.Instance).SetValue(gvSize, 1440);
break;
case Resolutions.FullHD:
gvSizeType.GetProperty("width", BindingFlags.Public | BindingFlags.Instance).SetValue(gvSize, 1920);
gvSizeType.GetProperty("height", BindingFlags.Public | BindingFlags.Instance).SetValue(gvSize, 1080);
break;
default:
Debug.Log("This resolution is not implemented.");
break;
}
}
void Update()
{
// TODO : リニア色空間に対応していない(2018.2)
if (Input.GetKeyDown(KeyCode.Space))
{
var currentDir = Directory.GetParent(Application.dataPath).ToString();
const string ssDir = "Screenshots";
Directory.CreateDirectory(Path.Combine(currentDir, ssDir));
var now = System.DateTime.Now.ToString().Replace("/", ".").Replace(":", ".");
var filename = "SS " + now + ".png";
var path = Path.Combine(currentDir, ssDir, filename);
ScreenCapture.CaptureScreenshot(path);
}
}
}