BoxCollider.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. value = new Vector3(MathEx.Max(value.x, 0.01f), MathEx.Max(value.y, 0.01f), MathEx.Max(value.z, 0.01f));
  21. if (extents == value)
  22. return;
  23. extents = value;
  24. if (Native != null)
  25. {
  26. Native.Extents = value;
  27. if (parent != null)
  28. parent.UpdateMassDistribution();
  29. }
  30. }
  31. }
  32. /// <summary>
  33. /// Position of the box shape, relative to the component's scene object.
  34. /// </summary>
  35. public Vector3 Center
  36. {
  37. get { return serializableData.localPosition; }
  38. set
  39. {
  40. if (serializableData.localPosition == value)
  41. return;
  42. serializableData.localPosition = value;
  43. if (Native != null)
  44. UpdateTransform();
  45. }
  46. }
  47. /// <summary>
  48. /// Returns the native box collider wrapped by this component.
  49. /// </summary>
  50. private NativeBoxCollider Native
  51. {
  52. get { return (NativeBoxCollider)native; }
  53. }
  54. /// <inheritdoc/>
  55. internal override NativeCollider CreateCollider()
  56. {
  57. NativeBoxCollider boxCollider = new NativeBoxCollider();
  58. boxCollider.Extents = extents;
  59. return boxCollider;
  60. }
  61. }
  62. }