private void AddInteractionPointer() { InteractionPointer pointer = HumanoidInteractionPointer.Add(handTarget.transform, InteractionPointer.PointerType.Ray); if (handTarget.isLeft) { pointer.transform.localPosition = new Vector3(-0.21F, -0.02F, 0.01F); pointer.transform.localRotation = Quaternion.Euler(-180, 90, 180); } else { pointer.transform.localPosition = new Vector3(0.21F, -0.02F, 0.01F); pointer.transform.localRotation = Quaternion.Euler(-180, -90, -180); } //HandInput.Add(handTarget.transform); ControllerInput controllerInput = handTarget.humanoid.GetComponent <ControllerInput>(); if (controllerInput != null) { if (handTarget.isLeft) { controllerInput.leftButtonOneInput.SetMethod(pointer.Activation, InputEvent.EventType.Change); controllerInput.leftTrigger1Input.SetMethod(pointer.Click, InputEvent.EventType.Change); } else { controllerInput.rightButtonOneInput.SetMethod(pointer.Activation, InputEvent.EventType.Change); controllerInput.rightTrigger1Input.SetMethod(pointer.Click, InputEvent.EventType.Change); } } }
private void CastRayFromPointer(InteractionPointer pointer, InputDeviceIDs inputDeviceID) { pointer.data.Reset(); pointer.data.inputDevice = inputDeviceID; pointer.data.transform = pointer.pointerTransform; if (pointer.pointerTransform == null) { return; } CastPhysicsRayFromPointer(pointer); CastUIRayFromPointer(pointer); pointer.data.scrollDelta = Vector2.zero; if (pointer.focusObject != null) { if (pointer.previousPosition.sqrMagnitude == 0) { pointer.data.delta = Vector2.zero; } else { pointer.data.delta = pointer.data.position - pointer.previousPosition; } pointer.previousPosition = pointer.data.position; pointer.touchPosition = pointer.data.pointerCurrentRaycast.worldPosition; } }
public void ActivateFingerPointing(bool isPointing, bool isLeft) { InteractionPointer pointer = isLeft ? pointers[(int)InputDeviceIDs.LeftHand] : pointers[(int)InputDeviceIDs.RightHand]; if (pointer != null) { pointer.focusingEnabled = isPointing; // only focusing when we are pointing } }
public bool IsTimedClick(int inputDevice) { InteractionPointer pointer = pointers[inputDevice]; return (!pointer.hasClicked && pointer.focusTimeToTouch != 0 && pointer.focusStart > 0 && Time.time - pointer.focusStart > pointer.focusTimeToTouch); }
public void HandInteractionActivation(bool isLeft) { InteractionPointer pointer = isLeft ? pointers[(int)InputDeviceIDs.LeftHand] : pointers[(int)InputDeviceIDs.RightHand]; if (pointer == null) { return; } pointer.ProcessTouch(); }
public void OnFingerTouchEnd(bool isLeft) { InteractionPointer pointer = isLeft ? pointers[(int)InputDeviceIDs.LeftHand] : pointers[(int)InputDeviceIDs.RightHand]; if (pointer == null) { return; } pointer.ProcessNoTouch(); }
public virtual void OnEnable() { pointer = (InteractionPointer)target; timedClickProp = serializedObject.FindProperty("timedClick"); pointerModeProp = serializedObject.FindProperty("rayType"); maxDistanceProp = serializedObject.FindProperty("maxDistance"); resolutionProp = serializedObject.FindProperty("resolution"); speedProp = serializedObject.FindProperty("speed"); radiusProp = serializedObject.FindProperty("radius"); }
public void OnFingerTouchStart(bool isLeft, GameObject obj) { InteractionPointer pointer = isLeft ? pointers[(int)InputDeviceIDs.LeftHand] : pointers[(int)InputDeviceIDs.RightHand]; if (pointer == null) { return; } pointer.focusObject = obj; pointer.data.delta = Vector3.zero; pointer.ProcessTouch(); }
public int CreateNewInteraction(Transform transform, float timedClick) { InteractionPointer pointer = new InteractionPointer(PointerType.Point, transform, eventSystem); pointers[nInteractions++] = pointer; pointer.focusingEnabled = false; pointer.localPointingDirection = Vector3.forward; pointer.focusTimeToTouch = timedClick; return(nInteractions - 1); }
private void ProcessPointer(InteractionPointer pointer, InputDeviceIDs inputDeviceID) { CastRayFromPointer(pointer, inputDeviceID); if (pointer.focusingEnabled && pointer.type == PointerType.Point) { pointer.ProcessFocus(); } if (pointer.focusObject != null && pointer.focusTimeToTouch != 0 && Time.time - pointer.focusStart > pointer.focusTimeToTouch) // we are clicking { pointer.ProcessTouch(); pointer.ProcessNoTouch(); } else if (pointer.clicking) { pointer.ProcessTouch(); } if (pointer.data.pointerCurrentRaycast.gameObject == null) // no focus { return; } pointer.data.pressPosition = pointer.data.position; pointer.data.pointerPressRaycast = pointer.data.pointerCurrentRaycast; pointer.data.pointerPress = null; //Clear this for setting later pointer.data.useDragThreshold = true; if (pointer.type == PointerType.Touch) { // UI touch without colliders works on the finger tip float distance = DistanceTipToTransform(pointer.pointerTransform, pointer.data.pointerCurrentRaycast.gameObject.transform); if (distance < 0) // we are touching { pointer.ProcessTouch(); } else if (distance > 0.05F) { pointer.ProcessNoTouch(); } else { pointer.ProcessFocus(); } } }
public GameObject GetTouchObject(InputDeviceIDs inputDeviceID) { InteractionPointer pointer = pointers[(int)inputDeviceID]; if (pointer == null) { return(null); } if (pointer.touchedObject != null) { return(pointer.touchedObject); } else { return(null); } }
public void SetExternalRayCast(int inputDeviceID, Vector3 focusPosition, Quaternion focusRotation, GameObject focusObject) { InteractionPointer pointer = pointers[inputDeviceID]; pointer.focusPosition = focusPosition; pointer.focusRotation = focusRotation; pointer.focusObject = focusObject; RaycastResult raycastResult = new RaycastResult(); raycastResult.worldPosition = pointer.focusPosition; raycastResult.worldNormal = pointer.focusRotation * Vector3.forward; raycastResult.distance = (raycastResult.worldPosition - pointer.pointerTransform.position).magnitude; raycastResult.gameObject = pointer.focusObject; pointer.data.pointerCurrentRaycast = raycastResult; pointer.externalRayCast = true; }
private void GazeInteractionButton(HeadTarget headTarget) { InteractionPointer interactionPointer = headTarget.transform.GetComponentInChildren <InteractionPointer>(); if (interactionPointer != null) { return; } GUILayout.BeginHorizontal(); if (GUILayout.Button("Add Interaction Pointer")) { AddInteractionPointer(); } if (GUILayout.Button("Add Teleporter")) { AddTeleporter(); } GUILayout.EndHorizontal(); }
private void AddInteractionPointer() { InteractionPointer pointer = HumanoidInteractionPointer.Add(headTarget.transform, InteractionPointer.PointerType.FocusPoint); Camera fpCamera = UnityVRHead.GetCamera(headTarget); if (fpCamera != null) { pointer.transform.position = fpCamera.transform.position; pointer.transform.rotation = fpCamera.transform.rotation; } pointer.focusPointObj.transform.localPosition = new Vector3(0, 0, 2); HeadInput.Add(headTarget.transform); ControllerInput controllerInput = headTarget.humanoid.GetComponent <ControllerInput>(); if (controllerInput != null) { controllerInput.leftButtonOneInput.SetMethod(pointer.Click, InputEvent.EventType.Start); } }
public static InteractionPointer Add(Transform parentTransform, PointerType pointerType = PointerType.Ray) { GameObject pointerObj = new GameObject("Interaction Pointer"); pointerObj.transform.SetParent(parentTransform); pointerObj.transform.localPosition = new Vector3(0.2039F, -0.0223F, 0.0092F); pointerObj.transform.localRotation = Quaternion.Euler(-180, -90, -180); GameObject focusPointObj = new GameObject("FocusPoint"); focusPointObj.transform.SetParent(pointerObj.transform); focusPointObj.transform.localPosition = Vector3.zero; focusPointObj.transform.localRotation = Quaternion.identity; if (pointerType == PointerType.FocusPoint) { GameObject focusPointSphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); focusPointSphere.transform.SetParent(focusPointObj.transform); focusPointSphere.transform.localPosition = Vector3.zero; focusPointSphere.transform.localRotation = Quaternion.identity; focusPointSphere.transform.localScale = Vector3.one * 0.1F; } else { LineRenderer pointerRay = focusPointObj.AddComponent <LineRenderer>(); pointerRay.startWidth = 0.01F; pointerRay.endWidth = 0.01F; pointerRay.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; pointerRay.receiveShadows = false; pointerRay.useWorldSpace = false; } InteractionPointer pointer = pointerObj.AddComponent <InteractionPointer>(); pointer.focusPointObj = focusPointObj; pointer.rayType = RayType.Straight; return(pointer); }
private void CastUIRayFromPointer(InteractionPointer pointer) { if (Camera.main == null) { return; } //Debug.DrawLine(Camera.main.transform.position, pointer.focusPosition); //Vector3 ray = Camera.main.ScreenToWorldPoint(pointer.data.position); //Debug.DrawLine(Camera.main.transform.position, ray, Color.green); eventSystem.RaycastAll(pointer.data, m_RaycastResultCache); //pointer.data.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache); RaycastResult raycastResult = FindFirstRaycast(m_RaycastResultCache); m_RaycastResultCache.Clear(); if (raycastResult.gameObject != null) { if (pointer.type == PointerType.Touch) { float distance = DistanceTipToTransform(pointer.pointerTransform, raycastResult.gameObject.transform); // Focus only when hovering if (distance > 0.05F) { return; } } pointer.data.pointerCurrentRaycast = raycastResult; pointer.focusObject = pointer.data.pointerCurrentRaycast.gameObject; // EventSystem.RaycastAll always casts from main.camera. This is why we need a trick to look like it is casting from the pointerlocation (e.g. finger) // The result does not look right in scene view, but does look OK in game view Vector3 focusDirection = (pointer.focusPosition - Camera.main.transform.position).normalized; pointer.focusPosition = Camera.main.transform.position + focusDirection * pointer.data.pointerCurrentRaycast.distance; // pointer.data.pointerCurrentRaycast.worldPosition == Vector.zero unfortunately //pointer.data.position = pointer.focusPosition; pointer.data.position = Camera.main.WorldToScreenPoint(pointer.focusPosition); } }
public void EnableTouchInput(HumanoidControl humanoid, bool isLeft, float autoActivation) { if (humanoid.avatarRig == null) { return; } if (pointers == null) { pointers = new InteractionPointer[maxInteractions]; // 0 = left index, 1 = right index, 2 = head, 3 = controller } Controller controllerInput = Controllers.GetController(0); Transform indexFingerDistal = null; Transform indexFingerTip = null; InteractionPointer pointer = null; if (isLeft) { indexFingerDistal = humanoid.avatarRig.GetBoneTransform(HumanBodyBones.LeftIndexDistal); if (indexFingerDistal != null) { if (indexFingerDistal.childCount == 1) { indexFingerTip = indexFingerDistal.GetChild(0); } else { indexFingerTip = indexFingerDistal; } pointer = new InteractionPointer(PointerType.Touch, indexFingerTip, eventSystem); pointers[(int)InputDeviceIDs.LeftHand] = pointer; if (controllerInput != null) { pointer.controllerInputSide = controllerInput.left; } } } else { indexFingerDistal = humanoid.avatarRig.GetBoneTransform(HumanBodyBones.RightIndexDistal); if (indexFingerDistal != null) { if (indexFingerDistal.childCount == 1) { indexFingerTip = indexFingerDistal.GetChild(0); } else { indexFingerTip = indexFingerDistal; } pointer = new InteractionPointer(PointerType.Touch, indexFingerTip, eventSystem); pointers[(int)InputDeviceIDs.RightHand] = pointer; if (controllerInput != null) { pointer.controllerInputSide = controllerInput.right; } } } if (indexFingerDistal != null) { if (indexFingerDistal.childCount > 0) { indexFingerTip = indexFingerDistal.GetChild(0); pointer.localPointingDirection = indexFingerTip.InverseTransformDirection(indexFingerTip.position - indexFingerDistal.position).normalized; } else { pointer.localPointingDirection = indexFingerDistal.InverseTransformDirection(indexFingerDistal.position - indexFingerDistal.parent.position).normalized; } } if (pointer != null) { pointer.focusTimeToTouch = autoActivation; // To support hovering pointer.focusingEnabled = true; } }
public void SetPointingDirection(int inputDevice, Vector3 direction) { InteractionPointer pointer = pointers[inputDevice]; pointer.localPointingDirection = pointer.pointerTransform.InverseTransformDirection(direction); }
private void CastPhysicsRayFromPointer(InteractionPointer pointer) { RaycastResult raycastResult = new RaycastResult(); if (pointer.focusingEnabled && pointer.type == PointerType.Point) { if (pointer.externalRayCast) { raycastResult.worldPosition = pointer.focusPosition; raycastResult.worldNormal = pointer.focusRotation * Vector3.forward; raycastResult.distance = (raycastResult.worldPosition - pointer.pointerTransform.position).magnitude; raycastResult.gameObject = pointer.focusObject; } else { Vector3 pointingDirection = pointer.pointerTransform.rotation * pointer.localPointingDirection; RaycastHit hit; bool raycastHit = Physics.Raycast(pointer.pointerTransform.position, pointingDirection * 10, out hit); if (raycastHit) { pointer.focusPosition = hit.point; pointer.focusRotation = Quaternion.LookRotation(hit.normal); pointer.focusObject = hit.transform.gameObject; raycastResult.worldPosition = hit.point; raycastResult.worldNormal = hit.normal; raycastResult.distance = hit.distance; raycastResult.gameObject = hit.transform.gameObject; } else { pointer.focusPosition = pointer.pointerTransform.position + pointingDirection * 10; pointer.focusRotation = Quaternion.LookRotation(-pointingDirection); pointer.focusObject = null; raycastResult.worldPosition = pointer.pointerTransform.position + pointingDirection * 10; raycastResult.worldNormal = -pointingDirection; raycastResult.distance = 0; raycastResult.gameObject = null; } if (Camera.main != null) { pointer.data.position = Camera.main.WorldToScreenPoint(pointer.focusPosition); raycastResult.screenPosition = Camera.main.WorldToScreenPoint(pointer.focusPosition); } } } else { pointer.focusPosition = pointer.pointerTransform.position; pointer.focusRotation = Quaternion.identity; pointer.focusObject = null; raycastResult.worldPosition = pointer.pointerTransform.position; raycastResult.worldNormal = Vector3.up; raycastResult.distance = 0; raycastResult.gameObject = null; if (Camera.main != null) { pointer.data.position = Camera.main.WorldToScreenPoint(pointer.pointerTransform.position); raycastResult.screenPosition = Camera.main.WorldToScreenPoint(pointer.focusPosition); } } pointer.data.pointerCurrentRaycast = raycastResult; }