diff --git a/Viagg-io/Assets/Prefabs/UI/_HANDMENU.prefab b/Viagg-io/Assets/Prefabs/UI/_HANDMENU.prefab index 3e0286a..97f3b23 100644 --- a/Viagg-io/Assets/Prefabs/UI/_HANDMENU.prefab +++ b/Viagg-io/Assets/Prefabs/UI/_HANDMENU.prefab @@ -872,13 +872,13 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1053014236144696775} serializedVersion: 2 - m_LocalRotation: {x: -0.7071065, y: -0, z: -0, w: 0.7071071} - m_LocalPosition: {x: 0, y: 0.0123, z: 0.0493} + m_LocalRotation: {x: -0, y: -0.7071068, z: -0.7071068, w: 0} + m_LocalPosition: {x: 0, y: 0.0123, z: 0.04929924} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] - m_Father: {fileID: 5063272971443299340} - m_LocalEulerAnglesHint: {x: -90, y: 0, z: 0} + m_Father: {fileID: 1996412656006795194} + m_LocalEulerAnglesHint: {x: -90, y: 0, z: -180} --- !u!20 &7001199050030130134 Camera: m_ObjectHideFlags: 0 @@ -1619,9 +1619,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: - - {fileID: 107801045539344950} - - {fileID: 6202651521140937909} - - {fileID: 7824485373208701159} + - {fileID: 1996412656006795194} m_Father: {fileID: 5630431603393244975} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1897047047148633122 @@ -2823,6 +2821,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: _previewImg: {fileID: 437821110515054555} + _capturecam: {fileID: 7001199050030130134} --- !u!1 &3665889797944952490 GameObject: m_ObjectHideFlags: 0 @@ -4607,14 +4606,14 @@ RectTransform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5117592593628755675} - m_LocalRotation: {x: 0, y: 0.70710677, z: 0.70710677, w: 0} + m_LocalRotation: {x: -0, y: 0.7071068, z: 0.7071068, w: 0} m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 0.15144438, y: 0.17863165, z: 0.571365} + m_LocalScale: {x: 0.15144433, y: 0.17863162, z: 0.5713649} m_ConstrainProportionsScale: 0 m_Children: - {fileID: 7413929428606852214} - {fileID: 1816826061814438359} - m_Father: {fileID: 5063272971443299340} + m_Father: {fileID: 1996412656006795194} m_LocalEulerAnglesHint: {x: -90, y: 90, z: 90} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0} @@ -5008,6 +5007,40 @@ MonoBehaviour: m_Interactions: m_SingletonActionBindings: [] m_Flags: 0 +--- !u!1 &5547875041402855972 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1996412656006795194} + m_Layer: 9 + m_Name: SmartphoneParent + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1996412656006795194 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5547875041402855972} + serializedVersion: 2 + m_LocalRotation: {x: -0.15405792, y: 0.17151026, z: 0.027164565, w: 0.9726832} + m_LocalPosition: {x: -0.02, y: -0.03, z: 0.02} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 107801045539344950} + - {fileID: 6202651521140937909} + - {fileID: 7824485373208701159} + m_Father: {fileID: 5063272971443299340} + m_LocalEulerAnglesHint: {x: -18, y: 20, z: 0} --- !u!1 &5702985173780472227 GameObject: m_ObjectHideFlags: 0 @@ -6134,7 +6167,7 @@ PrefabInstance: serializedVersion: 2 m_Modification: serializedVersion: 3 - m_TransformParent: {fileID: 5063272971443299340} + m_TransformParent: {fileID: 1996412656006795194} m_Modifications: - target: {fileID: 152089758756199514, guid: fd16c97ca719775409e646d3ee101b19, type: 3} propertyPath: m_Layer diff --git a/Viagg-io/Assets/Scripts/Screenshot.cs b/Viagg-io/Assets/Scripts/Screenshot.cs index 7154d34..45e8327 100644 --- a/Viagg-io/Assets/Scripts/Screenshot.cs +++ b/Viagg-io/Assets/Scripts/Screenshot.cs @@ -3,27 +3,24 @@ using System.Collections.Generic; using UnityEngine; using System; using UnityEngine.UI; -using Oculus.Platform; public class Screenshot : MonoBehaviour { [SerializeField] RawImage _previewImg; - GameObject XRCamera; //the XR Player Camera, named "Main Camera" - GameObject XRHoloVideoCamera; //the XR Player Camera, named "Main Camera no-post-processing" - GameObject SmartphoneCaptureCamera; //the GameObject, named "SmartphoneCaptureCamera" is a Camera with a CullingMask where the Layer "hands" is excluded ("_HANDMENU" and "XR Interactions Hands Setup" are on the "hands" layer) + [SerializeField] + Camera _capturecam; + // Update is called once per frame void Update() { - //StartCoroutine(TakeScreenshot()); - - /* if (Input.GetKeyDown(KeyCode.P)) - { - StartCoroutine(TakeScreenshot()); - } - */ + /* if (Input.GetKeyDown(KeyCode.P)) + { + CreatePreview(); + }*/ + } public void OnClickTakeScreenshot() @@ -33,7 +30,7 @@ public class Screenshot : MonoBehaviour public void OnClickPreview() { - StartCoroutine(CreatePreview()); + CreatePreview(); } public void DestroyPreviewTexture() @@ -51,31 +48,27 @@ public class Screenshot : MonoBehaviour ScreenCapture.CaptureScreenshot("snapshot_" + timpStamp + ".png"); } - IEnumerator CreatePreview() + void CreatePreview() { - yield return new WaitForEndOfFrame(); - // find all Cameras: - XRCamera = GameObject.Find("Main Camera"); - XRHoloVideoCamera = GameObject.Find("Main Camera no-post-processing"); - SmartphoneCaptureCamera = GameObject.Find("SmartphoneCaptureCamera"); + _capturecam.enabled = true; + RenderTexture screenTexture = new RenderTexture(Screen.width, Screen.height, 16); + _capturecam.targetTexture = screenTexture; + RenderTexture.active = screenTexture; + _capturecam.Render(); - // get the Camera components: - Camera vrcam = XRCamera.GetComponent(); - Camera vrcamnopost = XRHoloVideoCamera.GetComponent(); - Camera capturecam = SmartphoneCaptureCamera.GetComponent(); + Texture2D renderedTexture = new Texture2D(Screen.width, Screen.height); + renderedTexture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0); + renderedTexture.Apply(); + + RenderTexture.active = null; + _capturecam.enabled = false; - // switch active Cameras - vrcam.enabled = false; - vrcamnopost.enabled = false; - capturecam.enabled = true; + _previewImg.texture = renderedTexture; - // call the function to take actual screenshot - _previewImg.texture = ScreenCapture.CaptureScreenshotAsTexture(); - - // switch active Cameras back - vrcam.enabled = true; - vrcamnopost.enabled = true; - capturecam.enabled = false; + // Save texture in png file + byte[] byteArray = renderedTexture.EncodeToPNG(); + string timpStamp = DateTime.Now.ToString("ddMMyyyyHHmmssffff"); + System.IO.File.WriteAllBytes(Application.persistentDataPath + $"/snapshot_{timpStamp}.png", byteArray); } } diff --git a/Viagg-io/ProjectSettings/ProjectSettings.asset b/Viagg-io/ProjectSettings/ProjectSettings.asset index 5d0529c..6d337e2 100644 --- a/Viagg-io/ProjectSettings/ProjectSettings.asset +++ b/Viagg-io/ProjectSettings/ProjectSettings.asset @@ -140,6 +140,9 @@ PlayerSettings: bundleVersion: 0.1 preloadedAssets: - {fileID: 11400000, guid: be340e3c48769439d8d18a5a2bccd498, type: 2} + - {fileID: 11400000, guid: bfa1182bd221b4ca89619141f66f1260, type: 2} + - {fileID: -8196854396901781169, guid: 1a4c68ca72a83449f938d669337cb305, type: 2} + - {fileID: 7708199778347151547, guid: 0f4832b23b368b643bc8a91696fbb473, type: 2} metroInputSource: 0 wsaTransparentSwapchain: 0 m_HolographicPauseOnTrackingLoss: 1