示例#1
0
 void HandleGrabbing(bool grabInput, ref bool canThrow, Transform handTrs, PhysicsObject[] touchingPhysicsObjects, ref PhysicsObject grabbedPhysicsObject, PhysicsObject otherGrabbedPhysicsObject, Vector3 previousHandPosition, Vector3 previousHandEulerAngles)
 {
     if (grabInput)
     {
         if (canThrow)
         {
             if (grabbedPhysicsObject == null)
             {
                 for (int i = 0; i < touchingPhysicsObjects.Length; i++)
                 {
                     PhysicsObject physicsObject = touchingPhysicsObjects[i];
                     if (physicsObject.isGrabbable && physicsObject != grabbedPhysicsObject && physicsObject != otherGrabbedPhysicsObject)
                     {
                         StopCoroutine(UnignoreCollisionDelayRoutine(physicsObject.collider));
                         IgnoreCollision(physicsObject.collider, true);
                         physicsObject.trs.SetParent(handTrs);
                         grabbedPhysicsObject = physicsObject;
                         SetGrabPosition(grabbedPhysicsObject);
                         grabbedPhysicsObject.rigid.isKinematic = true;
                         Orb orb = physicsObject.GetComponent <Orb>();
                         if (orb != null && Level.Instance.orbs.Length == 2)
                         {
                             if ((orb == Level.instance.orbs[0]) == (handTrs == leftHandTrs))
                             {
                                 Level.instance.leftOrb  = orb;
                                 Level.instance.rightOrb = Level.instance.orbs[1];
                             }
                             else
                             {
                                 Level.instance.leftOrb  = Level.instance.orbs[1];
                                 Level.instance.rightOrb = orb;
                             }
                         }
                     }
                 }
             }
             else
             {
                 if (grabbedPhysicsObject.trs.parent == handTrs)
                 {
                     SetGrabPosition(grabbedPhysicsObject);
                 }
                 else
                 {
                     StopCoroutine(UnignoreCollisionDelayRoutine(grabbedPhysicsObject.collider));
                     StartCoroutine(UnignoreCollisionDelayRoutine(grabbedPhysicsObject.collider));
                     grabbedPhysicsObject.rigid.isKinematic = false;
                     grabbedPhysicsObject = null;
                 }
             }
         }
     }
     else
     {
         canThrow = true;
         if (grabbedPhysicsObject != null)
         {
             if (grabbedPhysicsObject.trs.parent == handTrs)
             {
                 grabbedPhysicsObject.trs.SetParent(null);
                 grabbedPhysicsObject.trs.position          = trs.position + GameCamera.Instance.trs.forward.SetY(0).normalized *grabbedPhysicsObjectDropDistance;
                 grabbedPhysicsObject.rigid.velocity        = (handTrs.position - previousHandPosition) / Time.deltaTime;
                 grabbedPhysicsObject.rigid.angularVelocity = QuaternionExtensions.GetAngularVelocity(Quaternion.Euler(previousHandEulerAngles), handTrs.rotation);
             }
             StopCoroutine(UnignoreCollisionDelayRoutine(grabbedPhysicsObject.collider));
             StartCoroutine(UnignoreCollisionDelayRoutine(grabbedPhysicsObject.collider));
             grabbedPhysicsObject.rigid.isKinematic = false;
             grabbedPhysicsObject = null;
         }
     }
 }