public void OnPointerTriggerPressDown(XREventData eventData) { XRHand pointingHand = eventData.hand; Color newCubeColor; if (pointingHand == XRHand.Left) { newCubeColor = Color.blue; } else { newCubeColor = Color.red; } renderer.material.color = newCubeColor; Vector3 controlPos = eventData.module.transform.position; Debug.Log(controlPos); Debug.Log(gameObject.transform.position); Vector3 direction = gameObject.transform.position - controlPos; Vector3 nor_dir = Vector3.Normalize(direction); Debug.Log("2333"); rb.AddForce(nor_dir * 800); Debug.Log("1111"); }
private Transform FindClosestSnapTransform(XRHand cg) { Transform closest = null; float distance = 0f; foreach (Transform t in snapTransforms) { if (snapTransformInfo[t].taken) { continue; } if (closest == null) { closest = t; distance = Vector3.Distance(cg.grabVol.transform.position, t.position); } float tempDist = Vector3.Distance(cg.grabVol.transform.position, t.position); if (tempDist < distance) { closest = t; distance = tempDist; } } return(closest); }
public override bool CanAttach(XRHand hand, out int priority) { if (!isActiveAndEnabled) { priority = 0; return(false); } if (hand2Enabled && this.hand && isActiveAndEnabled) { priority = -1; if (hand2) { return(false); } else { return(true); } } else { if (this.hand) { priority = -2; return(canSwapHand); } else { priority = 0; return(true); } } }
//this selects the animals - allow for multiple animals to be selected //and changes the size of the destination target cylinder public void OnPointerTriggerPressDown(XREventData eventData) { selectedCount = 0; var hit = new RaycastHit(); XRHand pointingHand = eventData.hand; Vector3 controllerPos = eventData.module.transform.position; Debug.Log(controllerPos); /* * Ray ray = Camera.main.ScreenPointToRay(eventData.worldPosition); * if (Physics.Raycast(ray, out hit)) { * Debug.Log("hit"); * Debug.Log(hit.transform.position); */ Debug.Log(eventData.worldPosition); GameObject obj = Instantiate(prefab, new Vector3(eventData.worldPosition.x, eventData.worldPosition.y, eventData.worldPosition.z), Quaternion.identity) as GameObject; GameObject[] dess = GameObject.FindGameObjectsWithTag("Des"); //clear all the other gameobjects that's tagged "Des" foreach (GameObject GO in dess) { GO.tag = "Untagged"; // GameObject.Destroy(GO); } obj.tag = "Des"; //detects the number of animals selected GameObject[] sels = GameObject.FindGameObjectsWithTag("Selected"); foreach (GameObject GO in sels) { selectedCount++; } //adjust the size of the target cylinder according to the number of selected animals obj.transform.localScale += new Vector3(0.1f * selectedCount, 0, 0.1f * selectedCount); }
//public GameObject prefab; //public Transform location; public void OnPointerTriggerPressDown(XREventData eventData) { XRHand pointingHand = eventData.hand; GameObject[] animals = GameObject.FindGameObjectsWithTag("Selected"); foreach (GameObject a in animals) { selectedAnimalsCount++; } //<--- commented to allow for selecting multiple animals //if (pointingHand == XRHand.Left) GameObject cb = GameObject.FindGameObjectWithTag("Des"); if (gameObject.tag == "Animal") { gameObject.tag = "Selected"; //allow an unselected animal to be selected Debug.Log("hit"); cb.transform.localScale += new Vector3(0.1f, 0, 0.1f); } else { gameObject.tag = "Animal"; cb.transform.localScale -= new Vector3(0.1f, 0, 0.1f); //Debug.Log("animal already selected"); //prevent duplicants } }
// Called by XRHand to initiate grabbing public void GrabBegin(XRHand g) { // Kind of par on the course for all grabbers, we find the closest snap transform Transform snapTo = (snapTransforms.Count > 0) ? FindClosestSnapTransform(g) : null; m_grabbers.Add(g, snapTo); if (m_debugMode) { DebugLogger.current.AddLine("Grabbed By: " + g.gameObject.name); } // check if we have a main grabber or not if (m_mainGrabber == null) { 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"); //} m_mainGrabber = g; } else { m_semanticGrabbers.Add(g); } return; }
public GVRControllerStatus(XRHand hand) : base(hand) { if (hand == XRHand.Right) { return; } controller = OVRInput.GetActiveController(); }
public override bool CanAttach(XRHand hand, out int priority) { priority = 1; if (!isActiveAndEnabled) { return(false); } return(true); }
private void OnUngrab(XRHand hand, GameObject obj) { if (obj != gameObject) { return; } transform.SetParent(_previousParent); }
private void _OnHandUngrab(XRHand hand, GameObject obj) { if (obj != gameObject) { return; } OnUnselect.Invoke(); }
private void _OnHandUntouch(XRHand hand, GameObject obj) { if (obj != gameObject) { return; } OnUntouch.Invoke(); }
private void OnGrab(XRHand hand, GameObject obj) { if (obj != gameObject) { return; } _previousParent = transform.parent; transform.SetParent(hand.transform); }
public void OnPointerTriggerPressDown(XREventData eventData) { XRHand pointingHand = eventData.hand; GameObject[] dess = GameObject.FindGameObjectsWithTag("Des"); //clear all the other gameobjects that's tagged "Des" foreach (GameObject GO in dess) { GO.tag = "Untagged"; } gameObject.tag = "Des"; }
public override void OnDetach(XRHand handAttachedMe) { if (handAttachedMe.whichHand == UnityEngine.XR.XRNode.LeftHand) { attachedLeftHand = null; } else if (handAttachedMe.whichHand == UnityEngine.XR.XRNode.RightHand) { attachedRightHand = null; } }
private void OnEnable()//should not use awake for network compatibility { if (whichHand == XRNode.LeftHand) { leftHand = this; } if (whichHand == XRNode.RightHand) { rightHand = this; } }
public FocusControllerStatus(XRHand hand) : base(hand) { if (WaveVR.Instance == null) { Debug.LogError("WaveVR.Instance is null!"); return; } var wvr_hand = hand == XRHand.Left ? WVR_DeviceType.WVR_DeviceType_Controller_Left : WVR_DeviceType.WVR_DeviceType_Controller_Right; device = WaveVR.Instance.getDeviceByType(wvr_hand); controller = WaveVR_Controller.Input(wvr_hand); }
private void OnUngrab(XRHand hand, GameObject obj) { if (obj != gameObject) { return; } _rigidbody.velocity = _velocity; _rigidbody.isKinematic = false; _velocity = Vector3.zero; transform.SetParent(_previousParent); }
private void OnGrab(XRHand hand, GameObject obj) { if (obj != gameObject) { return; } _previousParent = transform.parent; transform.SetParent(hand.transform); _velocity = Vector3.zero; _rigidbody.velocity = Vector3.zero; _rigidbody.isKinematic = true; _previousPosition = transform.position; }
public override void OnAttach(XRHand emptyHand, Vector3 attachPositionWS, Quaternion attachRotationWS) { if (emptyHand.whichHand == UnityEngine.XR.XRNode.LeftHand) { attachedLeftHand = emptyHand; leftRef = pivot.InverseTransformPoint(emptyHand.position); } else if (emptyHand.whichHand == UnityEngine.XR.XRNode.RightHand) { attachedRightHand = emptyHand; rightRef = pivot.InverseTransformPoint(emptyHand.position); } onTakeover.Invoke(); }
public override void OnAttach(XRHand emptyHand, Vector3 attachPositionWS, Quaternion attachRotationWS) { if (hand) { hand2 = emptyHand; attached2PositionLS = yoke.InverseTransformPoint(hand.position); attached2RotationLS = Quaternion.Inverse(yoke.rotation) * hand.rotation; } else { hand = emptyHand; attachedPositionLS = yoke.InverseTransformPoint(hand.position); attachedRotationLS = Quaternion.Inverse(yoke.rotation) * hand.rotation; } onTakeover.Invoke(); }
public void TransforAttached(XRHand other) { if (attached) { other.DetachIfAny(); other.attached = attached; foreach (var c in attached.GetComponentsInChildren <Collider>()) { other.IgnoreCollider(c); } attached = null; SendHapticImpulse(hapticSettings.detachStrength, hapticSettings.detachDuration); other.SendHapticImpulse(other.hapticSettings.attachStrength, other.hapticSettings.attachDuration); } }
public override void OnDetach(XRHand handAttachedMe) { if (handAttachedMe == hand2) { hand2 = null; } else { hand = hand2; attachedPositionLS = attached2PositionLS; attachedRotationLS = attached2RotationLS; hand2 = null; } if (hand == null) { ResetYoke(); } }
public override void OnAttach(XRHand emptyHand, Vector3 attachPositionWS, Quaternion attachRotationWS) { if (mounted) { _UnMount(); } if (!hand) { hand = emptyHand; (joint, jointBias) = BuildJoint(body, emptyHand.bodyToAttach, jointSettings); attachedPositionLS = transform.InverseTransformPoint(attachPositionWS); attachedRotationLS = Quaternion.Inverse(transform.rotation) * attachRotationWS; ResetMovement(); updateEvents.updateAttach.Invoke(emptyHand.playerRoot); _OnPickUp(); } else { if (!hand2Enabled) { hand.TransforAttached(emptyHand); hand = emptyHand; (joint, jointBias) = BuildJoint(body, emptyHand.bodyToAttach, jointSettings); attachedPositionLS = transform.InverseTransformPoint(attachPositionWS); attachedRotationLS = Quaternion.Inverse(transform.rotation) * attachRotationWS; //TODO Test Logic } else { if (hand2) { hand2.DetachIfAny(); } hand2 = emptyHand; (joint2, jointBias2) = BuildJoint(body, emptyHand.bodyToAttach, jointSettings); attached2PositionLS = transform.InverseTransformPoint(attachPositionWS); attached2RotationLS = Quaternion.Inverse(transform.rotation) * attachRotationWS; } } }
public override void OnDetach(XRHand handAttachedMe) { if (handAttachedMe == hand2) { Destroy(joint2); joint2 = null; hand2 = null; if (hand.isHovering(this)) { attachedPositionLS = transform.InverseTransformPoint(hand.position); attachedRotationLS = Quaternion.Inverse(transform.rotation) * hand.rotation; } } else { if (hand2) { if (hand2AutoDrop) { hand2.DetachIfAny(); Destroy(joint); joint = null; hand = null; _OnDrop(); } else { Destroy(joint); joint = null; hand = null; hand = hand2; hand2 = null; joint = joint2; joint2 = null; jointBias = jointBias2; attachedPositionLS = attached2PositionLS; attachedRotationLS = attached2RotationLS; } } else { Destroy(joint); joint = null; hand = null; _OnDrop(); } } }
public void GrabEnd(XRHand hand, Vector3 linVel, Vector3 angVel) { // Remove hand from grabbers list m_grabbers.Remove(hand); // If the hand letting go is the same as the main grabber, we need to check if we can assign a new main grabber if (GameObject.ReferenceEquals(hand.gameObject, m_mainGrabber.gameObject)) { // If we have any semantic grabbers, we'll assign the oldest one as the new main if (m_semanticGrabbers.Count > 0) { // Find the new grabber XRHand newGrabber = m_semanticGrabbers[0]; // Remove it from our semantics list m_semanticGrabbers.Remove(newGrabber); // Set it m_mainGrabber = newGrabber; } else { // Otherwise, set main grabber to null and do everything else. m_mainGrabber = null; // Set its linear and angular velocities to the object's rigidbody m_RigidBody.isKinematic = m_grabbedKinematic; m_RigidBody.velocity = linVel * 2f; m_RigidBody.angularVelocity = angVel; //this.gameObject.layer = m_originalLayer; //Transform[] children = this.GetComponentsInChildren<Transform>(); //foreach (Transform c in children) { // c.gameObject.layer = m_childrenOriginalLayers[c.gameObject.GetInstanceID()]; //} } } else { m_semanticGrabbers.Remove(hand); } return; }
public virtual void OnDetach(XRHand handAttachedMe) { }
public virtual void OnAttach(XRHand emptyHand, Vector3 attachPositionWS, Quaternion attachRotationWS) { }
public XRControllerStatus(XRHand hand = XRHand.None) { this.hand = hand; }
public OculusTouchControllerStatus(XRHand hand) : base(hand) { node = hand == XRHand.Left ? XRNode.LeftHand : XRNode.RightHand; this.touchMappings = hand == XRHand.Left ? leftTouchMappings : rightTouchMappings; this.pressMappings = hand == XRHand.Left ? leftPressMappings : rightPressMappings; }
public virtual bool GetAttachPosition(XRHand hand, out Vector3 position, out Quaternion rotation) { position = hand.position; rotation = hand.rotation; return(false); }