Skip to content

Commit 462fae1

Browse files
committed
Added camera app prototype
1 parent 7ea3b79 commit 462fae1

2 files changed

Lines changed: 73 additions & 8 deletions

File tree

Assets/Scripts/ScreenShotScript.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using UnityEngine;
2+
using UnityEngine.UI;
3+
using UnityEditor;
4+
using System.Collections;
5+
6+
public class ScreenShotScript : MonoBehaviour {
7+
8+
public AudioSource audio;
9+
public RawImage screenShot;
10+
11+
private Texture2D screenShotTexture;
12+
private string lastScreenShotPath;
13+
14+
// Use this for initialization
15+
void Start () {
16+
screenShotTexture = new Texture2D(100, 100);
17+
screenShot.texture = screenShotTexture;
18+
}
19+
20+
// Update is called once per frame
21+
void Update () {
22+
23+
}
24+
25+
void TakeScreenShot (string path) {
26+
StartCoroutine (CaptureScreen (path));
27+
}
28+
29+
IEnumerator CaptureScreen (string path) {
30+
// Wait till the last possible moment before screen rendering to hide the UI
31+
yield return null;
32+
// GameObject.Find("UICanvas").GetComponent<Canvas>().enabled = false;
33+
34+
// Wait for screen rendering to complete
35+
yield return new WaitForEndOfFrame();
36+
37+
// Take screenshot
38+
Application.CaptureScreenshot(path);
39+
40+
// Show UI after we're done
41+
// GameObject.Find("UICanvas").GetComponent<Canvas>().enabled = true;
42+
}
43+
44+
void OnGUI () {
45+
Event e = Event.current;
46+
47+
if (e.type == EventType.KeyDown && e.keyCode == KeyCode.F) {
48+
string current_time = System.DateTime.Now.ToString().Replace("/", "_").Replace(":", "_");
49+
lastScreenShotPath = FileUtil.GetUniqueTempPathInProject() + current_time + ".png";
50+
Debug.Log("saved: " + lastScreenShotPath);
51+
TakeScreenShot (lastScreenShotPath);
52+
53+
audio.Play ();
54+
Debug.Log ("Screenshot");
55+
56+
}
57+
}
58+
59+
void LateUpdate () {
60+
StartCoroutine (DisplayScreenShot ());
61+
}
62+
63+
IEnumerator DisplayScreenShot () {
64+
yield return null;
65+
66+
if (System.IO.File.Exists(lastScreenShotPath)) {
67+
Debug.Log("File found!");
68+
var screenShotBytes = System.IO.File.ReadAllBytes(lastScreenShotPath);
69+
screenShotTexture.LoadImage(screenShotBytes);
70+
screenShot.material.mainTexture = screenShotTexture;
71+
}
72+
}
73+
}

ProjectSettings/ProjectSettings.asset

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ PlayerSettings:
379379
XboxOnePersistentLocalStorageSize: 0
380380
intPropertyNames:
381381
- Metro::ScriptingBackend
382-
- Standalone::ScriptingBackend
383382
- WP8::ScriptingBackend
384383
- WebGL::ScriptingBackend
385384
- WebGL::audioCompressionFormat
@@ -388,7 +387,6 @@ PlayerSettings:
388387
- iOS::Architecture
389388
- iOS::ScriptingBackend
390389
Metro::ScriptingBackend: 2
391-
Standalone::ScriptingBackend: 0
392390
WP8::ScriptingBackend: 2
393391
WebGL::ScriptingBackend: 1
394392
WebGL::audioCompressionFormat: 4
@@ -397,19 +395,13 @@ PlayerSettings:
397395
iOS::Architecture: 2
398396
iOS::ScriptingBackend: 0
399397
boolPropertyNames:
400-
- WebGL::analyzeBuildSize
401398
- WebGL::dataCaching
402-
- WebGL::useEmbeddedResources
403-
WebGL::analyzeBuildSize: 0
404399
WebGL::dataCaching: 0
405-
WebGL::useEmbeddedResources: 0
406400
stringPropertyNames:
407401
- WebGL::emscriptenArgs
408402
- WebGL::template
409-
- additionalIl2CppArgs::additionalIl2CppArgs
410403
WebGL::emscriptenArgs:
411404
WebGL::template: APPLICATION:Default
412-
additionalIl2CppArgs::additionalIl2CppArgs:
413405
firstStreamedSceneWithResources: 0
414406
cloudProjectId:
415407
projectId:

0 commit comments

Comments
 (0)