void OnChanged(ChangedFlags flags)
        {
            if (collisionEntity == null)
            {
                return;
            }

            if (flags.HasFlag(ChangedFlags.PhysicsSettings))
            {
                var rigidBody = GetComponent <Rigidbody>();
                if (rigidBody && !rigidBody.isKinematic)
                {
                    collisionEntity.BecomeDynamic(rigidBody.mass);
                    collisionEntity.IsAffectedByGravity = rigidBody.useGravity;

                    /*collisionEntity.AngularVelocity = rigidBody.angularVelocity;
                     * collisionEntity.LinearVelocity = rigidBody.velocity;*/
                    collisionEntity.Mass = rigidBody.mass;
                }
                else
                {
                    collisionEntity.BecomeKinematic();
                    collisionEntity.IsAffectedByGravity = false;
                    collisionEntity.AngularVelocity     = Vector3.Zero;
                    collisionEntity.LinearVelocity      = Vector3.Zero;
                }
            }

            if (flags.HasFlag(ChangedFlags.Position) || flags.HasFlag(ChangedFlags.PhysicalShape))
            {
                collisionEntity.Position = transform.position + center.RotateBy(transform.rotation);
            }
            if (flags.HasFlag(ChangedFlags.Roltation))
            {
                collisionEntity.Orientation = transform.rotation;
            }

            if (flags.HasFlag(ChangedFlags.Scale))
            {
                var s = size * transform.scale * 2;
                collisionEntity.Width  = s.X;
                collisionEntity.Height = s.Y;
                collisionEntity.Length = s.Z;
            }

            /*if (representsMeshBounds && flags.HasFlag(ChangedFlags.Bounds))
             * {
             *  var renderer = gameObject.GetComponent<MeshRenderer>();
             *  if (renderer)
             *  {
             *      center = renderer.mesh.bounds.center;
             *      size = renderer.mesh.bounds.extents;
             *      representsMeshBounds = true;
             *
             *      var s = size * transform.scale;
             *
             *      collisionEntity = new BEPUphysics.Entities.Prefabs.Box(transform.position + center.RotateBy(transform.rotation), s.X, s.Y, s.Z);
             *  }
             * }*/
        }
Exemple #2
0
 internal void RaiseOnChanged(ChangedFlags flags)
 {
     if (OnChanged != null)
     {
         OnChanged(flags);
     }
 }
Exemple #3
0
 void OnMeshHasChanges(ChangedFlags flags)
 {
     gameObject.RaiseOnChanged(flags);
 }
 public ChangedEvent(ChangedFlags flags)
 {
     Flags = flags;
 }
Exemple #5
0
 public void UpdateCommand(ChangedFlags changed)
 {
     this.ChangedParameters |= changed;
     this.ChangedParameters &= ~ChangedFlags.Saved;
 }