BoxCollider.cs 2.0 KB

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