NativeJoint.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using System.Runtime.CompilerServices;
  5. namespace BansheeEngine
  6. {
  7. /// <summary>
  8. /// Wrapper around the native Joint class.
  9. /// <see cref="Joint"/>
  10. /// </summary>
  11. internal class NativeJoint : ScriptObject
  12. {
  13. private Joint component;
  14. /// <summary>
  15. /// Component that owns the native joint object.
  16. /// </summary>
  17. public Joint Component
  18. {
  19. get { return component; }
  20. set { component = value; }
  21. }
  22. public float BreakForce
  23. {
  24. set { Internal_SetBreakForce(mCachedPtr, value); }
  25. }
  26. public float BreakTorque
  27. {
  28. set { Internal_SetBreakTorque(mCachedPtr, value); }
  29. }
  30. public bool EnableCollision
  31. {
  32. set { Internal_SetEnableCollision(mCachedPtr, value); }
  33. }
  34. public void SetRigidbody(JointBody body, Rigidbody rigidbody)
  35. {
  36. IntPtr rigidbodyPtr = IntPtr.Zero;
  37. if (rigidbody != null)
  38. rigidbodyPtr = rigidbody.native.GetCachedPtr();
  39. Internal_SetBody(mCachedPtr, body, rigidbodyPtr);
  40. }
  41. public void SetPosition(JointBody body, Vector3 position)
  42. {
  43. Internal_SetPosition(mCachedPtr, body, ref position);
  44. }
  45. public void SetRotation(JointBody body, Quaternion rotation)
  46. {
  47. Internal_SetRotation(mCachedPtr, body, ref rotation);
  48. }
  49. public void Destroy()
  50. {
  51. Internal_Destroy(mCachedPtr);
  52. }
  53. private void Internal_DoOnJointBreak()
  54. {
  55. Component.DoOnJointBreak();
  56. }
  57. [MethodImpl(MethodImplOptions.InternalCall)]
  58. private static extern void Internal_Destroy(IntPtr thisPtr);
  59. [MethodImpl(MethodImplOptions.InternalCall)]
  60. private static extern void Internal_SetBody(IntPtr thisPtr, JointBody body, IntPtr rigidbody);
  61. [MethodImpl(MethodImplOptions.InternalCall)]
  62. private static extern void Internal_SetPosition(IntPtr thisPtr, JointBody body, ref Vector3 position);
  63. [MethodImpl(MethodImplOptions.InternalCall)]
  64. private static extern void Internal_SetRotation(IntPtr thisPtr, JointBody body, ref Quaternion rotation);
  65. [MethodImpl(MethodImplOptions.InternalCall)]
  66. private static extern void Internal_SetBreakForce(IntPtr thisPtr, float force);
  67. [MethodImpl(MethodImplOptions.InternalCall)]
  68. private static extern void Internal_SetBreakTorque(IntPtr thisPtr, float torque);
  69. [MethodImpl(MethodImplOptions.InternalCall)]
  70. private static extern void Internal_SetEnableCollision(IntPtr thisPtr, bool value);
  71. }
  72. }