private void FindCursorIfNeeded() { if ((Cursor == null) && SearchForCursorIfUnset) { Debug.LogWarningFormat( this, "Cursor hasn't been explicitly set on \"{0}.{1}\". We'll search for a cursor in the hierarchy, but" + " that comes with a performance cost, so it would be best if you explicitly set the cursor.", name, GetType().Name ); BaseCursor[] foundCursors = FindObjectsOfType <BaseCursor>(); if ((foundCursors == null) || (foundCursors.Length == 0)) { Debug.LogErrorFormat(this, "Couldn't find cursor for \"{0}.{1}\".", name, GetType().Name); } else if (foundCursors.Length > 1) { Debug.LogErrorFormat( this, "Found more than one ({0}) cursors for \"{1}.{2}\", so couldn't automatically set one.", foundCursors.Length, name, GetType().Name ); } else { Cursor = foundCursors[0]; } } }
protected override void OnEnable() { base.OnEnable(); SetCursor(); BaseCursor?.SetVisibility(true); TeleportSystem?.Register(gameObject); }
private void UpdateMousePosition(float mouseX, float mouseY) { if (Mathf.Abs(mouseX) >= movementThresholdToUnHide || Mathf.Abs(mouseY) >= movementThresholdToUnHide) { if (isDisabled) { BaseCursor?.SetVisibility(true); transform.rotation = CameraCache.Main.transform.rotation; } isDisabled = false; } if (!isDisabled) { timeoutTimer = 0.0f; } var newRotation = Vector3.zero; newRotation.x += mouseX; newRotation.y += mouseY; transform.Rotate(newRotation, Space.World); }
/// <inheritdoc /> public virtual void OnTeleportCompleted(TeleportEventData eventData) { using (OnTeleportCompletedPerfMarker.Auto()) { isTeleportRequestActive = false; BaseCursor?.SetVisibility(false); } }
public IEnumerator CursorScaling() { // Finding or initializing necessary objects Camera cam = GameObject.FindObjectOfType<Camera>(); BaseCursor baseCursor = GameObject.FindObjectOfType<BaseCursor>(); Assert.IsNotNull(baseCursor); // Make sure resizing is turned on Assert.IsTrue(baseCursor.ResizeCursorWithDistance); // Set CursorAngularScale for hardcoded calculations baseCursor.CursorAngularSize = 50.0f; cube.transform.position = Vector3.forward * 2.0f; // Wait for cursor to resize/move yield return new WaitForFixedUpdate(); yield return null; // Part one tests cursor size against precalculated values at two different distances // FIRST DISTANCE float precalculatedScale = 2.0f * Vector3.Distance(cam.transform.position, baseCursor.transform.position) * Mathf.Tan(baseCursor.CursorAngularSize * Mathf.Deg2Rad * 0.5f); Assert.IsTrue(Mathf.Approximately(precalculatedScale, baseCursor.transform.localScale.y)); yield return new WaitForFixedUpdate(); yield return null; cube.transform.position = Vector3.forward; // Wait for cursor to resize/move yield return new WaitForFixedUpdate(); yield return null; // SECOND DISTANCE precalculatedScale = 2.0f * Vector3.Distance(cam.transform.position, baseCursor.transform.position) * Mathf.Tan(baseCursor.CursorAngularSize * Mathf.Deg2Rad * 0.5f); Assert.IsTrue(Mathf.Approximately(precalculatedScale, baseCursor.transform.localScale.y)); yield return new WaitForFixedUpdate(); yield return null; //Part two tests if precalculated angularSize matches what is returned in baseCursor.ComputeScaleWithAngularScale() at two different distances // FIRST DISTANCE float firstAngularScale = 2 * Mathf.Atan2(baseCursor.LocalScale.y * 0.5f, Vector3.Distance(cam.transform.position, baseCursor.transform.position)); cube.gameObject.SetActive(false); yield return new WaitForFixedUpdate(); yield return null; // SECOND DISTANCE float secondAngularScale = 2 * Mathf.Atan2(baseCursor.LocalScale.y * 0.5f, Vector3.Distance(cam.transform.position, baseCursor.transform.position)); Assert.IsTrue(Mathf.Approximately(firstAngularScale, secondAngularScale)); }
/// <inheritdoc /> public virtual void OnTeleportStarted(TeleportEventData eventData) { using (OnTeleportStartedPerfMarker.Auto()) { // Turn off all pointers while we teleport. isTeleportRequestActive = true; BaseCursor?.SetVisibility(false); } }
protected override void OnDisable() { base.OnDisable(); MixedRealityToolkit.TeleportSystem?.Unregister(gameObject); IsHoldPressed = false; IsSelectPressed = false; HasSelectPressedOnce = false; BaseCursor?.SetVisibility(false); }
/// <inheritdoc /> public override void OnTeleportRequest(TeleportEventData eventData) { // Only turn off the pointer if we're not the one sending the request if (eventData.Pointer.PointerId == PointerId) { IsTeleportRequestActive = false; } else { IsTeleportRequestActive = true; BaseCursor?.SetVisibility(false); } }
/// <inheritdoc /> public override void OnInputDown(InputEventData eventData) { cursorWasDisabledOnDown = isDisabled; if (cursorWasDisabledOnDown) { BaseCursor?.SetVisibility(true); transform.rotation = CameraCache.Main.transform.rotation; } else { base.OnInputDown(eventData); } }
/// <summary> /// Hide the cursor during the gesture /// </summary> /// <param name="state"></param> private void HandleCursor(bool state) { // Hack for now. // TODO: Update Cursor Modifier to handle HideOnGesture, then calculate visibility so cursors can handle this correctly if (state) { mCursor = FindObjectOfType <BaseCursor>(); } if (HideCursorOnManipulation && mCursor != null) { mCursor.SetVisibility(!state); } }
private void Update() { if (!hideCursorWhenInactive || isDisabled) { return; } timeoutTimer += Time.unscaledDeltaTime; if (timeoutTimer >= hideTimeout) { timeoutTimer = 0.0f; BaseCursor?.SetVisibility(false); isDisabled = true; } }
/// <inheritdoc /> public virtual void OnTeleportRequest(TeleportEventData eventData) { using (OnTeleportRequestPerfMarker.Auto()) { // Only turn off the pointer if we're not the one sending the request if (eventData.Pointer.PointerId == PointerId) { isTeleportRequestActive = false; BaseCursor?.SetVisibility(true); } else { isTeleportRequestActive = true; BaseCursor?.SetVisibility(false); } } }
/// <summary> /// Set a new cursor for this <see cref="IMixedRealityPointer"/> /// </summary> /// <remarks>This <see cref="GameObject"/> must have a <see cref="IMixedRealityCursor"/> attached to it.</remarks> /// <param name="newCursor">The new cursor</param> public virtual void SetCursor(GameObject newCursor = null) { if (cursorInstance != null) { if (Application.isEditor) { DestroyImmediate(cursorInstance); } else { Destroy(cursorInstance); } cursorInstance = newCursor; } if (cursorInstance == null && cursorPrefab != null) { cursorInstance = Instantiate(cursorPrefab, transform); } if (cursorInstance != null) { cursorInstance.name = $"{Handedness}_{name}_Cursor"; BaseCursor = cursorInstance.GetComponent <IMixedRealityCursor>(); if (BaseCursor != null) { BaseCursor.DefaultCursorDistance = PointerExtent; BaseCursor.Pointer = this; BaseCursor.SetVisibilityOnSourceDetected = setCursorVisibilityOnSourceDetected; if (disableCursorOnStart) { BaseCursor.SetVisibility(false); } } else { Debug.LogError($"No IMixedRealityCursor component found on {cursorInstance.name}"); } } }
public override void OnPostSceneQuery() { // Use the results from the last update to set our NavigationResult float clearWorldLength = 0f; TeleportSurfaceResult = TeleportSurfaceResult.None; GravityDistorter.enabled = false; if (IsInteractionEnabled) { LineBase.enabled = true; // If we hit something if (Result.CurrentPointerTarget != null) { // Check if it's in our valid layers if (((1 << Result.CurrentPointerTarget.layer) & ValidLayers.value) != 0) { // See if it's a hot spot if (TeleportHotSpot != null && TeleportHotSpot.IsActive) { TeleportSurfaceResult = TeleportSurfaceResult.HotSpot; // Turn on gravity, point it at hotspot GravityDistorter.WorldCenterOfGravity = TeleportHotSpot.Position; GravityDistorter.enabled = true; } else { // If it's NOT a hotspot, check if the hit normal is too steep // (Hotspots override dot requirements) TeleportSurfaceResult = Vector3.Dot(Result.Details.LastRaycastHit.normal, Vector3.up) > upDirectionThreshold ? TeleportSurfaceResult.Valid : TeleportSurfaceResult.Invalid; } } else if (((1 << Result.CurrentPointerTarget.layer) & InvalidLayers) != 0) { TeleportSurfaceResult = TeleportSurfaceResult.Invalid; } else { TeleportSurfaceResult = TeleportSurfaceResult.None; } clearWorldLength = Result.Details.RayDistance; // Clamp the end of the parabola to the result hit's point LineBase.LineEndClamp = LineBase.GetNormalizedLengthFromWorldLength(clearWorldLength, LineCastResolution); BaseCursor?.SetVisibility(TeleportSurfaceResult == TeleportSurfaceResult.Valid || TeleportSurfaceResult == TeleportSurfaceResult.HotSpot); } else { BaseCursor?.SetVisibility(false); LineBase.LineEndClamp = 1f; } // Set the line color for (int i = 0; i < LineRenderers.Length; i++) { LineRenderers[i].LineColor = GetLineGradient(TeleportSurfaceResult); } } else { LineBase.enabled = false; } }
/// <inheritdoc /> public override void OnTeleportStarted(TeleportEventData eventData) { // Turn off all pointers while we teleport. IsTeleportRequestActive = true; BaseCursor?.SetVisibility(false); }
/// <inheritdoc /> public virtual void OnTeleportCanceled(TeleportEventData eventData) { isTeleportRequestActive = false; BaseCursor?.SetVisibility(false); }
/// <inheritdoc /> public virtual void OnTeleportCanceled(TeleportEventData eventData) { // Turn all our pointers back on. IsTeleportRequestActive = false; BaseCursor?.SetVisibility(true); }
/// <inheritdoc /> public virtual void OnTeleportRequest(TeleportEventData eventData) { // Only turn off pointers that aren't making the request. IsTeleportRequestActive = true; BaseCursor?.SetVisibility(false); }
public override void OnPostRaycast() { // Use the results from the last update to set our NavigationResult float clearWorldLength = 0f; TeleportSurfaceResult = TeleportSurfaceResult.None; GravityDistorter.enabled = false; if (IsInteractionEnabled) { LineBase.enabled = true; // If we hit something if (Result.CurrentPointerTarget != null) { // Check if it's in our valid layers if (((1 << Result.CurrentPointerTarget.layer) & ValidLayers.value) != 0) { // See if it's a hot spot if (TeleportHotSpot != null && TeleportHotSpot.IsActive) { TeleportSurfaceResult = TeleportSurfaceResult.HotSpot; // Turn on gravity, point it at hotspot GravityDistorter.WorldCenterOfGravity = TeleportHotSpot.Position; GravityDistorter.enabled = true; } else { // If it's NOT a hotspot, check if the hit normal is too steep // (Hotspots override dot requirements) TeleportSurfaceResult = Vector3.Dot(Result.Details.LastRaycastHit.normal, Vector3.up) > upDirectionThreshold ? TeleportSurfaceResult.Valid : TeleportSurfaceResult.Invalid; } } else if (((1 << Result.CurrentPointerTarget.layer) & InvalidLayers) != 0) { TeleportSurfaceResult = TeleportSurfaceResult.Invalid; } else { TeleportSurfaceResult = TeleportSurfaceResult.None; } // Use the step index to determine the length of the hit for (int i = 0; i <= Result.RayStepIndex; i++) { if (i == Result.RayStepIndex) { if (MixedRealityRaycaster.DebugEnabled) { Color debugColor = TeleportSurfaceResult != TeleportSurfaceResult.None ? Color.yellow : Color.cyan; Debug.DrawLine(Result.StartPoint + Vector3.up * 0.1f, Result.StartPoint + Vector3.up * 0.1f, debugColor); } // Only add the distance between the start point and the hit clearWorldLength += Vector3.Distance(Result.StartPoint, Result.Details.Point); } else if (i < Result.RayStepIndex) { // Add the full length of the step to our total distance clearWorldLength += Rays[i].Length; } } // Clamp the end of the parabola to the result hit's point LineBase.LineEndClamp = LineBase.GetNormalizedLengthFromWorldLength(clearWorldLength, LineCastResolution); BaseCursor?.SetVisibility(TeleportSurfaceResult == TeleportSurfaceResult.Valid || TeleportSurfaceResult == TeleportSurfaceResult.HotSpot); } else { BaseCursor?.SetVisibility(false); LineBase.LineEndClamp = 1f; } // Set the line color for (int i = 0; i < LineRenderers.Length; i++) { LineRenderers[i].LineColor = GetLineGradient(TeleportSurfaceResult); } } else { LineBase.enabled = false; } }
protected override void OnEnable() { base.OnEnable(); BaseCursor?.SetVisibility(false); }
/// <inheritdoc /> public override void OnTeleportCanceled(TeleportEventData eventData) { IsTeleportRequestActive = false; BaseCursor?.SetVisibility(false); }
/// <inheritdoc /> public override void SetCursor(GameObject newCursor = null) { base.SetCursor(newCursor); BaseCursor?.SetVisibility(false); }