diff --git a/unity/Assets/Maroon/GlobalEntities/WebGlReceiver/WebGlReceiver.cs b/unity/Assets/Maroon/GlobalEntities/WebGlReceiver/WebGlReceiver.cs index d7488f6d8..c972e28c1 100644 --- a/unity/Assets/Maroon/GlobalEntities/WebGlReceiver/WebGlReceiver.cs +++ b/unity/Assets/Maroon/GlobalEntities/WebGlReceiver/WebGlReceiver.cs @@ -19,6 +19,8 @@ public class WebGlReceiver : MonoBehaviour, GlobalEntity public WebGlDataEvent OnIncomingData = new WebGlDataEvent(); + public UnityEvent OnPauseRequest = new UnityEvent(); + // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Properties, Getters and Setters public string MostRecentData { get; private set; } @@ -72,5 +74,17 @@ public void GetDataFromJavaScript(string data) MostRecentData = data; OnIncomingData.Invoke(data); } + + + /// + /// Called from Javascript code when Escape is pressed. + /// Useful because Input.GetKeyDown(KeyCode.Escape) might not always be caught, + /// because browser unlocks mouse cursor when pressing Escape while cursor is locked + /// + public void PauseRequest() + { + Debug.Log("Unity received a PauseRequest from Javascript"); + OnPauseRequest?.Invoke(); + } } } \ No newline at end of file diff --git a/unity/Assets/Maroon/SharedEntities/Player/ModeFirstPerson/ModeFirstPersonInputHandler.cs b/unity/Assets/Maroon/SharedEntities/Player/ModeFirstPerson/ModeFirstPersonInputHandler.cs index 53dfd5b40..aa6317b66 100644 --- a/unity/Assets/Maroon/SharedEntities/Player/ModeFirstPerson/ModeFirstPersonInputHandler.cs +++ b/unity/Assets/Maroon/SharedEntities/Player/ModeFirstPerson/ModeFirstPersonInputHandler.cs @@ -29,10 +29,8 @@ private void Start() { m_PlayerCharacterController = GetComponent(); - /* Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; - */ } private void LateUpdate() @@ -55,7 +53,6 @@ private void Update() public bool CanProcessInput() { - return true; // TODO return Cursor.lockState == CursorLockMode.Locked; } diff --git a/unity/Assets/Maroon/reusableGui/Menu/PrefabsBase/Maroon.ReusableGUI.Menu.PrefabsBase.asmdef b/unity/Assets/Maroon/reusableGui/Menu/PrefabsBase/Maroon.ReusableGUI.Menu.PrefabsBase.asmdef index 39b6d153a..c8a7921c2 100644 --- a/unity/Assets/Maroon/reusableGui/Menu/PrefabsBase/Maroon.ReusableGUI.Menu.PrefabsBase.asmdef +++ b/unity/Assets/Maroon/reusableGui/Menu/PrefabsBase/Maroon.ReusableGUI.Menu.PrefabsBase.asmdef @@ -4,12 +4,8 @@ "references": [ "GUID:f9b0aa2a96663864693b204ee0977e65", "GUID:833d205176b3e444a810dbf875342968", - "GUID:30817c1a0e6d646d99c048fc403f5979", - "GUID:e720aa64e3f58fb4880566a322584340", - "GUID:325984b52e4128546bc7558552f8b1d2", - "GUID:72872094b21c16e48b631b2224833d49", "GUID:6055be8ebefd69e48b49212b09b47b2f", - "GUID:7bdbd1a0d606bb444b8111edbc9d16cb" + "GUID:56f15dd651d5d3a44bbfc9ca89629921" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/unity/Assets/Maroon/reusableGui/Menu/PrefabsBase/scrMenu.cs b/unity/Assets/Maroon/reusableGui/Menu/PrefabsBase/scrMenu.cs index 2ebd4bcf1..e836947a5 100644 --- a/unity/Assets/Maroon/reusableGui/Menu/PrefabsBase/scrMenu.cs +++ b/unity/Assets/Maroon/reusableGui/Menu/PrefabsBase/scrMenu.cs @@ -1,10 +1,17 @@ -using UnityEngine; +#if UNITY_WEBGL +// For WebGlReceiver +using Maroon.GlobalEntities; +#endif +using UnityEngine; public class scrMenu : MonoBehaviour { // ################################################################################################################# // Members + private CursorLockMode cursorLockModeBeforeMenu = CursorLockMode.None; + private bool cursorVisibleBeforeMenu = true; + // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Open/Close @@ -52,6 +59,13 @@ private void Start() { this.OpenMenu(); } + +#if UNITY_WEBGL + if (this.EnableEscKey) + { + WebGlReceiver.Instance.OnPauseRequest.AddListener(() => OpenMenu()); + } +#endif } // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -75,19 +89,32 @@ public void Update() public void OpenMenu() { + if (IsOpen) + return; + + // Save cursor state and ensure cursor is useable + cursorLockModeBeforeMenu = Cursor.lockState; + cursorVisibleBeforeMenu = Cursor.visible; + Cursor.lockState = CursorLockMode.None; + Cursor.visible = true; + this.Canvas.SetActive(true); this.IsOpen = true; } - public void CloseMenu() { this.Canvas.SetActive(false); this.IsOpen = false; - - if(this.RemoveExtraColumnsOnClose) + if (this.RemoveExtraColumnsOnClose) { this.RemoveAllMenuColumnsButFirst(); } + + // Restore cursor state + Cursor.visible = cursorVisibleBeforeMenu; + Cursor.lockState = cursorLockModeBeforeMenu; + cursorLockModeBeforeMenu = CursorLockMode.None; + cursorVisibleBeforeMenu = true; } // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/unity/Assets/Maroon/reusableGui/Menu/PrefabsColumns/scrMenuColumnPauseMenu.cs b/unity/Assets/Maroon/reusableGui/Menu/PrefabsColumns/scrMenuColumnPauseMenu.cs index cd64c4ac1..98708dac1 100644 --- a/unity/Assets/Maroon/reusableGui/Menu/PrefabsColumns/scrMenuColumnPauseMenu.cs +++ b/unity/Assets/Maroon/reusableGui/Menu/PrefabsColumns/scrMenuColumnPauseMenu.cs @@ -89,12 +89,14 @@ private void OnClickMainMenu() { SceneManager.Instance.LoadSceneRequest(this.targetMainMenuSceneVR); } - else { SceneManager.Instance.LoadSceneRequest(this.targetMainMenuScenePC); } this.Menu.CloseMenu(); + + Cursor.lockState = CursorLockMode.None; + Cursor.visible = true; } private void OnClickResume() diff --git a/unity/Assets/Maroon/scenes/laboratory/prefabs/InfoSign/Scripts/scrInfoSignEnterScene.cs b/unity/Assets/Maroon/scenes/laboratory/prefabs/InfoSign/Scripts/scrInfoSignEnterScene.cs index 020895471..581829817 100644 --- a/unity/Assets/Maroon/scenes/laboratory/prefabs/InfoSign/Scripts/scrInfoSignEnterScene.cs +++ b/unity/Assets/Maroon/scenes/laboratory/prefabs/InfoSign/Scripts/scrInfoSignEnterScene.cs @@ -22,6 +22,13 @@ public class scrInfoSignEnterScene : MonoBehaviour public void EnterScene() { Debug.Log("Enter Scene : " + this.targetScene); + + if (!(PlatformManager.Instance.CurrentPlatformIsVR)) + { + Cursor.lockState = CursorLockMode.None; + Cursor.visible = true; + } + Maroon.GlobalEntities.SceneManager.Instance.LoadSceneRequest(this.targetScene); } diff --git a/unity/Assets/Maroon/scenes/special/MainMenu.pc.unity b/unity/Assets/Maroon/scenes/special/MainMenu.pc.unity index 4940d79c0..58b3302a3 100644 --- a/unity/Assets/Maroon/scenes/special/MainMenu.pc.unity +++ b/unity/Assets/Maroon/scenes/special/MainMenu.pc.unity @@ -3549,7 +3549,7 @@ PrefabInstance: - target: {fileID: 5344395389771861343, guid: 145cddb358f0d25439cf243545b2e848, type: 3} propertyPath: m_AnchoredPosition.y - value: 354.93225 + value: 354.94058 objectReference: {fileID: 0} - target: {fileID: 5352018906956156261, guid: 145cddb358f0d25439cf243545b2e848, type: 3} @@ -3989,7 +3989,7 @@ PrefabInstance: - target: {fileID: 6305038362095575829, guid: 145cddb358f0d25439cf243545b2e848, type: 3} propertyPath: m_AnchoredPosition.y - value: 354.93228 + value: 354.94052 objectReference: {fileID: 0} - target: {fileID: 6343315362415410101, guid: 145cddb358f0d25439cf243545b2e848, type: 3} @@ -5867,79 +5867,6 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1001 &841269665 -PrefabInstance: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - serializedVersion: 3 - m_TransformParent: {fileID: 0} - m_Modifications: - - target: {fileID: 6813379361624955085, guid: 6af4a1300054ffc47943d1822170d2a5, - type: 3} - propertyPath: m_RootOrder - value: 3 - objectReference: {fileID: 0} - - target: {fileID: 6813379361624955085, guid: 6af4a1300054ffc47943d1822170d2a5, - type: 3} - propertyPath: m_LocalPosition.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 6813379361624955085, guid: 6af4a1300054ffc47943d1822170d2a5, - type: 3} - propertyPath: m_LocalPosition.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 6813379361624955085, guid: 6af4a1300054ffc47943d1822170d2a5, - type: 3} - propertyPath: m_LocalPosition.z - value: 2 - objectReference: {fileID: 0} - - target: {fileID: 6813379361624955085, guid: 6af4a1300054ffc47943d1822170d2a5, - type: 3} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 6813379361624955085, guid: 6af4a1300054ffc47943d1822170d2a5, - type: 3} - propertyPath: m_LocalRotation.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 6813379361624955085, guid: 6af4a1300054ffc47943d1822170d2a5, - type: 3} - propertyPath: m_LocalRotation.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 6813379361624955085, guid: 6af4a1300054ffc47943d1822170d2a5, - type: 3} - propertyPath: m_LocalRotation.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 6813379361624955085, guid: 6af4a1300054ffc47943d1822170d2a5, - type: 3} - propertyPath: m_LocalEulerAnglesHint.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 6813379361624955085, guid: 6af4a1300054ffc47943d1822170d2a5, - type: 3} - propertyPath: m_LocalEulerAnglesHint.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 6813379361624955085, guid: 6af4a1300054ffc47943d1822170d2a5, - type: 3} - propertyPath: m_LocalEulerAnglesHint.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 6813379361625179373, guid: 6af4a1300054ffc47943d1822170d2a5, - type: 3} - propertyPath: m_Name - value: PlayerPC - objectReference: {fileID: 0} - m_RemovedComponents: [] - m_RemovedGameObjects: [] - m_AddedGameObjects: [] - m_AddedComponents: [] - m_SourcePrefab: {fileID: 100100000, guid: 6af4a1300054ffc47943d1822170d2a5, type: 3} --- !u!1001 &1025945157 PrefabInstance: m_ObjectHideFlags: 0 @@ -6116,6 +6043,159 @@ PrefabInstance: m_AddedGameObjects: [] m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: c6c418fdd21aa054fb854a2c70683b60, type: 3} +--- !u!1 &1713930002 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1713930004} + - component: {fileID: 1713930003} + - component: {fileID: 1713930006} + - component: {fileID: 1713930005} + m_Layer: 0 + m_Name: Camera + m_TagString: MainCamera + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!20 &1713930003 +Camera: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1713930002} + m_Enabled: 1 + serializedVersion: 2 + m_ClearFlags: 1 + m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} + m_projectionMatrixMode: 1 + m_GateFitMode: 2 + m_FOVAxisMode: 0 + m_Iso: 200 + m_ShutterSpeed: 0.005 + m_Aperture: 16 + m_FocusDistance: 10 + m_FocalLength: 50 + m_BladeCount: 5 + m_Curvature: {x: 2, y: 11} + m_BarrelClipping: 0.25 + m_Anamorphism: 0 + m_SensorSize: {x: 36, y: 24} + m_LensShift: {x: 0, y: 0} + m_NormalizedViewPortRect: + serializedVersion: 2 + x: 0 + y: 0 + width: 1 + height: 1 + near clip plane: 0.3 + far clip plane: 300 + field of view: 60 + orthographic: 0 + orthographic size: 5 + m_Depth: -1 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingPath: -1 + m_TargetTexture: {fileID: 0} + m_TargetDisplay: 0 + m_TargetEye: 3 + m_HDR: 1 + m_AllowMSAA: 1 + m_AllowDynamicResolution: 0 + m_ForceIntoRT: 0 + m_OcclusionCulling: 1 + m_StereoConvergence: 10 + m_StereoSeparation: 0.022 +--- !u!4 &1713930004 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1713930002} + serializedVersion: 2 + 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: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1713930005 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1713930002} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 948f4100a11a5c24981795d21301da5c, type: 3} + m_Name: + m_EditorClassIdentifier: + volumeTrigger: {fileID: 1713930004} + volumeLayer: + serializedVersion: 2 + m_Bits: 4096 + stopNaNPropagation: 1 + finalBlitToCameraTarget: 0 + antialiasingMode: 1 + temporalAntialiasing: + jitterSpread: 0.75 + sharpness: 0.25 + stationaryBlending: 0.95 + motionBlending: 0.85 + subpixelMorphologicalAntialiasing: + quality: 2 + fastApproximateAntialiasing: + fastMode: 1 + keepAlpha: 0 + fog: + enabled: 1 + excludeSkybox: 1 + debugLayer: + lightMeter: + width: 512 + height: 256 + showCurves: 1 + histogram: + width: 512 + height: 256 + channel: 3 + waveform: + exposure: 0.12 + height: 256 + vectorscope: + size: 256 + exposure: 0.12 + overlaySettings: + linearDepth: 0 + motionColorIntensity: 4 + motionGridSize: 64 + colorBlindnessType: 0 + colorBlindnessStrength: 1 + m_Resources: {fileID: 11400000, guid: d82512f9c8e5d4a4d938b575d47f88d4, type: 2} + m_ShowToolkit: 0 + m_ShowCustomSorter: 0 + breakBeforeColorGrading: 0 + m_BeforeTransparentBundles: [] + m_BeforeStackBundles: [] + m_AfterStackBundles: [] +--- !u!81 &1713930006 +AudioListener: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1713930002} + m_Enabled: 1 --- !u!1001 &2028860672 PrefabInstance: m_ObjectHideFlags: 0 @@ -6196,6 +6276,6 @@ SceneRoots: - {fileID: 1663446998} - {fileID: 330137523} - {fileID: 1025945157} - - {fileID: 841269665} + - {fileID: 1713930004} - {fileID: 2028860672} - {fileID: 497219649} diff --git a/unity/Assets/WebGLTemplates/MaroonWeb/index.html b/unity/Assets/WebGLTemplates/MaroonWeb/index.html index 78f271cb5..4c72af39a 100644 --- a/unity/Assets/WebGLTemplates/MaroonWeb/index.html +++ b/unity/Assets/WebGLTemplates/MaroonWeb/index.html @@ -302,5 +302,31 @@ ); +