diff --git a/Fika.Core/Coop/FreeCamera/FreeCamera.cs b/Fika.Core/Coop/FreeCamera/FreeCamera.cs index acdea910..f988cdab 100644 --- a/Fika.Core/Coop/FreeCamera/FreeCamera.cs +++ b/Fika.Core/Coop/FreeCamera/FreeCamera.cs @@ -29,6 +29,7 @@ public class FreeCamera : MonoBehaviour private bool showOverlay; private NightVision nightVision; private ThermalVision thermalVision; + private FreeCameraController freeCameraController; private KeyCode forwardKey = KeyCode.W; private KeyCode backKey = KeyCode.S; @@ -57,6 +58,8 @@ protected void Start() nightVision = CameraClass.Instance.NightVision; thermalVision = CameraClass.Instance.ThermalVision; + + freeCameraController = Singleton.Instance.gameObject.GetComponent(); } private void KeybindOverlay_SettingChanged(object sender, EventArgs e) @@ -88,6 +91,7 @@ protected void OnGUI() GUILayout.Label($"Spacebar + Left/Right Mouse Button: Jump and spectate in head cam"); GUILayout.Label($"T: Teleport to cam position"); GUILayout.Label($"N: {visionText}"); + GUILayout.Label($"M: Disable culling"); GUILayout.Label($"HOME: {(disableInput ? "Enable Input" : "Disable Input")}"); GUILayout.Label($"Shift + Ctrl: Turbo Speed"); @@ -103,11 +107,11 @@ protected void Update() return; } + // Toggle input if (Input.GetKeyDown(KeyCode.Home)) { disableInput = !disableInput; - string status = disableInput == true ? "disabled" : "enabled"; - NotificationManagerClass.DisplayMessageNotification($"Free cam input is now {status}."); + NotificationManagerClass.DisplayMessageNotification($"Free cam input is now {(disableInput ? "disabled" : "enabled")}."); } if (disableInput) @@ -289,11 +293,21 @@ protected void Update() } } + // Toggle vision if (Input.GetKeyDown(KeyCode.N)) { ToggleVision(); } + // Disable culling + if (Input.GetKeyDown(KeyCode.M)) + { + if (freeCameraController != null) + { + freeCameraController.DisableAllCullingObjects(); + } + } + if (isFollowing) { if (CurrentPlayer != null) diff --git a/Fika.Core/Coop/FreeCamera/FreeCameraController.cs b/Fika.Core/Coop/FreeCamera/FreeCameraController.cs index 71e8ee27..2624262e 100644 --- a/Fika.Core/Coop/FreeCamera/FreeCameraController.cs +++ b/Fika.Core/Coop/FreeCamera/FreeCameraController.cs @@ -46,6 +46,7 @@ public class FreeCameraController : MonoBehaviour private bool deathFadeEnabled; private DisablerCullingObjectBase[] allCullingObjects; private List previouslyActiveBakeGroups; + private bool hasEnabledCulling = false; protected void Awake() { @@ -368,7 +369,29 @@ private void SetPlayerToFreecamMode(Player localPlayer) _gamePlayerOwner.enabled = false; _freeCamScript.SetActive(true); + } + /// + /// A helper method to reset the player view back to First Person + /// + /// + private void SetPlayerToFirstPersonMode(Player localPlayer) + { + // re-enable _gamePlayerOwner + _gamePlayerOwner.enabled = true; + _freeCamScript.SetActive(false); + + localPlayer.PointOfView = EPointOfView.FirstPerson; + CameraClass.Instance.SetOcclusionCullingEnabled(true); + + if (hasEnabledCulling) + { + EnableAllCullingObjects(); + } + } + + public void DisableAllCullingObjects() + { int count = 0; foreach (DisablerCullingObjectBase cullingObject in allCullingObjects) { @@ -379,7 +402,9 @@ private void SetPlayerToFreecamMode(Player localPlayer) count++; cullingObject.SetComponentsEnabled(true); } - FikaPlugin.Instance.FikaLogger.LogDebug($"Enabled {count} Culling Triggers."); +#if DEBUG + FikaPlugin.Instance.FikaLogger.LogWarning($"Enabled {count} Culling Triggers."); +#endif PerfectCullingAdaptiveGrid perfectCullingAdaptiveGrid = FindObjectOfType(); if (perfectCullingAdaptiveGrid != null) @@ -404,21 +429,12 @@ private void SetPlayerToFreecamMode(Player localPlayer) } } } + + hasEnabledCulling = true; } - /// - /// A helper method to reset the player view back to First Person - /// - /// - private void SetPlayerToFirstPersonMode(Player localPlayer) + public void EnableAllCullingObjects() { - // re-enable _gamePlayerOwner - _gamePlayerOwner.enabled = true; - _freeCamScript.SetActive(false); - - localPlayer.PointOfView = EPointOfView.FirstPerson; - CameraClass.Instance.SetOcclusionCullingEnabled(true); - int count = 0; foreach (DisablerCullingObjectBase cullingObject in allCullingObjects) { @@ -429,7 +445,9 @@ private void SetPlayerToFirstPersonMode(Player localPlayer) count++; cullingObject.SetComponentsEnabled(false); } - FikaPlugin.Instance.FikaLogger.LogDebug($"Disabled {count} Culling Triggers."); +#if DEBUG + FikaPlugin.Instance.FikaLogger.LogWarning($"Disabled {count} Culling Triggers."); +#endif PerfectCullingAdaptiveGrid perfectCullingAdaptiveGrid = FindObjectOfType(); if (perfectCullingAdaptiveGrid != null) @@ -456,6 +474,8 @@ private void SetPlayerToFirstPersonMode(Player localPlayer) } } } + + hasEnabledCulling = false; } ///