SphereCollider.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 sphere geometry.
  7. /// </summary>
  8. public sealed class SphereCollider : Collider
  9. {
  10. [SerializeField]
  11. private float radius;
  12. /// <summary>
  13. /// Radius of the sphere.
  14. /// </summary>
  15. public float Radius
  16. {
  17. get { return radius; }
  18. set
  19. {
  20. if (radius == value)
  21. return;
  22. radius = value;
  23. if (Native != null)
  24. {
  25. Native.Radius = value;
  26. if (parent != null)
  27. parent.UpdateMassDistribution();
  28. }
  29. }
  30. }
  31. /// <summary>
  32. /// Position of the sphere 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 sphere collider wrapped by this component.
  48. /// </summary>
  49. private NativeSphereCollider Native
  50. {
  51. get { return (NativeSphereCollider)native; }
  52. }
  53. /// <inheritdoc/>
  54. internal override NativeCollider CreateCollider()
  55. {
  56. NativeSphereCollider sphereCollider = new NativeSphereCollider();
  57. sphereCollider.Radius = radius;
  58. return sphereCollider;
  59. }
  60. }
  61. }