SphereCollider.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. namespace BansheeEngine
  4. {
  5. /** @addtogroup Physics
  6. * @{
  7. */
  8. /// <summary>
  9. /// Collider with sphere geometry.
  10. /// </summary>
  11. public sealed class SphereCollider : Collider
  12. {
  13. [SerializeField]
  14. private float radius = 1.0f;
  15. /// <summary>
  16. /// Radius of the sphere.
  17. /// </summary>
  18. public float Radius
  19. {
  20. get { return radius; }
  21. set
  22. {
  23. value = MathEx.Max(value, 0.01f);
  24. if (radius == value)
  25. return;
  26. radius = value;
  27. if (Native != null)
  28. {
  29. Native.Radius = value;
  30. if (parent != null)
  31. parent.UpdateMassDistribution();
  32. }
  33. }
  34. }
  35. /// <summary>
  36. /// Position of the sphere shape, relative to the component's scene object.
  37. /// </summary>
  38. public Vector3 Center
  39. {
  40. get { return serializableData.localPosition; }
  41. set
  42. {
  43. if (serializableData.localPosition == value)
  44. return;
  45. serializableData.localPosition = value;
  46. if (Native != null)
  47. UpdateTransform();
  48. }
  49. }
  50. /// <summary>
  51. /// Returns the native sphere collider wrapped by this component.
  52. /// </summary>
  53. private NativeSphereCollider Native
  54. {
  55. get { return (NativeSphereCollider)native; }
  56. }
  57. /// <inheritdoc/>
  58. internal override NativeCollider CreateCollider()
  59. {
  60. NativeSphereCollider sphereCollider = new NativeSphereCollider();
  61. sphereCollider.Radius = radius;
  62. return sphereCollider;
  63. }
  64. }
  65. /** @} */
  66. }