예제 #1
0
        /// <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();
        }
예제 #2
0
        /// <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;
        }
예제 #3
0
        /// <summary>
        /// Destroys the internal rigidbody representation.
        /// </summary>
        private void DestroyNative()
        {
            ClearColliders();

            if (native != null)
            {
                native.Destroy();
                native = null;
            }
        }
예제 #4
0
        /// <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();
            }
        }
예제 #5
0
 private static extern void Internal_CreateInstance(NativeRigidbody instance, IntPtr linkedSO);
예제 #6
0
 private static extern void Internal_CreateInstance(NativeRigidbody instance, IntPtr linkedSO);
예제 #7
0
        /// <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();
            }
        }
예제 #8
0
        /// <summary>
        /// Destroys the internal rigidbody representation.
        /// </summary>
        private void DestroyNative()
        {
            ClearColliders();

            if (native != null)
            {
                native.Destroy();
                native = null;
            }
        }