Feature : Adding the dev room #1

Merged
BoxOfPandor merged 17 commits from feat/add-dev-room into Prototype 2026-03-10 09:14:27 +01:00
3 changed files with 37240 additions and 72 deletions
Showing only changes of commit cf523f77ec - Show all commits

View File

@@ -1,4 +1,3 @@
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
@@ -7,23 +6,31 @@ using UnityEngine.InputSystem;
public class WallInteractButton : MonoBehaviour
{
[Header("Interaction")]
[Tooltip("Optional Input Action. If empty, fallback key will be used.")]
[SerializeField] private InputActionReference interactAction;
[Tooltip("Used only if no Input Action is assigned.")]
[SerializeField] private Key fallbackKey = Key.E;
[Tooltip("Key the player must press to interact (keyboard fallback).")]
[SerializeField] private Key interactKey = Key.E;
[Tooltip("If true, the button can only be triggered once.")]
[SerializeField] private bool oneShot = false;
[Header("Prompt")]
[SerializeField] private TMP_Text promptText;
[SerializeField] private string promptMessage = "Press E to interact";
[Header("Physical Press")]
[Tooltip("Transform that moves to simulate a physical press (optional).")]
[SerializeField] private Transform buttonMesh;
[Tooltip("How far the button moves when pressed.")]
[SerializeField] private float pressDepth = 0.05f;
[Tooltip("Speed of the press/release animation.")]
[SerializeField] private float pressSpeed = 10f;
[Header("Events")]
public UnityEvent OnInteract;
private bool m_playerInRange;
private bool m_hasInteracted;
private bool m_used;
private Vector3 m_buttonRestPos;
private Vector3 m_buttonPressedPos;
private bool m_isVisuallyPressed;
private void Reset()
{
@@ -31,79 +38,99 @@ public class WallInteractButton : MonoBehaviour
col.isTrigger = true;
}
private void OnEnable()
{
if (interactAction != null)
{
interactAction.action.Enable();
}
}
private void OnDisable()
{
if (interactAction != null)
{
interactAction.action.Disable();
}
}
private void Start()
{
UpdatePrompt(false);
if (buttonMesh != null)
{
m_buttonRestPos = buttonMesh.localPosition;
m_buttonPressedPos = m_buttonRestPos - buttonMesh.localRotation * Vector3.forward * pressDepth;
}
}
private void Update()
{
if (!m_playerInRange)
return;
if (oneShot && m_hasInteracted)
return;
if (WasInteractPressed())
if (m_playerInRange && Keyboard.current != null && Keyboard.current[interactKey].wasPressedThisFrame)
{
m_hasInteracted = true;
OnInteract?.Invoke();
TryInteract();
}
AnimateButton();
}
private void TryInteract()
{
if (oneShot && m_used)
return;
m_used = true;
m_isVisuallyPressed = true;
OnInteract?.Invoke();
if (!oneShot)
Invoke(nameof(ReleaseVisual), 0.15f);
}
private void ReleaseVisual()
{
m_isVisuallyPressed = false;
}
private void AnimateButton()
{
if (buttonMesh == null)
return;
Vector3 target = m_isVisuallyPressed ? m_buttonPressedPos : m_buttonRestPos;
buttonMesh.localPosition = Vector3.Lerp(buttonMesh.localPosition, target, Time.deltaTime * pressSpeed);
}
private void OnTriggerEnter(Collider other)
{
if (!IsPlayer(other))
return;
if (IsPlayer(other))
m_playerInRange = true;
UpdatePrompt(true);
}
private void OnTriggerExit(Collider other)
{
if (!IsPlayer(other))
return;
if (IsPlayer(other))
m_playerInRange = false;
UpdatePrompt(false);
}
private bool WasInteractPressed()
{
if (interactAction != null)
return interactAction.action.WasPressedThisFrame() || interactAction.action.WasPerformedThisFrame();
return Keyboard.current != null && Keyboard.current[fallbackKey].wasPressedThisFrame;
}
private bool IsPlayer(Collider other)
{
return other.CompareTag("Player") || other.GetComponentInParent<PlayerMovement>() != null;
if (other.CompareTag("Player"))
return true;
if (other.GetComponentInParent<PlayerMovement>() != null)
return true;
return false;
}
private void UpdatePrompt(bool visible)
#if UNITY_EDITOR
private void OnDrawGizmos()
{
if (promptText == null)
Collider col = GetComponent<Collider>();
if (col == null)
return;
promptText.text = promptMessage;
promptText.gameObject.SetActive(visible);
Gizmos.matrix = transform.localToWorldMatrix;
Gizmos.color = m_playerInRange
? new Color(0f, 1f, 0f, 0.25f)
: new Color(1f, 0.9f, 0f, 0.15f);
if (col is SphereCollider sphere)
{
Gizmos.DrawSphere(sphere.center, sphere.radius);
Gizmos.color = m_playerInRange ? Color.green : Color.yellow;
Gizmos.DrawWireSphere(sphere.center, sphere.radius);
}
else if (col is BoxCollider box)
{
Gizmos.DrawCube(box.center, box.size);
Gizmos.color = m_playerInRange ? Color.green : Color.yellow;
Gizmos.DrawWireCube(box.center, box.size);
}
}
#endif
}

File diff suppressed because one or more lines are too long

View File

@@ -69,11 +69,16 @@
{
"type": "System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"key": "ShapeBuilder.ActiveShapeIndex",
"value": "{\"m_Value\":6}"
"value": "{\"m_Value\":3}"
},
{
"type": "UnityEngine.Vector3, UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
"key": "ShapeBuilder.LastSize.Cube",
"value": "{\"m_Value\":{\"x\":0.10000000149011612,\"y\":2.0,\"z\":2.0}}"
},
{
"type": "UnityEngine.Vector3, UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
"key": "ShapeBuilder.LastSize.Sphere",
"value": "{\"m_Value\":{\"x\":0.5,\"y\":0.5,\"z\":0.5}}"
},
{
@@ -81,16 +86,31 @@
"key": "ShapeBuilder.LastRotation.Cube",
"value": "{\"m_Value\":{\"x\":0.0,\"y\":0.0,\"z\":0.0,\"w\":1.0}}"
},
{
"type": "UnityEngine.Quaternion, UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
"key": "ShapeBuilder.LastRotation.Sphere",
"value": "{\"m_Value\":{\"x\":0.0,\"y\":0.0,\"z\":0.0,\"w\":1.0}}"
},
{
"type": "UnityEngine.ProBuilder.PivotLocation, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
"key": "ShapeBuilder.PivotLocation.Cube",
"value": "{\"m_Value\":0}"
},
{
"type": "UnityEngine.ProBuilder.PivotLocation, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
"key": "ShapeBuilder.PivotLocation.Sphere",
"value": "{\"m_Value\":0}"
},
{
"type": "UnityEngine.ProBuilder.Shapes.Shape, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
"key": "ShapeBuilder.Cube",
"value": "{}"
},
{
"type": "UnityEngine.ProBuilder.Shapes.Shape, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
"key": "ShapeBuilder.Sphere",
"value": "{}"
},
{
"type": "UnityEngine.Rendering.ShadowCastingMode, UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
"key": "mesh.shadowCastingMode",