fix/dev-room #5

Merged
Antoine2507 merged 31 commits from fix/dev-room into Prototype 2026-03-17 10:49:58 +01:00
2 changed files with 1194 additions and 34603 deletions
Showing only changes of commit 44d3ef02a3 - Show all commits

View File

@@ -20,6 +20,7 @@ public class PressurePlateButton : MonoBehaviour
public UnityEvent OnReleased;
private readonly HashSet<Collider> m_validCollidersOnPlate = new HashSet<Collider>();
private readonly HashSet<Collider> m_stayedThisPhysicsFrame = new HashSet<Collider>();
private bool m_isPressed;
private void Reset()
@@ -42,8 +43,16 @@ public class PressurePlateButton : MonoBehaviour
}
}
private void OnTriggerStay(Collider other)
{
if (IsValidActivator(other))
m_stayedThisPhysicsFrame.Add(other);
}
private void OnTriggerExit(Collider other)
{
m_stayedThisPhysicsFrame.Remove(other);
if (!m_validCollidersOnPlate.Remove(other))
return;
@@ -54,6 +63,26 @@ public class PressurePlateButton : MonoBehaviour
}
}
private void FixedUpdate()
{
if (m_validCollidersOnPlate.Count == 0)
{
m_stayedThisPhysicsFrame.Clear();
return;
}
m_validCollidersOnPlate.RemoveWhere(c => c == null || !c.enabled || !c.gameObject.activeInHierarchy);
m_validCollidersOnPlate.IntersectWith(m_stayedThisPhysicsFrame);
m_stayedThisPhysicsFrame.Clear();
if (m_validCollidersOnPlate.Count == 0 && m_isPressed)
{
m_isPressed = false;
OnReleased?.Invoke();
}
}
private bool IsValidActivator(Collider other)
{
if (((1 << other.gameObject.layer) & detectionMask) == 0)

File diff suppressed because one or more lines are too long