Fix: cleanup and minor perf improvements

This commit is contained in:
Ferlat Thibaud
2026-03-25 01:28:18 +01:00
parent 9fd251f6e9
commit e69bdb93f8
21 changed files with 130 additions and 136 deletions
@@ -107,7 +107,7 @@ namespace Unheimlich.Features.DetectiveBoard
arms.HideArms(3f);
}
InputManager.SetContext(InputManager.InputContext.Listening);
InputManager.SetContext(InputManager.InputContext.DetectiveBoard);
if (_cameraHeadBob != null)
{
@@ -119,9 +119,6 @@ namespace Unheimlich.Features.DetectiveBoard
CrosshairController.Instance.Hide();
}
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
var cameraPan = PlayerController.Instance.CameraPanController;
var originalSettings = cameraPan.Settings;
@@ -200,9 +197,6 @@ namespace Unheimlich.Features.DetectiveBoard
{
CrosshairController.Instance.Show();
}
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
private void RestoreHeadBob()
@@ -63,7 +63,7 @@ namespace Unheimlich.Features.Dialogue
/// </summary>
public void Update()
{
if (!_manager.IsInDialogue || !_manager.CurrentDialogueUI.AreChoicesVisible())
if (!_manager.IsDialogueActive || !_manager.CurrentDialogueUI.AreChoicesVisible())
return;
_raycastTimer += Time.deltaTime;
@@ -16,7 +16,7 @@ namespace Unheimlich.Features.Dialogue
{
[Header("State")]
public bool IsInDialogue = false;
[SerializeField] private bool IsInDialogue = false;
[Header("Focus Settings")]
[SerializeField] private LayerMask _choiceLayer;
@@ -65,19 +65,7 @@ namespace Unheimlich.Features.Dialogue
if (_focusSystem != null)
{
_mainCamera = Camera.main;
_focusSystem = new DialogueFocusSystem(
this,
_mainCamera,
PlayerController.Instance?.CameraEffects,
_choiceLayer,
_focusRange,
_focusTime,
_raycastInterval,
_recoveryDuration,
_focusRetentionTime,
_fallbackShakeIntensity
);
_focusSystem.OnChoiceMade += (choice) => OnChoiceMade?.Invoke(choice);
InitFocusSystem();
// Also reset dialogue state in case we exited mid-dialogue
IsInDialogue = false;
@@ -89,7 +77,15 @@ namespace Unheimlich.Features.Dialogue
private void Start()
{
_mainCamera = Camera.main;
InitFocusSystem();
}
/// <summary>
/// Creates or recreates the DialogueFocusSystem with the current inspector settings.
/// Called from Start and OnEnabled (domain-reload-less re-entry).
/// </summary>
private void InitFocusSystem()
{
_focusSystem = new DialogueFocusSystem(
this,
_mainCamera,
@@ -10,14 +10,16 @@ namespace Unheimlich.Features.Dialogue.UI
{
private Transform _cameraTransform;
private void Start()
private void Awake()
{
_cameraTransform = Camera.main.transform;
_cameraTransform = Camera.main != null ? Camera.main.transform : null;
if (_cameraTransform == null)
Debug.LogWarning($"BillboardUI on {gameObject.name}: Main camera not found!");
}
private void Start() { }
private void LateUpdate()
{
if (_cameraTransform != null)
@@ -48,11 +48,14 @@ namespace Unheimlich.Features.Dialogue.UI
private int _fadeCanvasTweenId = -1;
private int _rotationTweenId = -1;
private List<int> _floatingTweenIds = new List<int>();
private Camera _mainCamera;
private static readonly Vector3 ViewportCenter = new Vector3(0.5f, 0.5f, 0f);
private void Awake()
{
_mainCamera = Camera.main;
if (_dialogueCanvasGroup == null && _dialoguePanel != null)
{
_dialogueCanvasGroup = _dialoguePanel.GetComponent<CanvasGroup>();
@@ -366,7 +369,7 @@ namespace Unheimlich.Features.Dialogue.UI
_sortTimer = 0f;
FloatingWordsSpawner.SortByDistance(_activeChoices, Camera.main);
FloatingWordsSpawner.SortByDistance(_activeChoices, _mainCamera);
}
}
}
@@ -44,8 +44,6 @@ namespace Unheimlich.Features.Diapason
_cameraHeadBob = GetComponentInChildren<CameraHeadBob>();
}
void OnDestroy() { }
void Update()
{
var diapasonAction = InputManager.GetDiapasonAction();
@@ -101,11 +101,6 @@ namespace Unheimlich.Features.Items
public float RotationSpeed => _rotationSpeed;
private void OnEnable()
{
LeanTween.init();
}
private void OnDestroy()
{
LeanTween.cancel(gameObject);
@@ -508,8 +508,7 @@ namespace Unheimlich.Features.Portals
if (_viewTexture != null)
_viewTexture.Release();
// Use DefaultHDR for better shadow and lighting compatibility in URP
_viewTexture = new RenderTexture(Screen.width, Screen.height, 24, RenderTextureFormat.DefaultHDR);
_viewTexture = new RenderTexture(Screen.width, Screen.height, PortalConstants.RENDER_TEXTURE_DEPTH, PortalConstants.RENDER_TEXTURE_FORMAT);
_viewTexture.filterMode = FilterMode.Bilinear;
_viewTexture.antiAliasing = 1;
_viewTexture.Create();
@@ -31,6 +31,7 @@ namespace Unheimlich.Features.Portals
private Portal _portal;
private Dictionary<AudioSource, AudioSource> _proxyMapping = new Dictionary<AudioSource, AudioSource>();
private Dictionary<AudioSource, AudioLowPassFilter> _filterMapping = new Dictionary<AudioSource, AudioLowPassFilter>();
private Camera _playerCamera;
private GameObject _lastLoadedRoomInstance;
private bool _needsRefresh;
@@ -38,6 +39,7 @@ namespace Unheimlich.Features.Portals
private void Awake()
{
_portal = GetComponent<Portal>();
_playerCamera = Camera.main;
}
private void OnEnable()
@@ -123,7 +125,7 @@ namespace Unheimlich.Features.Portals
/// </summary>
private void UpdateProxies()
{
Camera playerCam = Camera.main;
Camera playerCam = _playerCamera;
if (playerCam == null)
return;
@@ -32,7 +32,7 @@ namespace Unheimlich.Features.Portals
/// <summary>
/// Represents a room instance that has been loaded through a portal.
/// Caches room bounds for efficient distance calculations.
/// Caches room bounds and colliders for efficient distance/containment calculations.
/// </summary>
private class LoadedRoom
{
@@ -42,6 +42,7 @@ namespace Unheimlich.Features.Portals
public Portal SourcePortal;
public Bounds CachedBounds;
public bool BoundsCalculated = false;
public Collider[] CachedColliders;
}
private void Start()
@@ -184,7 +185,7 @@ namespace Unheimlich.Features.Portals
/// <summary>
/// Determines which room (if any) currently contains the player.
/// Uses collider bounds checks to detect room occupancy.
/// Uses cached collider bounds to detect room occupancy.
/// </summary>
private void UpdateCurrentPlayerRoom()
{
@@ -196,10 +197,12 @@ namespace Unheimlich.Features.Portals
if (loadedRoom.RoomInstance == null)
continue;
Collider[] roomColliders = loadedRoom.RoomInstance.GetComponentsInChildren<Collider>();
Collider[] roomColliders = loadedRoom.CachedColliders;
if (roomColliders == null) continue;
foreach (Collider col in roomColliders)
{
if (col.bounds.Contains(_player.position))
if (col != null && col.bounds.Contains(_player.position))
{
_currentPlayerRoom = loadedRoom.RoomInstance;
return;
@@ -247,7 +250,8 @@ namespace Unheimlich.Features.Portals
RoomInstance = roomInstance,
RoomId = roomId,
LoadPosition = portal.transform.position,
SourcePortal = portal
SourcePortal = portal,
CachedColliders = roomInstance.GetComponentsInChildren<Collider>()
};
_loadedRooms.Add(roomId, loadedRoom);