Octave3DBoxCollider.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #if UNITY_EDITOR
  2. using UnityEngine;
  3. namespace O3DWB
  4. {
  5. public class Octave3DBoxCollider : Octave3DCollider
  6. {
  7. #region Private Variables
  8. private OrientedBox _orientedBox;
  9. #endregion
  10. #region Public Properties
  11. public OrientedBox OrientedBox { get { return new OrientedBox(_orientedBox); } }
  12. public Box ModelSpaceBox { get { return _orientedBox.ModelSpaceBox; } }
  13. #endregion
  14. #region Constructors
  15. public Octave3DBoxCollider(OrientedBox orientedBox)
  16. {
  17. _orientedBox = new OrientedBox(orientedBox);
  18. }
  19. #endregion
  20. #region Public Methods
  21. public override Octave3DColliderType GetColliderType()
  22. {
  23. return Octave3DColliderType.Box;
  24. }
  25. public override bool Raycast(Ray ray, out Octave3DColliderRayHit colliderRayHit)
  26. {
  27. colliderRayHit = null;
  28. float t;
  29. if (_orientedBox.Raycast(ray, out t))
  30. {
  31. Vector3 hitPoint = ray.GetPoint(t);
  32. BoxFace faceWhichContainsHitPoint = _orientedBox.GetBoxFaceClosestToPoint(hitPoint);
  33. Vector3 hitNormal = _orientedBox.GetBoxFacePlane(faceWhichContainsHitPoint).normal;
  34. colliderRayHit = new Octave3DColliderRayHit(ray, t, hitPoint, hitNormal, this);
  35. }
  36. return colliderRayHit != null;
  37. }
  38. #endregion
  39. }
  40. }
  41. #endif