Mini demo with all features
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
using UnityEngine;
|
||||
using Unheimlich.Gameplay.Player;
|
||||
using Unheimlich.UI.DetectiveBoard;
|
||||
|
||||
namespace Unheimlich.NonEuclidean
|
||||
{
|
||||
public class DetectiveBoardPortalHider : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float _checkInterval = 0.1f;
|
||||
[SerializeField] private float _hideDistance = 5f;
|
||||
[SerializeField] private bool _enableDebugLogs = true;
|
||||
|
||||
private Canvas _detectiveBoardCanvas;
|
||||
private NonEuclideanManager _manager;
|
||||
private float _checkTimer;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_manager = NonEuclideanManager.Instance;
|
||||
|
||||
if (DetectiveBoardCanvas.Instance != null)
|
||||
{
|
||||
_detectiveBoardCanvas = DetectiveBoardCanvas.Instance.GetComponent<Canvas>();
|
||||
}
|
||||
|
||||
if (_enableDebugLogs)
|
||||
{
|
||||
Debug.Log($"[DetectiveBoardPortalHider] Initialized - Manager: {_manager != null}, Canvas: {_detectiveBoardCanvas != null}");
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_detectiveBoardCanvas == null || _manager == null || PlayerController.Instance == null)
|
||||
{
|
||||
if (_enableDebugLogs && Time.frameCount % 300 == 0)
|
||||
{
|
||||
Debug.LogWarning($"[DetectiveBoardPortalHider] Missing references - Canvas: {_detectiveBoardCanvas != null}, Manager: {_manager != null}, Player: {PlayerController.Instance != null}");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
_checkTimer += Time.deltaTime;
|
||||
|
||||
if (_checkTimer >= _checkInterval)
|
||||
{
|
||||
_checkTimer = 0f;
|
||||
CheckAndToggleCanvas();
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckAndToggleCanvas()
|
||||
{
|
||||
Vector3 playerPos = PlayerController.Instance.transform.position;
|
||||
NonEuclideanRoom currentRoom = _manager.ActiveRoom;
|
||||
|
||||
if (currentRoom == null)
|
||||
{
|
||||
if (_enableDebugLogs)
|
||||
Debug.LogWarning("[DetectiveBoardPortalHider] No active room");
|
||||
return;
|
||||
}
|
||||
|
||||
NonEuclideanRoom boardRoom = GetDetectiveBoardRoom();
|
||||
|
||||
if (boardRoom == null)
|
||||
{
|
||||
if (_enableDebugLogs && Time.frameCount % 300 == 0)
|
||||
Debug.LogWarning("[DetectiveBoardPortalHider] Could not find board room");
|
||||
_detectiveBoardCanvas.enabled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
bool isInBoardRoom = (currentRoom == boardRoom);
|
||||
|
||||
if (_enableDebugLogs)
|
||||
Debug.Log($"[DetectiveBoardPortalHider] Current room: {currentRoom.name}, Board room: {boardRoom.name}, In board room: {isInBoardRoom}, Portals count: {currentRoom.Portals.Length}");
|
||||
|
||||
foreach (var portal in currentRoom.Portals)
|
||||
{
|
||||
float distance = Vector3.Distance(playerPos, portal.transform.position);
|
||||
|
||||
bool shouldHide = false;
|
||||
|
||||
if (isInBoardRoom)
|
||||
{
|
||||
shouldHide = (distance < _hideDistance);
|
||||
|
||||
if (_enableDebugLogs && shouldHide)
|
||||
Debug.Log($"[DetectiveBoardPortalHider] In board room, close to portal '{portal.name}' (distance: {distance:F2}m) - hiding canvas");
|
||||
}
|
||||
else if (portal.TargetRoom == boardRoom)
|
||||
{
|
||||
shouldHide = (distance < _hideDistance);
|
||||
|
||||
if (_enableDebugLogs && shouldHide)
|
||||
Debug.Log($"[DetectiveBoardPortalHider] Close to portal '{portal.name}' leading to board room (distance: {distance:F2}m) - hiding canvas");
|
||||
}
|
||||
|
||||
if (shouldHide)
|
||||
{
|
||||
_detectiveBoardCanvas.enabled = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (_enableDebugLogs)
|
||||
Debug.Log("[DetectiveBoardPortalHider] Not close to any relevant portal - enabling canvas");
|
||||
_detectiveBoardCanvas.enabled = true;
|
||||
}
|
||||
|
||||
private NonEuclideanRoom GetDetectiveBoardRoom()
|
||||
{
|
||||
if (_detectiveBoardCanvas == null)
|
||||
return null;
|
||||
|
||||
Transform current = _detectiveBoardCanvas.transform;
|
||||
|
||||
while (current != null)
|
||||
{
|
||||
NonEuclideanRoom room = current.GetComponent<NonEuclideanRoom>();
|
||||
if (room != null)
|
||||
{
|
||||
if (_enableDebugLogs && Time.frameCount % 300 == 0)
|
||||
Debug.Log($"[DetectiveBoardPortalHider] Found board room: {room.name}");
|
||||
return room;
|
||||
}
|
||||
|
||||
current = current.parent;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 16e1f1371a69f6d4db490054110293b7
|
||||
@@ -183,10 +183,30 @@ namespace Unheimlich.NonEuclidean
|
||||
{
|
||||
if (obj == null) return;
|
||||
|
||||
obj.layer = layer;
|
||||
int currentLayer = obj.layer;
|
||||
|
||||
bool shouldPreserveLayer =
|
||||
currentLayer == LayerMask.NameToLayer("UI") ||
|
||||
currentLayer == LayerMask.NameToLayer("DetectiveBoard") ||
|
||||
currentLayer == LayerMask.NameToLayer("Interactable") ||
|
||||
currentLayer == LayerMask.NameToLayer("Player") ||
|
||||
currentLayer == LayerMask.NameToLayer("Words") ||
|
||||
currentLayer == LayerMask.NameToLayer("Listenable") ||
|
||||
currentLayer == LayerMask.NameToLayer("HandsTouch");
|
||||
|
||||
if (!shouldPreserveLayer)
|
||||
{
|
||||
obj.layer = layer;
|
||||
}
|
||||
|
||||
Collider collider = obj.GetComponent<Collider>();
|
||||
if (collider)
|
||||
{
|
||||
collider.enabled = !isBehindPortal;
|
||||
}
|
||||
|
||||
Renderer renderer = obj.GetComponent<Renderer>();
|
||||
if (renderer)
|
||||
if (renderer && !(renderer is CanvasRenderer))
|
||||
{
|
||||
/*MaterialPropertyBlock block = new MaterialPropertyBlock();
|
||||
renderer.GetPropertyBlock(block);
|
||||
|
||||
Reference in New Issue
Block a user