/// <summary> /// Changes the rigidbody parent of the collider. Meant to be called from the Rigidbody itself. /// </summary> /// <param name="rigidbody">New rigidbody to assign as the parent to the collider.</param> /// <param name="isInternal">If true the rigidbody will just be changed internally, but parent rigidbody will not be /// notified.</param> internal void SetRigidbody(Rigidbody rigidbody, bool isInternal = false) { if (rigidbody == parent) { return; } if (native != null && !isInternal) { if (parent != null) { parent.RemoveCollider(this); } NativeRigidbody nativeRigidbody = null; if (rigidbody != null) { nativeRigidbody = rigidbody.native; } native.Rigidbody = nativeRigidbody; if (rigidbody != null) { rigidbody.AddCollider(this); } } parent = rigidbody; UpdateCollisionReportMode(); }
/// <summary> /// Creates the internal representation of the Joint and restores the values saved by the Component. /// </summary> private void RestoreNative() { // Make sure to always create a new instance of this array, as IntPtrs don't get serialized [email protected] = new [] { IntPtr.Zero, IntPtr.Zero }; if (commonData.bodies[0] != null) { NativeRigidbody nativeBody = commonData.bodies[0].native; if (nativeBody != null) { [email protected][0] = nativeBody.GetCachedPtr(); } } if (commonData.bodies[1] != null) { NativeRigidbody nativeBody = commonData.bodies[1].native; if (nativeBody != null) { [email protected][1] = nativeBody.GetCachedPtr(); } } GetLocalTransform(JointBody.Target, out [email protected][0], out [email protected][0]); GetLocalTransform(JointBody.Anchor, out [email protected][1], out [email protected][1]); native = CreateNative(); native.Component = this; }
/// <summary> /// Destroys the internal rigidbody representation. /// </summary> private void DestroyNative() { ClearColliders(); if (native != null) { native.Destroy(); native = null; } }
/// <summary> /// Restores internal rigidbody representation and assigns it the properties stored by the component. /// </summary> private void RestoreNative() { native = new NativeRigidbody(SceneObject); native.Component = this; UpdateColliders(); #if DEBUG CheckForNestedRigibody(); #endif native.Position = SceneObject.Position; native.Rotation = SceneObject.Rotation; // Note: Merge into one call to avoid many virtual function calls native.PositionSolverCount = serializableData.positionSolverCount; native.VelocitySolverCount = serializableData.velocitySolverCount; native.MaxAngularVelocity = serializableData.maxAngularVelocity; native.Drag = serializableData.linearDrag;; native.AngularDrag = serializableData.angularDrag; native.SleepThreshold = serializableData.sleepThreshold; native.UseGravity = serializableData.useGravity; native.Kinematic = serializableData.isKinematic; native.Flags = serializableData.flags; if ((serializableData.flags & RigidbodyFlag.AutoTensors) == 0) { native.CenterOfMassPosition = serializableData.centerMassPosition; native.CenterOfMassRotation = serializableData.centerMassRotation; native.InertiaTensor = serializableData.inertiaTensor; native.Mass = serializableData.mass; } else { if ((serializableData.flags & RigidbodyFlag.AutoMass) == 0) { native.Mass = serializableData.mass; } native.UpdateMassDistribution(); } }
private static extern void Internal_CreateInstance(NativeRigidbody instance, IntPtr linkedSO);
/// <summary> /// Restores internal rigidbody representation and assigns it the properties stored by the component. /// </summary> private void RestoreNative() { native = new NativeRigidbody(SceneObject); native.Component = this; UpdateColliders(); #if DEBUG CheckForNestedRigibody(); #endif native.Position = SceneObject.Position; native.Rotation = SceneObject.Rotation; // Note: Merge into one call to avoid many virtual function calls native.PositionSolverCount = serializableData.positionSolverCount; native.VelocitySolverCount = serializableData.velocitySolverCount; native.MaxAngularVelocity = serializableData.maxAngularVelocity; native.Drag = serializableData.linearDrag;; native.AngularDrag = serializableData.angularDrag; native.SleepThreshold = serializableData.sleepThreshold; native.UseGravity = serializableData.useGravity; native.Kinematic = serializableData.isKinematic; native.Flags = serializableData.flags; if ((serializableData.flags & RigidbodyFlag.AutoTensors) == 0) { native.CenterOfMassPosition = serializableData.centerMassPosition; native.CenterOfMassRotation = serializableData.centerMassRotation; native.InertiaTensor = serializableData.inertiaTensor; native.Mass = serializableData.mass; } else { if ((serializableData.flags & RigidbodyFlag.AutoMass) == 0) native.Mass = serializableData.mass; native.UpdateMassDistribution(); } }