fix/dev-room #5
@@ -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
Reference in New Issue
Block a user