PlaneCollider.cs 2.2 KB

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