예제 #1
0
        [Test] public void CloneJointRigidBodies()
        {
            // Create two joint bodies
            GameObject sourceA = new GameObject("ObjectA");
            GameObject sourceB = new GameObject("ObjectB", sourceA);

            sourceA.AddComponent <Transform>();
            sourceB.AddComponent <Transform>();
            RigidBody sourceBodyA = sourceA.AddComponent <RigidBody>();
            RigidBody sourceBodyB = sourceB.AddComponent <RigidBody>();

            sourceBodyA.AddJoint(new DistanceJointInfo(), sourceBodyB);

            // Are the two bodies joint together as expected?
            Assert.AreEqual(1, sourceBodyA.Joints.Count());
            Assert.AreSame(sourceBodyA.Joints.First().OtherBody, sourceBodyB);
            Assert.IsTrue(sourceBodyB.Joints == null || !sourceBodyB.Joints.Any());

            // Clone the object hierarchy
            GameObject targetA     = sourceA.DeepClone();
            GameObject targetB     = targetA.ChildAtIndex(0);
            RigidBody  targetBodyA = targetA.GetComponent <RigidBody>();
            RigidBody  targetBodyB = targetB.GetComponent <RigidBody>();

            // Is the cloned hierarchy joint together as expected?
            Assert.AreEqual(1, targetBodyA.Joints.Count());
            Assert.IsTrue(targetBodyB.Joints == null || !targetBodyB.Joints.Any());
            Assert.AreSame(targetBodyA.Joints.First().OtherBody, targetBodyB);
            Assert.AreNotSame(sourceBodyA.Joints.First(), targetBodyA.Joints.First());
        }
예제 #2
0
        public override void Undo()
        {
            if (this.backupParentObjA == null)
            {
                throw new InvalidOperationException("Can't undo what hasn't been done yet");
            }
            for (int i = 0; i < this.targetObj.Length; i++)
            {
                JointInfo joint   = this.targetObj[i];
                RigidBody parentA = this.backupParentObjA[i];
                RigidBody parentB = this.backupParentObjB[i];
                if (joint == null)
                {
                    continue;
                }

                if (parentA != null)
                {
                    parentA.AddJoint(joint, parentB);
                }
                else if (parentB != null)
                {
                    parentB.AddJoint(joint, parentA);
                }
            }
            var affectedBodies = this.targetParentObjA
                                 .Concat(this.targetParentObjB)
                                 .Concat(this.backupParentObjA)
                                 .Concat(this.backupParentObjB)
                                 .Distinct();

            DualityEditorApp.NotifyObjPropChanged(this, new ObjectSelection(affectedBodies), ReflectionInfo.Property_RigidBody_Joints);
        }
예제 #3
0
 public override void Do()
 {
     for (int i = 0; i < this.targetObj.Length; i++)
     {
         JointInfo joint  = this.targetObj[i];
         RigidBody parent = this.targetParentObj[i];
         if (joint == null)
         {
             continue;
         }
         if (parent == null)
         {
             continue;
         }
         parent.AddJoint(joint);
     }
     DualityEditorApp.NotifyObjPropChanged(this, new ObjectSelection(this.targetParentObj.Distinct()), ReflectionInfo.Property_RigidBody_Joints);
 }
예제 #4
0
        public override void Do()
        {
            if (this.backupParentObjA == null)
            {
                this.backupParentObjA = new RigidBody[this.targetObj.Length];
                this.backupParentObjB = new RigidBody[this.targetObj.Length];
                for (int i = 0; i < this.backupParentObjA.Length; i++)
                {
                    this.backupParentObjA[i] = this.targetObj[i].BodyA;
                    this.backupParentObjB[i] = this.targetObj[i].BodyB;
                }
            }

            for (int i = 0; i < this.targetObj.Length; i++)
            {
                JointInfo joint   = this.targetObj[i];
                RigidBody parentA = this.targetParentObjA[i];
                RigidBody parentB = this.targetParentObjB[i];
                if (joint == null)
                {
                    continue;
                }

                if (parentA != null)
                {
                    parentA.AddJoint(joint, parentB);
                }
                else if (parentB != null)
                {
                    parentB.AddJoint(joint, parentA);
                }
            }

            var affectedBodies = this.targetParentObjA
                                 .Concat(this.targetParentObjB)
                                 .Concat(this.backupParentObjA)
                                 .Concat(this.backupParentObjB)
                                 .Distinct();

            DualityEditorApp.NotifyObjPropChanged(this, new ObjectSelection(affectedBodies), ReflectionInfo.Property_RigidBody_Joints);
        }
예제 #5
0
        [Test] public void CloneJointRigidBodies()
        {
            // Create two joint bodies
            GameObject sourceA = new GameObject("ObjectA");
            GameObject sourceB = new GameObject("ObjectB", sourceA);

            sourceA.AddComponent <Transform>();
            sourceB.AddComponent <Transform>();
            RigidBody sourceBodyA = sourceA.AddComponent <RigidBody>();
            RigidBody sourceBodyB = sourceB.AddComponent <RigidBody>();

            sourceBodyA.AddJoint(new DistanceJointInfo(), sourceBodyB);

            // Are the two bodies joint together as expected?
            Assert.AreEqual(1, sourceBodyA.Joints.Count());
            Assert.AreSame(sourceBodyA.Joints.First().OtherBody, sourceBodyB);
            Assert.IsTrue(sourceBodyB.Joints == null || !sourceBodyB.Joints.Any());

            // Clone the object hierarchy
            GameObject targetA     = sourceA.DeepClone();
            GameObject targetB     = targetA.Children[0];
            RigidBody  targetBodyA = targetA.GetComponent <RigidBody>();
            RigidBody  targetBodyB = targetB.GetComponent <RigidBody>();

            // Is the cloned hierarchy joint together as expected?
            Assert.AreEqual(1, targetBodyA.Joints.Count());
            Assert.IsTrue(targetBodyB.Joints == null || !targetBodyB.Joints.Any());
            Assert.AreSame(targetBodyA.Joints.First().OtherBody, targetBodyB);
            Assert.AreNotSame(sourceBodyA.Joints.First(), targetBodyA.Joints.First());

            // Clone only the source joint, but not any body
            JointInfo isolatedSourceJoint = sourceBodyA.Joints.FirstOrDefault();
            JointInfo isolatedTargetJoint = isolatedSourceJoint.DeepClone();

            // Is the cloned joint still isolated, and not attached to any body?
            Assert.IsNotNull(isolatedSourceJoint.ParentBody);
            Assert.IsNotNull(isolatedSourceJoint.OtherBody);
            Assert.IsNull(isolatedTargetJoint.ParentBody);
            Assert.IsNull(isolatedTargetJoint.OtherBody);
            Assert.AreEqual(1, sourceBodyA.Joints.Count());
        }
예제 #6
0
        public override void Do()
        {
            if (this.backupParentBody == null)
            {
                this.backupParentBody = new RigidBody[this.targetObj.Length];
                this.backupOtherBody  = new RigidBody[this.targetObj.Length];
                for (int i = 0; i < this.backupParentBody.Length; i++)
                {
                    this.backupParentBody[i] = this.targetObj[i].ParentBody;
                    this.backupOtherBody[i]  = this.targetObj[i].OtherBody;
                }
            }

            for (int i = 0; i < this.targetObj.Length; i++)
            {
                JointInfo joint      = this.targetObj[i];
                RigidBody parentBody = this.targetParentBody[i];
                RigidBody otherBody  = this.targetOtherBody[i];
                if (joint == null)
                {
                    continue;
                }

                if (parentBody != null)
                {
                    parentBody.AddJoint(joint, otherBody);
                }
                else if (otherBody != null)
                {
                    otherBody.AddJoint(joint, parentBody);
                }
            }

            var affectedBodies = this.targetParentBody
                                 .Concat(this.targetOtherBody)
                                 .Concat(this.backupParentBody)
                                 .Concat(this.backupOtherBody)
                                 .Distinct();

            DualityEditorApp.NotifyObjPropChanged(this, new ObjectSelection(affectedBodies), ReflectionInfo.Property_RigidBody_Joints);
        }
 public override void Undo()
 {
     if (this.backupParentObjA == null)
     {
         throw new InvalidOperationException("Can't undo what hasn't been done yet");
     }
     for (int i = 0; i < this.backupParentObjA.Length; i++)
     {
         RigidBody bodyA = this.backupParentObjA[i];
         RigidBody bodyB = this.backupParentObjB[i];
         if (bodyA != null)
         {
             bodyA.AddJoint(this.targetObj[i], bodyB);
         }
         else if (bodyB != null)
         {
             bodyB.AddJoint(this.targetObj[i], bodyA);
         }
     }
     DualityEditorApp.NotifyObjPropChanged(this, new ObjectSelection(this.backupParentObjA.Concat(this.backupParentObjB).Distinct()), ReflectionInfo.Property_RigidBody_Joints);
 }
        private void SetupFrictionJoint(RigidBody body)
        {
            // If we already have a friction joint, is it connecting the right bodies?
            if (this.frictionJoint != null)
            {
                if (this.frictionJoint.ParentBody != body ||
                    this.frictionJoint.ParentBody != this.baseObject)
                {
                    this.frictionJoint.ParentBody.RemoveJoint(this.frictionJoint);
                    this.frictionJoint = null;
                }
            }

            // Create a friction joint connecting our body to the body it is standing on
            if (this.frictionJoint == null)
            {
                this.frictionJoint = new FrictionJointInfo();
                this.frictionJoint.CollideConnected = true;
                this.frictionJoint.MaxTorque        = 0.0f;
                body.AddJoint(this.frictionJoint, this.baseObject);
            }
        }