private void HandleDown(GameObject downObject) { if (touchedObj == null) { return; // not possible but just double check } // if haven't grab anything && not in stretch mode if (!grabSomething && !inStretchMode) { // if already been grabbed if (m_CurrentInteractible.IsGrabbing) { // enter stretch mode! inStretchMode = true; stretchObj = touchedObj; originalScale = stretchObj.transform.localScale; initialControllersDistance = (attachPoint.position - m_CurrentInteractible.CurrentGrabbedPoint()).sqrMagnitude; Debug.Log(gameObject.name + "starts stretching!"); DeviceVibrate(); } else { // be grabbed! m_CurrentInteractible.Down(gameObject); m_CurrentInteractible.grabbedPoint = attachPoint.position; // Grab in PHYSICS way if has rigidbody if (objHasRigidbody) { // disable the kinematic (if it is) so can be controlled by joint if (objIsKinematic) { touchedObj.GetComponent <Rigidbody> ().isKinematic = false; } // add fixed joint joint = touchedObj.AddComponent <FixedJoint> (); joint.connectedBody = attachPoint; } else // or NON-PHYSICS(hierarchy way) { touchedObj.transform.parent = gameObject.transform; } grabSomething = true; Debug.Log(gameObject.name + " grabs!"); DeviceVibrate(); } } }
public void HandleTriggerDown(object sender, ClickedEventArgs e) //public void HandleTriggerDown(GameObject sender) { // if(m_inSelfScalingMode && otherController.InSelfScalingSupportMode) // { // originalScale = player.localScale; // initialControllersDistance = (attachPoint.position - otherController.attachPoint.position).sqrMagnitude; // return; // } if (!inUse) { return; } else { hand.OnDown(); } if (touchedObj == null) { return; // not possible but just double check } // if haven't grab anything && not in stretch mode if (!grabSomething && !inStretchMode) { // if already been grabbed if (m_CurrentInteractible.IsGrabbing) { // enter stretch mode! inStretchMode = true; stretchObj = touchedObj; originalScale = stretchObj.transform.localScale; initialControllersDistance = (attachPoint.position - m_CurrentInteractible.GrabbedPos).sqrMagnitude; //Debug.Log (gameObject.name + "starts stretching!"); DeviceVibrate(); // remote the joint attached to other controller if (m_CurrentInteractible.Joint) { stretchObj.GetComponent <Rigidbody> ().isKinematic = true; m_CurrentInteractible.RemoveJoint(); } } else { // be grabbed! m_CurrentInteractible.Down(gameObject); m_CurrentInteractible.grabbedPoint = attachPoint.position; // Grab in PHYSICS way if has rigidbody if (m_CurrentInteractible.TheRigidbody) //if (m_CurrentInteractible.HasRigidbody) { Debug.Log("to grab r_body"); // set the kinematic false (if it is) so can be controlled by joint if (m_CurrentInteractible.IsKinematic) { Debug.Log("to grab IsKinematic"); m_CurrentInteractible.IsKinematic = false; } Debug.Log("add joint"); // add fixed joint m_CurrentInteractible.AddJoint(attachPoint); } else // or NON-PHYSICS(hierarchy way) { stickerParent = touchedObj.transform.parent; touchedObj.transform.parent = gameObject.transform; } grabSomething = true; DeviceVibrate(); } } }