PlaneCollider.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. namespace BansheeEngine
  2. {
  3. /// <summary>
  4. /// Collider with plane geometry.
  5. /// </summary>
  6. public sealed class PlaneCollider : Collider
  7. {
  8. [SerializeField]
  9. private float distance;
  10. [SerializeField]
  11. private Vector3 normal;
  12. /// <summary>
  13. /// Distance of the plane from the local origin, along its normal vector.
  14. /// </summary>
  15. public float Distance
  16. {
  17. get { return distance; }
  18. set
  19. {
  20. if (distance == value)
  21. return;
  22. distance = value;
  23. serializableData.localPosition = normal * distance;
  24. if (Native != null)
  25. UpdateTransform();
  26. }
  27. }
  28. /// <summary>
  29. /// Normal vector of the plane. It determines how is the plane oriented.
  30. /// </summary>
  31. public Vector3 Normal
  32. {
  33. get { return normal; }
  34. set
  35. {
  36. if (normal == value)
  37. return;
  38. normal = value.Normalized;
  39. serializableData.localRotation = Quaternion.FromToRotation(Vector3.XAxis, normal);
  40. if (Native != null)
  41. UpdateTransform();
  42. }
  43. }
  44. /// <inheritdoc/>
  45. protected override bool IsValidParent(Rigidbody parent)
  46. {
  47. // Planes cannot be added to non-kinematic rigidbodies
  48. return parent.IsKinematic;
  49. }
  50. /// <summary>
  51. /// Returns the native plane collider wrapped by this component.
  52. /// </summary>
  53. private NativePlaneCollider Native
  54. {
  55. get { return (NativePlaneCollider)native; }
  56. }
  57. /// <inheritdoc/>
  58. internal override NativeCollider CreateCollider()
  59. {
  60. return new NativePlaneCollider();
  61. }
  62. }
  63. }