HKI Core
ScreenShotMaker.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using System.IO;
3 using System.Collections;
4 
5 namespace HKI.Core.Misc
6 {
14  public class ScreenShotMaker : MonoBehaviour
15  {
16  // Public variables
17  [SerializeField] KeyCode CaptureKey = KeyCode.F8;
18  [SerializeField] string ScreenShotsPath = "Screenshots";
19  [SerializeField] string Name = "Screen";
20 
21  [SerializeField] GameObject[] HudFreeScreenShotHideObjects;
22  [SerializeField] KeyCode CaptureKeyForHudFree = KeyCode.F9;
23 
24 
25  // Private Variables
26  int count = 0;
27  bool[] oldStatus;
28 
29  // Update function
30  void Update()
31  {
32  if (Input.GetKeyDown(CaptureKey))
33  StartCoroutine(CaptureScreenshoot(false));
34 
35  if (Input.GetKeyDown(CaptureKeyForHudFree))
36  StartCoroutine(CaptureScreenshoot(true));
37 
38  }
39 
40  IEnumerator CaptureScreenshoot(bool withoutHUD)
41  {
42  count++;
43 
44  if (HudFreeScreenShotHideObjects != null && withoutHUD)
45  {
46  oldStatus = new bool[HudFreeScreenShotHideObjects.Length];
47 
48  for (int i = 0; i < oldStatus.Length; i++)
49  {
50  oldStatus[i] = HudFreeScreenShotHideObjects[i].activeSelf;
51  HudFreeScreenShotHideObjects[i].SetActive(false);
52  }
53 
54  yield return null;
55  }
56 
57  yield return null;
58  if (!Directory.Exists(ScreenShotsPath))
59  Directory.CreateDirectory(ScreenShotsPath);
60 
61  ScreenCapture.CaptureScreenshot(ScreenShotsPath + "/" + Name + "_" + count.ToString() + ".png");
62 
63  yield return null;
64  if (HudFreeScreenShotHideObjects != null && withoutHUD)
65  {
66  for (int i = 0; i < oldStatus.Length; i++)
67  HudFreeScreenShotHideObjects[i].SetActive(oldStatus[i]);
68  }
69 
70  }
71  }
72 }
IEnumerator CaptureScreenshoot(bool withoutHUD)
GameObject [] HudFreeScreenShotHideObjects
This MonoBehaviour creates screenshots by pressing a key. Currently this script only works inside the...