private void GrabObject(Collider other) { if (_objectInfo == null) { return; } VRTK_InteractGrab grab = (other.GetComponent <VRTK_InteractGrab>() ? other.GetComponent <VRTK_InteractGrab>() : other.GetComponentInParent <VRTK_InteractGrab>()); if (grab && grab.GetGrabbedObject() == null && grab.gameObject.GetComponent <VRTK_ControllerEvents>().grabPressed&& Time.time >= _grabTimer) { string Name = _objectInfo.EnglishName; VRTK_InteractTouch touch = grab.gameObject.GetComponent <VRTK_InteractTouch>(); GameObject prefab = Instantiate(Resources.Load <GameObject>("Prefabs/LabObjects/" + Name), null, false); if (prefab == null) { Debug.LogError("The labObjects of name: " + Name + " is null!"); return; } touch.ForceTouch(prefab); grab.AttemptGrab(); _grabTimer = Time.time + _grabDelay; } }
private GameObject SpawnInHand(GameObject go) { if (m_InteractGrab.GetGrabbedObject() != null) { m_InteractGrab.ForceRelease(); } //if (m_SpawnObject != null & m_IsClearSpawnObject == true) //{ // Destroy(m_SpawnObject); //} m_SpawnObject = Instantiate(go); VRTK_InteractableObject interactableObject = m_SpawnObject.GetComponent <VRTK_InteractableObject>(); interactableObject = interactableObject? interactableObject: m_SpawnObject.GetComponentInChildren <VRTK_InteractableObject>(); //m_IsClearSpawnObject = true; if (interactableObject.isGrabbable && !interactableObject.IsGrabbed()) { m_SpawnObject.transform.position = m_Grabpoint.transform.position; m_InteractTouch.ForceTouch(interactableObject.gameObject); m_InteractGrab.AttemptGrab(); } return(m_SpawnObject); }
private IEnumerator SwapToObjectSequence() { _isSnappingToHand = false; _isSnappedToHand = true; _proxy.SetActive(false); _actualObject.gameObject.SetActive(true); for (int i = 0; i < _actualObjectInteractables.Length; i++) { _actualObjectInteractables[i].InteractableObjectUngrabbed += HandleObjectDropped; } _bookImageCollider.enabled = false; _actualObject.transform.position = _proxy.transform.position; _actualObject.transform.rotation = _proxy.transform.rotation; _actualObject.transform.SetParent(null); VRTK_InteractTouch touch = _controllerReference.actual.GetComponentInChildren <VRTK_InteractTouch>(); VRTK_InteractGrab grab = _controllerReference.actual.GetComponentInChildren <VRTK_InteractGrab>(); if (_actualObjectInteractables.Length > 0) { touch.ForceTouch(_actualObjectInteractables[0].gameObject); } grab.ForceRelease(); yield return(null); grab.AttemptGrab(); }
private IEnumerator ForceGrab() { yield return(null); if (touch && grab) { GameObject matchStick = Instantiate(Resources.Load <GameObject>("Prefabs/MatchStic")); touch.ForceStopTouching(); grab.ForceRelease(); touch.ForceTouch(matchStick); grab.AttemptGrab(); } }
public void TryAutoGrab() { if (gs.autoGrab) { if (interactTouch.GetTouchedObject() == null) { Block block = BlockManager.AutoGrabBlock(); block.transform.SetPositionAndRotation(transform.position, transform.rotation); interactTouch.ForceTouch(block.gameObject); interactGrab.AttemptGrab(); } } }
private void DoTriggerPressed(object sender, ControllerInteractionEventArgs e) { if (CheckHasArrow() || CheckBowHasArrow()) { return; } else { GameObject newArrow = Instantiate(arrow); touch.ForceTouch(newArrow); grab.AttemptGrab(); use.AttemptUse(); } }
protected virtual void ReUseUndroppableObject() { if (undroppableUsedObject != null) { VRTK_InteractableObject undroppableUsedObjectScript = undroppableUsedObject.GetComponent <VRTK_InteractableObject>(); if (interactTongTouch != null && undroppableUsedObjectScript != null && !undroppableUsedObjectScript.IsGrabbed()) { undroppableUsedObject.SetActive(true); interactTongTouch.ForceTouch(undroppableUsedObject); AttemptGrab(); } } else { undroppableUsedObject = null; } }
void TouchNearestObject() { GameObject nearestObject = mrs.CalculateNearestTouchPoint(this.transform); //if (nearestObject.name.Equals("Control Ball")) //{ // controlBallTouched = true; //} //else //{ // controlBallTouched = false; //} if (nearestObject != null) { VRTK_InteractTouch IT = this.transform.GetChild(1).GetComponent <VRTK_InteractTouch>(); IT.ForceTouch(nearestObject); } }
void Grab(bool isRightHand, GameObject prefab, bool isShowHeadQuiver) { DebugConsole.instance.ShowColliderHeadQuiver(isShowHeadQuiver); bool dropped = Drop(isRightHand, prefab); if (!dropped) { return; } GameObject weapon = Instantiate(prefab); if (isRightHand) { RightHandTouch.ForceTouch(weapon); RightHandGrab.AttemptGrab(); } else { LeftHandTouch.ForceTouch(weapon); LeftHandGrab.AttemptGrab(); } }
public override void Grabbed(GameObject grabbingObject) { VRTK_InteractGrab grabScript = grabbingObject.GetComponent <VRTK_InteractGrab>(); VRTK_InteractTouch touchScript = grabbingObject.GetComponent <VRTK_InteractTouch>(); VRTK_ControllerActions controllerActions = grabbingObject.GetComponent <VRTK_ControllerActions>(); grabScript.ForceRelease(); bool isRightController = grabbingObject.name.Contains("right"); if (!alwaysUseSlider && (alwaysUseStatic || attachPtCount >= staticAttachPtCount)) { //print("making static joint"); staticAttachPtCount++; GameObject zbAttachPoint = Instantiate(StaticAttachPoint_PF); GameObject attachPoint = zbAttachPoint.transform.GetChild(0).gameObject; foreach (ZB_PaddleBlade paddle in paddleBlades) { if (alwaysUseSlider) { paddle.mainControlActions = controllerActions; } else { paddle.secondaryControlActions = controllerActions; paddle.ForcePoint = attachPoint.gameObject; } } ZB_AttachPoint attachPointScript = attachPoint.GetComponent <ZB_AttachPoint>(); Transform spawnPoint = (grabScript && grabScript.controllerAttachPoint) ? grabScript.controllerAttachPoint.transform: grabbingObject.transform; //Transform spawnPoint = grabbingObject.transform.GetChild(0).transform.GetChild(1).GetChild(0).transform; if (isRightController) { rightSnapHandle = attachPoint.transform.GetChild(0).transform; } else { leftSnapHandle = attachPoint.transform.GetChild(0).transform; } attachPointScript.spawningObj = this; touchScript.ForceStopTouching(); touchScript.ForceTouch(attachPoint.gameObject); zbAttachPoint.transform.position = spawnPoint.position; zbAttachPoint.transform.rotation = transform.rotation; float attachPtLocalY = transform.InverseTransformPoint(zbAttachPoint.transform.position).y; Vector3 zeroPos = transform.TransformPoint(new Vector3(0f, attachPtLocalY, 0f)); zbAttachPoint.transform.position = zeroPos; ConfigurableJoint attachPtJoint = attachPoint.GetComponent <ConfigurableJoint>(); //sliderJoint.connectedBody = rBody; attachPtJoint.connectedBody = rBody; SetStaticAttachPointJointRestraints(ref attachPtJoint); attachPtJoint.connectedBody = rBody; grabScript.AttemptGrab(); if (isRightController) { rightControlLocalY = attachPtLocalY; currRightControl = grabbingObject; if (alwaysUseSlider) { rightRotateTrack.follow = true; } attachPointScript.isRightController = true; currRightAttachPt = attachPointScript.gameObject; } else { leftControlLocalY = attachPtLocalY; currLeftControl = grabbingObject; if (alwaysUseSlider) { leftRotateTrack.follow = true; } attachPointScript.isRightController = false; currLeftAttachPt = attachPointScript.gameObject; } } else { //print("making slider joint"); attachPtCount++; foreach (ZB_PaddleBlade paddleBlade in paddleBlades) { paddleBlade.mainControlActions = controllerActions; } GameObject zbAttachPoint = Instantiate(AttachPoint_PF); GameObject attachPoint = zbAttachPoint.transform.GetChild(0).gameObject; GameObject slider = zbAttachPoint.transform.GetChild(1).gameObject; ZB_AttachPoint attachPointScript = attachPoint.GetComponent <ZB_AttachPoint>(); Transform spawnPoint = (grabScript && grabScript.controllerAttachPoint) ? grabScript.controllerAttachPoint.transform : grabbingObject.transform; if (isRightController) { rightSnapHandle = attachPoint.transform.GetChild(0).transform; } else { leftSnapHandle = attachPoint.transform.GetChild(0).transform; } attachPointScript.spawningObj = this; touchScript.ForceStopTouching(); touchScript.ForceTouch(attachPoint.gameObject); zbAttachPoint.transform.position = spawnPoint.position; zbAttachPoint.transform.rotation = transform.rotation; float attachPtLocalY = transform.InverseTransformPoint(zbAttachPoint.transform.position).y; Vector3 zeroPos = transform.TransformPoint(new Vector3(0f, attachPtLocalY, 0f)); zbAttachPoint.transform.position = zeroPos; ConfigurableJoint sliderJoint = slider.GetComponent <ConfigurableJoint>(); ConfigurableJoint attachPtJoint = attachPoint.GetComponent <ConfigurableJoint>(); attachPtJoint.connectedBody = rBody; SetStaticAttachPointJointRestraints(ref attachPtJoint); SetSliderJointRestraints(ref sliderJoint); attachPtJoint.connectedBody = rBody; sliderJoint.connectedBody = rBody; grabScript.AttemptGrab(); if (isRightController) { rightControlLocalY = attachPtLocalY; currRightControl = grabbingObject; rightRotateTrack.follow = true; attachPointScript.isRightController = true; currRightAttachPt = attachPointScript.gameObject; } else { leftControlLocalY = attachPtLocalY; currLeftControl = grabbingObject; leftRotateTrack.follow = false; attachPointScript.isRightController = false; currLeftAttachPt = attachPointScript.gameObject; } StartCoroutine(DelayedJointConnect(attachPtJoint, slider.GetComponent <Rigidbody>())); } }
public void GrabWeapon(GameObject weapon) { print("GRAB"); RightHandTouch.ForceTouch(weapon); RightHandGrab.AttemptGrab(); }