BoxCollider.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. namespace BansheeEngine
  2. {
  3. /// <summary>
  4. /// Collider with box geometry.
  5. /// </summary>
  6. public sealed class BoxCollider : Collider
  7. {
  8. [SerializeField]
  9. private Vector3 extents = Vector3.One;
  10. /// <summary>
  11. /// Extents (half size) of the geometry of the box.
  12. /// </summary>
  13. public Vector3 Extents
  14. {
  15. get { return extents; }
  16. set
  17. {
  18. if (extents == value)
  19. return;
  20. extents = value;
  21. if (Native != null)
  22. {
  23. Native.Extents = value;
  24. if (parent != null)
  25. parent.UpdateMassDistribution();
  26. }
  27. }
  28. }
  29. /// <summary>
  30. /// Position of the box shape, relative to the component's scene object.
  31. /// </summary>
  32. public Vector3 Center
  33. {
  34. get { return serializableData.localPosition; }
  35. set
  36. {
  37. if (serializableData.localPosition == value)
  38. return;
  39. serializableData.localPosition = value;
  40. if (Native != null)
  41. UpdateTransform();
  42. }
  43. }
  44. /// <summary>
  45. /// Returns the native box collider wrapped by this component.
  46. /// </summary>
  47. private NativeBoxCollider Native
  48. {
  49. get { return (NativeBoxCollider)native; }
  50. }
  51. /// <inheritdoc/>
  52. internal override NativeCollider CreateCollider()
  53. {
  54. NativeBoxCollider boxCollider = new NativeBoxCollider();
  55. boxCollider.Extents = extents;
  56. return boxCollider;
  57. }
  58. }
  59. }