From 6c1365e40dfd603a501903f292ec88af6af7ab7e Mon Sep 17 00:00:00 2001 From: Santiago Lo Coco Date: Sun, 10 Nov 2024 21:00:08 +0100 Subject: [PATCH] Add recording toggle button in the hand menu --- Assets/Scenes/WebView.unity | 129 +++++++++++++++++++++++++- Assets/Scripts/VideoCaptureHandler.cs | 32 ++++--- ProjectSettings/ProjectSettings.asset | 4 +- 3 files changed, 148 insertions(+), 17 deletions(-) diff --git a/Assets/Scenes/WebView.unity b/Assets/Scenes/WebView.unity index a359ba7..48a4901 100644 --- a/Assets/Scenes/WebView.unity +++ b/Assets/Scenes/WebView.unity @@ -326,6 +326,38 @@ Transform: m_Father: {fileID: 874783136} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &37601137 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 37601138} + m_Layer: 0 + m_Name: BackPlateToggle + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 0 +--- !u!4 &37601138 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 37601137} + 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_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 1138108149} + m_Father: {fileID: 1434034947} + m_RootOrder: 3 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &39324663 GameObject: m_ObjectHideFlags: 0 @@ -1444,6 +1476,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 213eedf9daf5d174eaae7f09687660c2, type: 3} m_Name: m_EditorClassIdentifier: + videoCaptureButton: {fileID: 1434034946} --- !u!1 &311871181 GameObject: m_ObjectHideFlags: 0 @@ -5903,6 +5936,89 @@ Transform: m_Father: {fileID: 661354343} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1138108148 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1138108149} + - component: {fileID: 1138108152} + - component: {fileID: 1138108151} + m_Layer: 0 + m_Name: Quad + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1138108149 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1138108148} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0.005} + m_LocalScale: {x: 0.025, y: 0.025, z: 0.001} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 37601138} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!23 &1138108151 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1138108148} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 2 + m_LightProbeUsage: 0 + m_ReflectionProbeUsage: 0 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 552f1a3245d3edc4a96fe296c950532a, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_AdditionalVertexStreams: {fileID: 0} +--- !u!33 &1138108152 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1138108148} + m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0} --- !u!1 &1178961612 GameObject: m_ObjectHideFlags: 0 @@ -6525,6 +6641,7 @@ Transform: - {fileID: 721881399} - {fileID: 1051310894} - {fileID: 1573461585} + - {fileID: 37601138} m_Father: {fileID: 5499636272584020691} m_RootOrder: 5 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -6686,20 +6803,22 @@ MonoBehaviour: states: {fileID: 11400000, guid: e51893c8eb7938e4ba43985af43c0f72, type: 2} InputActionId: 0 isGlobal: 0 - Dimensions: 1 + Dimensions: 2 dimensionIndex: 0 startDimensionIndex: 0 - CanSelect: 0 - CanDeselect: 0 + CanSelect: 1 + CanDeselect: 1 voiceCommand: Select voiceRequiresFocus: 1 profiles: - Target: {fileID: 843332182} Themes: - {fileID: 11400000, guid: 8f8cfb3041153fa45bccb6d664a563ec, type: 2} - - Target: {fileID: 495050159} + - {fileID: 11400000, guid: 8f8cfb3041153fa45bccb6d664a563ec, type: 2} + - Target: {fileID: 37601137} Themes: - - {fileID: 11400000, guid: 087b16002c2b0b445baa3ed3beae44a9, type: 2} + - {fileID: 11400000, guid: 452ab0b768e73aa45a65adeb08147cec, type: 2} + - {fileID: 11400000, guid: c020ebf06513a084caa57aa68a245a6b, type: 2} OnClick: m_PersistentCalls: m_Calls: diff --git a/Assets/Scripts/VideoCaptureHandler.cs b/Assets/Scripts/VideoCaptureHandler.cs index c807cd9..24416cb 100644 --- a/Assets/Scripts/VideoCaptureHandler.cs +++ b/Assets/Scripts/VideoCaptureHandler.cs @@ -5,12 +5,17 @@ using System.IO; using System.Threading.Tasks; using UnityEngine; using UnityEngine.Windows.WebCam; +using Microsoft.MixedReality.Toolkit.UI; #if WINDOWS_UWP && !UNITY_EDITOR using Windows.Storage; #endif public class VideoCaptureHandler : MonoBehaviour { + [SerializeField] + private GameObject videoCaptureButton = null; + + private Interactable videoCaptureButtonInteractable = null; private VideoCapture videoCapture = null; #if WINDOWS_UWP && !UNITY_EDITOR @@ -37,7 +42,7 @@ public class VideoCaptureHandler : MonoBehaviour if (availableSpace < minAvailableSpace) { Debug.LogWarning("Not enough storage space to continue recording. Saving video."); - videoCapture.StopRecordingAsync(OnStoppedRecordingVideo); + StopRecordingVideo(); } } catch (Exception ex) @@ -54,6 +59,17 @@ public class VideoCaptureHandler : MonoBehaviour #else VideoCapture.CreateAsync(false, OnVideoCaptureCreated); #endif + if (videoCaptureButtonInteractable == null) + { + videoCaptureButtonInteractable = videoCaptureButton.GetComponent(); + } + videoCaptureButtonInteractable.IsToggled = true; + } + + public void StopRecordingVideo() + { + videoCapture.StopRecordingAsync(OnStoppedRecordingVideo); + videoCaptureButtonInteractable.IsToggled = false; } public void ToggleRecordingVideo() @@ -107,7 +123,7 @@ public class VideoCaptureHandler : MonoBehaviour } else { - Debug.LogError("Failed to create VideoCapture Instance"); + Debug.LogError("Failed to create VideoCapture instance"); } } @@ -117,7 +133,7 @@ public class VideoCaptureHandler : MonoBehaviour { string filename = string.Format("WebView_{0}.mp4", DateTime.UtcNow.ToString("yyyy-MM-ddTHHmmssZ")); string filepath = Path.Combine(Application.persistentDataPath, filename); - Debug.Log("Saving Video to: " + filepath); + Debug.Log("Saving video to: " + filepath); videoCapture.StartRecordingAsync(filepath, OnStartedRecordingVideo); } @@ -125,21 +141,15 @@ public class VideoCaptureHandler : MonoBehaviour private void OnStartedRecordingVideo(VideoCapture.VideoCaptureResult result) { - Debug.Log("Started Recording Video"); + Debug.Log("Started recording video"); #if WINDOWS_UWP && !UNITY_EDITOR StartCoroutine(CheckAvailableStorageSpace()); #endif } - public void StopRecordingVideo() - { - Debug.Log("Stopping Video Recording"); - videoCapture.StopRecordingAsync(OnStoppedRecordingVideo); - } - private void OnStoppedRecordingVideo(VideoCapture.VideoCaptureResult result) { - Debug.Log("Stopped Recording Video"); + Debug.Log("Stopped recording video"); videoCapture.StopVideoModeAsync(OnStoppedVideoCaptureMode); } diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 9edf22e..1a301bd 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -138,7 +138,9 @@ PlayerSettings: 16:9: 1 Others: 1 bundleVersion: 0.1 - preloadedAssets: [] + preloadedAssets: + - {fileID: 3919825601010146741, guid: 3f9164acd8abd4446a837f0de5c295d6, type: 2} + - {fileID: -8850236580838408871, guid: c00f5eb6c0921504a9911f55c664e377, type: 2} metroInputSource: 0 wsaTransparentSwapchain: 0 m_HolographicPauseOnTrackingLoss: 1