private Transform FindClosestSnapTransform(CustomGrabber cg) { Transform closest = null; float distance = 0f; foreach (Transform t in snapTransforms) { if (snapTransformsTaken[t]) { continue; } if (closest == null) { closest = t; distance = Vector3.Distance(cg.grabDestination.position, t.position); } float tempDist = Vector3.Distance(cg.grabDestination.position, t.position); if (tempDist < distance) { closest = t; distance = tempDist; } } return(closest); }
public void GrabEnd(CustomGrabber cg, Vector3 linearVelocity, Vector3 angularVelocity) { if (m_debugText) { m_debugText.text = "GRAB END"; } RemoveController(cg); //if (m_debugText) m_debugText.text += " | RESETTING LAYERS"; this.gameObject.layer = m_originalLayer; Transform[] children = this.GetComponentsInChildren <Transform>(); foreach (Transform c in children) { //if (m_debugText) m_debugText.text += "Reset layer for " + c.name + " "; c.gameObject.layer = m_childrenOriginalLayers[c.gameObject.GetInstanceID()]; } //if (m_debugText) m_debugText.text += " | " + (originalParent == null).ToString(); if (shouldSetParent) { //if (m_debugText) m_debugText.text += " | RESETTING PARENT"; transform.SetParent(originalParent, true); } else { //if (m_debugText) m_debugText.text += " | NULL PARENT RESET"; } if (grabbers.Count == 0) { m_RigidBody.isKinematic = m_grabbedKinematic; m_RigidBody.velocity = linearVelocity; m_RigidBody.angularVelocity = angularVelocity; } }
public void Init(bool canStart = false, CustomGrabber grabber = null) { m_LineRenderer = this.GetComponent <LineRenderer>(); if (m_raycastOrigin == null) { m_raycastOrigin = this.transform; } m_grabber = grabber; m_raycastDownwardDistance = m_raycastDistance; layerMaskHover = 1 << LayerMask.NameToLayer("AvoidHover"); layerMaskHover = ~layerMaskHover; layerMaskLocomotion = 1 << LayerMask.NameToLayer("Locomotion"); layerMaskLocomotion = ~layerMaskLocomotion; combinedLayerMask = layerMaskHover | layerMaskLocomotion; m_LineRenderer.positionCount = m_numPoints; ResizeVolumeDetectors(); SetDebugMode(m_debugMode); if (canStart) { Activate(); } }
public void AddGrabber(CustomGrabber cg, Transform to) { /* * // We add this grabber to our list of grabbers * grabbers.Add(cg); * heldBy.Add(cg, to); * * if (m_debugText) m_debugText.text = "Hand Being Added"; * * // Set the hint0 since this is a new hand that's grabbing this. This is set whenever we grab or let go of an object. * h0 = cg.transform.position + Vector3.forward; * rot = this.transform.rotation; * //posDiff = transform.InverseTransformPoint(transform.position) - transform.InverseTransformPoint(cg.grabDestination.position); * posDiff = cg.grabDestination.position - transform.position; * rotDiff = Quaternion.Inverse(cg.grabDestination.rotation * transform.rotation); * currentGrabber = cg; * * // We need to assign the hands based on if they're left or right * switch(cg.OVRController) { * case (OVRInput.Controller.LTouch): * m_leftHand = cg; // Save hand to left hand reference * //if (m_debugText) m_debugText.text = "Left Hand Set: " + (m_leftHand != null).ToString(); * l0 = m_leftHand.transform.position; // Get the initial hand position, save it * if (m_rightHand == null) { * // now we're in the situation that this is the first grabber touching and holding this object. We need to initially assign some variables. * // mainly that if we're not grabbing the right hand, then obviously we need our left hand as our r0 reference * r0 = l0; * } * break; * case (OVRInput.Controller.RTouch): * m_rightHand = cg; * //if (m_debugText) m_debugText.text = "Right Hand Set: " + (m_rightHand != null).ToString(); * r0 = m_rightHand.transform.position; * if (m_leftHand == null) { * l0 = r0; * } * break; * } * * /* * // heldBy refers to the mapping between grabber and snap transform, even if it's null (because we don't have any snaps available) * heldBy.Add(cg, to); * // If we are passing a snap transform, we reserve it within snapTransformsTaken * if (to != null) { snapTransformsTaken[to] = true; } */ /* * if (grabbers.Count >= 1 && grabbers[0].shouldSnap) { * StopCoroutine(SnapToTransformProcess); * StartCoroutine(SnapToTransformProcess); * // SnapToTransform(); * } */ }
public bool GrabBegin(CustomGrabber g) { if (m_debugText) { m_debugText.text = "GRAB BEGIN"; } if (grabbers.Count >= numGrabbersAllowed) { // end early if we're not allowed to add this grabber due to total num of grabbers being achieved return(false); } // Set rigidbody mechanics... m_RigidBody.isKinematic = true; m_RigidBody.velocity = Vector3.zero; m_RigidBody.angularVelocity = Vector3.zero; // Set parent to the hand if (shouldSetParent) { transform.SetParent(g.transform, true); } m_rotationTime = 0f; // Add the "AvoidHover" layer to this to prevent hover effect this.gameObject.layer = LayerMask.NameToLayer("AvoidHover"); Transform[] children = this.GetComponentsInChildren <Transform>(); foreach (Transform c in children) { c.gameObject.layer = LayerMask.NameToLayer("AvoidHover"); } /* * // snapTransforms refers to the snap transformations that are attached to this object. * // If we have any snap transforms attached to this object, we need to find the closest one and orient the object to match the nsap transform * Transform snapTo = null; * if (snapTransforms.Count > 0) { snapTo = FindClosestSnapTransform(g); } * // We then continue with the add grabber script */ Transform snapTo = null; if (snapTransforms.Count > 0) { snapTo = FindClosestSnapTransform(g); } //AddGrabber(g, snapTo); AddGrabber(g, snapTo); // We return true to indicate that we can associate this object to being grabbed by whatever hand grabbed this. return(true); }
public void AddGrabber(CustomGrabber cg, Transform to) { grabbers.Add(cg); heldBy.Add(cg, to); if (to != null) { snapTransformsTaken[to] = true; } if (grabbers.Count == 1 && grabbers[0].shouldSnap) { SnapToTransform(); } }
public void GrabEnd(CustomGrabber cg, Vector3 linearVelocity, Vector3 angularVelocity) { RemoveController(cg); this.gameObject.layer = m_originalLayer; Transform[] children = this.GetComponentsInChildren <Transform>(); foreach (Transform c in children) { c.gameObject.layer = m_childrenOriginalLayers[c.gameObject.GetInstanceID()]; } if (grabbers.Count == 0) { m_RigidBody.isKinematic = m_grabbedKinematic; m_RigidBody.velocity = linearVelocity; m_RigidBody.angularVelocity = angularVelocity; } }
// Left controller prep - returns early private void PrepareLeft(CustomGrabber g) { if (g == null) { return; } m_leftHand = g; m_leftHand.Init(); if (m_trackingTime) { m_inputTimes.Add("left_index", -1f); m_inputTimes.Add("left_grip", -1f); m_inputTimes.Add("left_one", -1f); m_inputTimes.Add("left_two", -1f); m_inputTimes.Add("left_thumbDir", -1f); m_inputTimes.Add("left_thumbPress", -1f); m_inputTimes.Add("start", -1f); } m_inputDowns.Add("left_index", 0f); m_inputDowns.Add("left_grip", 0f); m_inputDowns.Add("left_one", 0f); m_inputDowns.Add("left_two", 0f); // m_inputDowns.Add("left_thumbNorth", 0f); // m_inputDowns.Add("left_thumbSouth", 0f); // m_inputDowns.Add("left_thumbEast", 0f); // m_inputDowns.Add("left_thumbWest", 0f); m_inputDowns.Add("left_thumbPress", 0f); m_inputTimes.Add("start", 0f); // Left Joystick m_thumbDirections.Add("left", Vector2.zero); m_thumbAngles.Add("left", Vector2.zero); // Grab object m_grabbedObjects.Add("left", null); // If there's a pointer... if (m_leftHand.pointer != null) { m_pointerTargets.Add("left", null); } }
private Transform FindClosestSnapTransform(CustomGrabber cg) { /* * Transform closest = null; * float distance = 0f; * foreach(Transform t in snapTransforms) { * if (snapTransformsTaken[t]) { continue; } * if (closest == null) { * closest = t; * distance = Vector3.Distance(cg.grabDestination.position, t.position); * } * float tempDist = Vector3.Distance(cg.grabDestination.position, t.position); * if (tempDist < distance) { * closest = t; * distance = tempDist; * } * } * return closest; */ return(null); }
public void GrabEnd(CustomGrabber cg, Vector3 linearVelocity, Vector3 angularVelocity) { Destroy(destinationObject); destinationObject = null; m_grabbers.Remove(cg); if (m_grabbers.Count >= 1) { CreatePseudoParent(); } else if (m_rigidbody != null) { m_rigidbody.isKinematic = m_originalKinematicSetting; m_rigidbody.detectCollisions = m_originalDetectCollisions; m_rigidbody.velocity = linearVelocity; m_rigidbody.angularVelocity = angularVelocity; } if (m_debugText != null) { m_debugText.text = "GRAB ENDED"; } return; }
public bool GrabBegin(CustomGrabber cg) { if (m_debugText != null) { m_debugText.text = "GRAB BEGAN"; } if (m_grabbers.Count >= m_numGrabbers || m_grabbers.Contains(cg)) { return(false); } m_grabbers.Add(cg); if (m_rigidbody != null) { m_rigidbody.isKinematic = m_shouldBeKinematic; m_rigidbody.detectCollisions = m_shouldDetectCollisions; } if (m_grabbers.Count == 1) { CreatePseudoParent(); } return(true); }
public void GrabBegin(CustomGrabber g) { if (grabbers.Count >= numGrabbersAllowed) { return; } m_RigidBody.isKinematic = true; m_RigidBody.velocity = Vector3.zero; m_RigidBody.angularVelocity = Vector3.zero; this.gameObject.layer = LayerMask.NameToLayer("AvoidHover"); Transform[] children = this.GetComponentsInChildren <Transform>(); foreach (Transform c in children) { c.gameObject.layer = LayerMask.NameToLayer("AvoidHover"); } Transform snapTo = null; if (snapTransforms.Count > 0) { snapTo = FindClosestSnapTransform(g); } AddGrabber(g, snapTo); }
public void RemoveController(CustomGrabber cg) { Transform t = null; if (heldBy.TryGetValue(cg, out t)) { if (t != null) { snapTransformsTaken[t] = false; } } heldBy.Remove(cg); int grabberIndex = grabbers.IndexOf(cg); if (grabberIndex > -1) { grabbers.RemoveAt(grabberIndex); } if (grabbers.Count > 0) { SnapToTransform(); } }
public void GrabbedChanged(CustomGrabber grabber, OVRInput.Controller c, CustomGrabbable cg) { onGrabbedChanged?.Invoke(grabber, c, cg); }
public void RemoveController(CustomGrabber cg) { //if (m_debugText) m_debugText.text += " | Removing Controller"; /* * Transform t = null; * if (heldBy.TryGetValue(cg, out t)) { * if (t != null) { snapTransformsTaken[t] = false; } * } * //StopCoroutine(SnapToTransformProcess); * heldBy.Remove(cg); */ /* * rot = this.transform.rotation; * heldBy.Remove(cg); * * switch(cg.OVRController) { * case(OVRInput.Controller.LTouch): * // We need to reset the l0 and h0 * m_leftHand = null; * l0 = Vector3.zero; * * if (m_rightHand == null) { * h0 = Vector3.zero; * r0 = Vector3.zero; * posDiff = Vector3.zero; * rotDiff = Quaternion.identity; * currentGrabber = null; * } else { * h0 = m_rightHand.transform.position + Vector3.forward; * l0 = m_rightHand.transform.position; * r0 = l0; * posDiff = m_rightHand.grabDestination.position - transform.position; * rotDiff = Quaternion.Inverse(m_rightHand.grabDestination.rotation * transform.rotation); * currentGrabber = m_rightHand; * } * break; * case(OVRInput.Controller.RTouch): * m_rightHand = null; * r0 = Vector3.zero; * if (m_leftHand == null) { * h0 = Vector3.zero; * l0 = Vector3.zero; * leftFirst = false; * posDiff = Vector3.zero; * rotDiff = Quaternion.identity; * currentGrabber = null; * } else { * h0 = m_leftHand.transform.position + Vector3.forward; * r0 = m_leftHand.transform.position + Vector3.forward; * l0 = r0; * leftFirst = true; * posDiff = m_leftHand.grabDestination.position - transform.position; * rotDiff = Quaternion.Inverse(m_leftHand.grabDestination.rotation * transform.rotation); * currentGrabber = m_leftHand; * } * break; * } * //int grabberIndex = grabbers.IndexOf(cg); * //if (grabberIndex > -1) { grabbers.RemoveAt(grabberIndex); } * grabbers.Remove(cg); * * //if (m_debugText) m_debugText.text += " | Successfully Removed Controller"; * /* * if (grabbers.Count > 0) { * StartCoroutine(SnapToTransformProcess); * // SnapToTransform(); * } */ }
public void GrabbedTurnedOff(CustomGrabber grabber, OVRInput.Controller c, CustomGrabbable cg) { onGrabbedTurnedOff?.Invoke(grabber, c, cg); }
public void ThumbRelease(CustomGrabber cg, OVRInput.Controller c) { onThumbRelease?.Invoke(cg, c); }
public void ThumbPress(CustomGrabber cg, OVRInput.Controller c) { onThumbPress?.Invoke(cg, c); }
public void TwoUp(CustomGrabber cg, OVRInput.Controller c) { onTwoUp?.Invoke(cg, c); }
public void OneDown(CustomGrabber cg, OVRInput.Controller c) { onOneDown?.Invoke(cg, c); }
public void TriggerDown(CustomGrabber cg, OVRInput.Controller c) { onTriggerDown?.Invoke(cg, c); }