Skip to content
9 changes: 9 additions & 0 deletions Assets/Gizmos.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/LeapMotion+OVR.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/LeapMotion.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/OVR.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/Plugins.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/Scripts.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 72 additions & 0 deletions Assets/Scripts/ScreenShotScript.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class ScreenShotScript : MonoBehaviour
{

public AudioSource shutterAudio;
public RawImage screenShot;
private Texture2D screenShotTexture;
private string lastScreenShotPath;

// Use this for initialization
void Start ()
{
screenShotTexture = new Texture2D (100, 100);
screenShot.texture = screenShotTexture;
}

// Update is called once per frame
void Update ()
{

}

void OnGUI ()
{
Event e = Event.current;

if (e.type == EventType.KeyDown && e.keyCode == KeyCode.F) {
string current_time = System.DateTime.Now.ToString ().Replace ("/", "_").Replace (":", "_");
lastScreenShotPath = Application.temporaryCachePath + "/" + current_time + ".png";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reasons, this path has a problem. After replacing Application.temporaryCachePath with ~/Desktop/, the number of errors are dramatically decreased.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

screen shot 2015-12-03 at 9 08 55 pm

On my machine this is how it's like.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That "Application.temporaryCachePath" returns a path for temporary usage. reference

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this was my misunderstanding. Path has no problem.

Debug.Log ("Screenshot saved: " + lastScreenShotPath);
TakeScreenShot (lastScreenShotPath);
shutterAudio.Play ();
}
}

void LateUpdate ()
{
StartCoroutine (DisplayScreenShot ());
}

private void TakeScreenShot (string path)
{
StartCoroutine (CaptureScreen (path));
}

private IEnumerator CaptureScreen (string path)
{
// Wait till the last possible moment before screen rendering to hide the UI
yield return null;

// Wait for screen rendering to complete
yield return new WaitForEndOfFrame ();

// Take screenshot
Application.CaptureScreenshot (path);
}

private IEnumerator DisplayScreenShot ()
{
yield return null;

if (System.IO.File.Exists (lastScreenShotPath)) {
Debug.Log ("Last screenshot found!");
var screenShotBytes = System.IO.File.ReadAllBytes (lastScreenShotPath);
screenShotTexture.LoadImage (screenShotBytes);
screenShot.material.mainTexture = screenShotTexture;
}
}
}
12 changes: 12 additions & 0 deletions Assets/Scripts/ScreenShotScript.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

181 changes: 178 additions & 3 deletions Assets/_Scenes/MainScene.unity → Assets/_Scenes/CameraScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,80 @@ Transform:
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
--- !u!1 &614197765
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the file /Assets/_Scenes/MainScene.unity is used only for camera app, it should be named CameraScene.unity.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah if 'UnityEditor' is not available, which path should I use to save the screenshot?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I'll change the code and the scene name

GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 224: {fileID: 614197769}
- 222: {fileID: 614197768}
- 114: {fileID: 614197767}
- 114: {fileID: 614197766}
m_Layer: 5
m_Name: LastScreenShot
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &614197766
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 614197765}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8ae231a950bd349ba978d2b63ffc82c7, type: 3}
m_Name:
m_EditorClassIdentifier:
shutterAudio: {fileID: 1001552816}
screenShot: {fileID: 614197767}
--- !u!114 &614197767
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 614197765}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -98529514, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Texture: {fileID: 0}
m_UVRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
--- !u!222 &614197768
CanvasRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 614197765}
--- !u!224 &614197769
RectTransform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 614197765}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1655184830}
m_RootOrder: 0
m_AnchorMin: {x: .5, y: .5}
m_AnchorMax: {x: .5, y: .5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: .5, y: .5}
--- !u!1 &1001552815
GameObject:
m_ObjectHideFlags: 0
Expand All @@ -213,7 +287,7 @@ GameObject:
- 4: {fileID: 1001552817}
- 82: {fileID: 1001552816}
m_Layer: 0
m_Name: Audio Source
m_Name: ScreenShotShutterAudioSource
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
Expand All @@ -228,7 +302,7 @@ AudioSource:
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 8300000, guid: 4a64aea7c38a8432996fe575a7fc694e, type: 3}
m_audioClip: {fileID: 8300000, guid: 8ceb0f4b3eec34e7fb161b668911eb22, type: 3}
m_PlayOnAwake: 0
m_Volume: 1
m_Pitch: 1
Expand Down Expand Up @@ -295,11 +369,22 @@ Transform:
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1001552815}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 2, y: 19, z: 159}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
--- !u!1 &1074163266 stripped
GameObject:
m_PrefabParentObject: {fileID: 120736, guid: 3ec5dd60dda4e49ba89053ede7744b29, type: 2}
m_PrefabInternal: {fileID: 460777660}
--- !u!81 &1074163271
AudioListener:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1074163266}
m_Enabled: 1
--- !u!1 &1243471458
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -360,3 +445,93 @@ Transform:
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
--- !u!1 &1655184829
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 224: {fileID: 1655184830}
- 223: {fileID: 1655184833}
- 114: {fileID: 1655184832}
- 114: {fileID: 1655184831}
m_Layer: 5
m_Name: ScreenShotCanvas
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1655184830
RectTransform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1655184829}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 128}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 614197769}
m_Father: {fileID: 0}
m_RootOrder: 4
m_AnchorMin: {x: .5, y: .5}
m_AnchorMax: {x: .5, y: .5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: .5, y: .5}
--- !u!114 &1655184831
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1655184829}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1301386320, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IgnoreReversedGraphics: 1
m_BlockingObjects: 0
m_BlockingMask:
serializedVersion: 2
m_Bits: 4294967295
--- !u!114 &1655184832
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1655184829}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1980459831, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_UiScaleMode: 0
m_ReferencePixelsPerUnit: 100
m_ScaleFactor: 1
m_ReferenceResolution: {x: 800, y: 600}
m_ScreenMatchMode: 0
m_MatchWidthOrHeight: 0
m_PhysicalUnit: 3
m_FallbackScreenDPI: 96
m_DefaultSpriteDPI: 96
m_DynamicPixelsPerUnit: 1
--- !u!223 &1655184833
Canvas:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1655184829}
m_Enabled: 1
serializedVersion: 2
m_RenderMode: 2
m_Camera: {fileID: 0}
m_PlaneDistance: 100
m_PixelPerfect: 0
m_ReceivesEvents: 1
m_OverrideSorting: 0
m_OverridePixelPerfect: 0
m_SortingLayerID: 0
m_SortingOrder: 0

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ProjectSettings/EditorSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
EditorSettings:
m_ObjectHideFlags: 0
serializedVersion: 3
m_ExternalVersionControlSupport: Hidden Meta Files
m_ExternalVersionControlSupport: Visible Meta Files
m_SerializationMode: 2
m_WebSecurityEmulationEnabled: 0
m_WebSecurityEmulationHostUrl: http://www.mydomain.com/mygame.unity3d
Expand Down