SFX_ColliderCollisionDetector.cs 969 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using UnityEngine;
  3. // ReSharper disable once CheckNamespace
  4. namespace QFX.SFX
  5. {
  6. public class SFX_ColliderCollisionDetector : SFX_ControlledObject, SFX_ICollisionsProvider
  7. {
  8. public bool IsSingleCollisionMode = true;
  9. private bool _wasCollided;
  10. public event Action<SFX_CollisionPoint> OnCollision;
  11. private void OnCollisionEnter(Collision collision)
  12. {
  13. if (!IsRunning)
  14. return;
  15. if (_wasCollided && IsSingleCollisionMode)
  16. return;
  17. foreach (var contact in collision.contacts)
  18. {
  19. if (!_wasCollided)
  20. _wasCollided = true;
  21. if (OnCollision != null)
  22. OnCollision.Invoke(new SFX_CollisionPoint
  23. {
  24. Point = contact.point,
  25. Normal = contact.normal
  26. });
  27. }
  28. }
  29. }
  30. }