From fbbfaf9e3e9bed18229b997cd35a2922ac207164 Mon Sep 17 00:00:00 2001 From: Guilherme Hernandez Date: Sat, 28 Nov 2020 23:45:36 -0300 Subject: [PATCH] Improve switching between ROCamera and FreeflyCam --- Assets/Scripts/Core.cs | 23 ++++++++++++++++++++--- Assets/Scripts/FreeflyCam.cs | 9 --------- Assets/Scripts/Renderer/ROCamera.cs | 2 +- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Assets/Scripts/Core.cs b/Assets/Scripts/Core.cs index 8fafed2d..f2ac18fc 100644 --- a/Assets/Scripts/Core.cs +++ b/Assets/Scripts/Core.cs @@ -39,14 +39,14 @@ public static PathFindingManager PathFinding { private static string CFG_NAME = "config.txt"; private bool isMapSelectorEnabled = false; - private bool isRoCamEnabled = false; + private bool isRoCamEnabled = true; private void Awake() { if (Instance == null) { Instance = this; } - /** + /** * Caching the camera as it's heavy to search for it */ if (MainCamera == null) { @@ -114,16 +114,33 @@ void FixedUpdate() { } void Update() { + // ESC pressed: toggle map selector visiblity if (Input.GetKeyDown(KeyCode.Escape)) { isMapSelectorEnabled = !isMapSelectorEnabled; mapDropdown.gameObject.SetActive(isMapSelectorEnabled); - } else if (Input.GetKeyDown(KeyCode.F1)) { + + // disable cameras when map selector is visible + MainCamera.GetComponent().enabled = !isMapSelectorEnabled && isRoCamEnabled; + MainCamera.GetComponent().enabled = !isMapSelectorEnabled && !isRoCamEnabled; + + // disable entity when map selector is visible + MainCamera.GetComponentInParent().enabled = !isMapSelectorEnabled; + } + + // F1 pressed and not on map selector: switch between ROCamera and FreeflyCam + if (Input.GetKeyDown(KeyCode.F1) && !isMapSelectorEnabled) { isRoCamEnabled = !isRoCamEnabled; MainCamera.GetComponent().enabled = isRoCamEnabled; MainCamera.GetComponent().enabled = !isRoCamEnabled; Cursor.lockState = isRoCamEnabled ? CursorLockMode.None : Cursor.lockState; Cursor.visible = isRoCamEnabled; + + // switched to ROCamera: updated it so we go from wherever + // freefly is to where ROCam should be + if (isRoCamEnabled) { + MainCamera.GetComponent().Start(); + } } diff --git a/Assets/Scripts/FreeflyCam.cs b/Assets/Scripts/FreeflyCam.cs index 8089ade8..98a26296 100644 --- a/Assets/Scripts/FreeflyCam.cs +++ b/Assets/Scripts/FreeflyCam.cs @@ -46,15 +46,6 @@ void Start() { } void Update() { - if(Input.GetKeyDown(KeyCode.End) || Input.GetKeyDown(KeyCode.Escape)) { - Cursor.lockState = (CursorLockMode.Locked != Cursor.lockState) ? CursorLockMode.Locked : CursorLockMode.None; - Cursor.visible = Cursor.lockState != CursorLockMode.Locked; - } - - if(Cursor.lockState != CursorLockMode.Locked) { - return; - } - rotationX = rotationX + Input.GetAxis("Mouse X") * cameraSensitivity; rotationY = rotationY + Input.GetAxis("Mouse Y") * cameraSensitivity; rotationY = Mathf.Clamp(rotationY, -90, 90); diff --git a/Assets/Scripts/Renderer/ROCamera.cs b/Assets/Scripts/Renderer/ROCamera.cs index ad843be7..4c2084c3 100644 --- a/Assets/Scripts/Renderer/ROCamera.cs +++ b/Assets/Scripts/Renderer/ROCamera.cs @@ -29,7 +29,7 @@ public enum DIRECTION : int { [SerializeField] private float rotation = 0f; [SerializeField] private float angle; - private void Start() { + public void Start() { HandleYawPitch(); HandleZoom(); }