private void Update() { if (!InputSystem.FocusProvider.TryGetFocusDetails(Pointer, out focusDetails)) { if (InputSystem.FocusProvider.IsPointerRegistered(Pointer)) { Debug.LogError($"{name}: Unable to get focus details for {pointer.GetType().Name}!"); } } UpdateCursorState(); UpdateCursorTransform(); }
protected FocusDetails?GetFocusDetails(IMixedRealityPointer pointer) { if (pointer == null) { return(null); } FocusDetails focusDetails; if (!CoreServices.InputSystem.FocusProvider.TryGetFocusDetails(pointer, out focusDetails)) { if (CoreServices.InputSystem.FocusProvider.IsPointerRegistered(pointer)) { Debug.LogError($"{name}: Unable to get focus details for {pointer.GetType().Name}!"); } } return(focusDetails); }
private void Update() { // Skip Update if the input system is missing during a runtime profile switch if ((CoreServices.InputSystem == null) || (CoreServices.InputSystem.FocusProvider == null)) { return; } if (!CoreServices.InputSystem.FocusProvider.TryGetFocusDetails(Pointer, out focusDetails)) { if (CoreServices.InputSystem.FocusProvider.IsPointerRegistered(Pointer)) { Debug.LogError($"{name}: Unable to get focus details for {pointer.GetType().Name}!"); } } UpdateCursorState(); UpdateCursorTransform(); }
/// <summary> /// Update the cursor's transform /// </summary> protected virtual void UpdateCursorTransform() { if (Pointer == null) { Debug.LogError($"[BaseCursor.{name}] No Pointer has been assigned!"); return; } FocusDetails focusDetails; if (!MixedRealityToolkit.InputSystem.FocusProvider.TryGetFocusDetails(Pointer, out focusDetails)) { if (MixedRealityToolkit.InputSystem.FocusProvider.IsPointerRegistered(Pointer)) { Debug.LogError($"{name}: Unable to get focus details for {pointer.GetType().Name}!"); } return; } GameObject newTargetedObject = MixedRealityToolkit.InputSystem.FocusProvider.GetFocusedObject(Pointer); Vector3 lookForward; // Normalize scale on before update targetScale = Vector3.one; // If no game object is hit, put the cursor at the default distance if (newTargetedObject == null) { TargetedObject = null; targetPosition = RayStep.GetPointByDistance(Pointer.Rays, defaultCursorDistance); lookForward = -RayStep.GetDirectionByDistance(Pointer.Rays, defaultCursorDistance); targetRotation = lookForward.magnitude > 0 ? Quaternion.LookRotation(lookForward, Vector3.up) : transform.rotation; } else { // Update currently targeted object TargetedObject = newTargetedObject; if (Pointer.CursorModifier != null) { Pointer.CursorModifier.GetModifiedTransform(this, out targetPosition, out targetRotation, out targetScale); } else { // If no modifier is on the target, just use the hit result to set cursor position // Get the look forward by using distance between pointer origin and target position // (This may not be strictly accurate for extremely wobbly pointers, but it should produce usable results) float distanceToTarget = Vector3.Distance(Pointer.Rays[0].Origin, focusDetails.Point); lookForward = -RayStep.GetDirectionByDistance(Pointer.Rays, distanceToTarget); targetPosition = focusDetails.Point + (lookForward * surfaceCursorDistance); Vector3 lookRotation = Vector3.Slerp(focusDetails.Normal, lookForward, lookRotationBlend); targetRotation = Quaternion.LookRotation(lookRotation == Vector3.zero ? lookForward : lookRotation, Vector3.up); } } float deltaTime = useUnscaledTime ? Time.unscaledDeltaTime : Time.deltaTime; // Use the lerp times to blend the position to the target position transform.position = Vector3.Lerp(transform.position, targetPosition, deltaTime / positionLerpTime); transform.localScale = Vector3.Lerp(transform.localScale, targetScale, deltaTime / scaleLerpTime); transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, deltaTime / rotationLerpTime); }