Fix: cleanup and minor perf improvements
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user