IEnumerator AnimateUndoPerformed(bool undo) { var targetMaterial = undo ? m_UndoButtonMaterial : m_RedoButtonMaterial; var startingColor = m_UndoButtonMaterial.GetColor(k_MaterialColorProperty); var targetColor = startingColor; targetColor.a = k_UndoPerformedAlpha; var transitionAmount = 0f; var currentDuration = 0f; while (transitionAmount < 1f) { var currentColor = Color.Lerp(startingColor, targetColor, MathUtilsExt.SmoothInOutLerpFloat(transitionAmount)); targetMaterial.SetColor(k_MaterialColorProperty, currentColor); currentDuration += Time.deltaTime; transitionAmount = currentDuration / k_EngageAnimationDuration; yield return(null); } transitionAmount = currentDuration = 0f; startingColor = targetColor; targetColor.a = k_DisengagedAlpha; while (transitionAmount < 1f) { var currentColor = Color.Lerp(startingColor, targetColor, MathUtilsExt.SmoothInOutLerpFloat(transitionAmount)); targetMaterial.SetColor(k_MaterialColorProperty, currentColor); currentDuration += Time.deltaTime; transitionAmount = currentDuration / k_EngageAnimationDuration; yield return(null); } targetMaterial.SetColor(k_MaterialColorProperty, targetColor); }
IEnumerator UpdateVisibility(bool visible) { m_Visible = visible; if (visible) { yield return(new WaitForSeconds(m_Delay)); } const float hidingSpeedMultiplier = 8f; const float showingSpeedMultiplier = 1.25f; var durationMultiplier = visible ? showingSpeedMultiplier : hidingSpeedMultiplier; var currentCanvasGroupAlpha = m_CanvasGroup.alpha; var targetCanvasGroupAlpha = visible ? 1f : 0f; var amount = 0f; while (amount < 1f) { var shapedAmount = MathUtilsExt.SmoothInOutLerpFloat(amount += Time.unscaledDeltaTime * durationMultiplier); var targetZeroOneLerpValue = Mathf.Lerp(currentCanvasGroupAlpha, targetCanvasGroupAlpha, shapedAmount); m_CanvasGroup.alpha = targetZeroOneLerpValue; m_BorderImage.fillAmount = targetZeroOneLerpValue; yield return(null); } m_CanvasGroup.alpha = targetCanvasGroupAlpha; m_AnimationVisibilityCoroutine = null; }
IEnumerator AnimateHighlight(bool isHighlighted) { var currentAlpha = m_CanvasGroup.alpha; var targetAlpha = 1f; var alphaTransitionAmount = 0f; var textTransform = m_Text.transform; var textCurrentLocalPosition = textTransform.localPosition; var textTargetLocalPosition = isHighlighted ? new Vector3(m_TextOriginalLocalPosition.x, m_TextOriginalLocalPosition.y, m_HighlightedZOffset) : m_TextOriginalLocalPosition; var positionTransitionAmount = 0f; var currentTextLocalScale = textTransform.localScale; var targetTextLocalScale = isHighlighted ? Vector3.one * 1.15f : Vector3.one; var speedMultiplier = isHighlighted ? 8f : 4f; while (alphaTransitionAmount < 1f) { var alphaSmoothTransition = MathUtilsExt.SmoothInOutLerpFloat(alphaTransitionAmount); var positionSmoothTransition = MathUtilsExt.SmoothInOutLerpFloat(positionTransitionAmount); m_CanvasGroup.alpha = Mathf.Lerp(currentAlpha, targetAlpha, alphaSmoothTransition); textTransform.localPosition = Vector3.Lerp(textCurrentLocalPosition, textTargetLocalPosition, positionSmoothTransition); textTransform.localScale = Vector3.Lerp(currentTextLocalScale, targetTextLocalScale, alphaSmoothTransition); alphaTransitionAmount += Time.deltaTime * speedMultiplier; positionTransitionAmount += alphaTransitionAmount * 1.35f; // slightly faster position transition yield return(null); } textTransform.localPosition = textTargetLocalPosition; textTransform.localScale = targetTextLocalScale; m_CanvasGroup.alpha = targetAlpha; m_VisibilityCoroutine = null; }
IEnumerator RepositionElement(IAdaptPosition adaptiveElement) { var adaptiveTransform = adaptiveElement.adaptiveTransform; var currentPosition = adaptiveTransform.position; var targetPosition = m_GazeTransform.position; targetPosition = targetPosition + this.GetViewerScale() * m_GazeTransform.forward * adaptiveElement.adaptivePositionRestDistance; if (!adaptiveElement.resetAdaptivePosition) { this.Pulse(Node.None, m_MovingPulse); const float kTransitionSpeedScalar = 4f; adaptiveElement.beingMoved = true; var transitionAmount = 0f; while (transitionAmount < 1f) { var smoothTransition = MathUtilsExt.SmoothInOutLerpFloat(transitionAmount); smoothTransition *= smoothTransition; adaptiveTransform.position = Vector3.Lerp(currentPosition, targetPosition, smoothTransition); transitionAmount += Time.deltaTime * kTransitionSpeedScalar; adaptiveTransform.LookAt(m_GazeTransform); yield return(null); } } adaptiveTransform.position = targetPosition; adaptiveTransform.LookAt(m_GazeTransform); adaptiveElement.adaptiveElementRepositionCoroutine = null; adaptiveElement.beingMoved = false; adaptiveElement.resetAdaptivePosition = false; }
IEnumerator AnimatePulseColor() { const float kTargetDuration = 1f; m_PulseDuration = 0f; var maxShaderLineRadius = new Vector3(0.03f, 0f, 100f); var minShaderLineRadius = new Vector3(0.005f, 0f, 100f); var currentVector3ShaderLineRadius = m_HintLineMaterial.GetVector(k_ShaderLineRadiusPropertyName); var currentColor = m_ScrollLineRenderer.colorStart; // The line stand & end colors are the same; fetch only one of them while (m_PulseDuration < kTargetDuration) { var shapedDuration = MathUtilsExt.SmoothInOutLerpFloat(m_PulseDuration / kTargetDuration); var newColor = Color.Lerp(currentColor, m_PulseColor, shapedDuration); m_ScrollLineRenderer.SetColors(newColor, newColor); m_PulseDuration += Time.unscaledDeltaTime * 5; m_HintLineMaterial.SetVector(k_ShaderLineRadiusPropertyName, Vector3.Lerp(currentVector3ShaderLineRadius, maxShaderLineRadius, shapedDuration)); yield return(null); } while (m_PulseDuration > 0f) { var shapedDuration = MathUtilsExt.SmoothInOutLerpFloat(m_PulseDuration / kTargetDuration); var newColor = Color.Lerp(m_VisibleColor, m_PulseColor, shapedDuration); m_ScrollLineRenderer.SetColors(newColor, newColor); m_PulseDuration -= Time.unscaledDeltaTime * 1.5f; m_HintLineMaterial.SetVector(k_ShaderLineRadiusPropertyName, Vector3.Lerp(minShaderLineRadius, maxShaderLineRadius, shapedDuration)); yield return(null); } m_ScrollLineRenderer.SetColors(m_VisibleColor, m_VisibleColor); m_PulseDuration = 0f; }
IEnumerator AnimateVisibility(bool fadeIn) { var currentAlpha = fadeIn ? 0f : m_CanvasGroup.alpha; var targetAlpha = fadeIn ? 1f : 0f; var alphaTransitionAmount = 0f; var textTransform = m_Text.transform; var textCurrentLocalPosition = textTransform.localPosition; textCurrentLocalPosition = fadeIn ? new Vector3(m_TextOriginalLocalPosition.x, m_TextOriginalLocalPosition.y, m_FadeInZOffset) : textCurrentLocalPosition; var textTargetLocalPosition = m_TextOriginalLocalPosition; var positionTransitionAmount = 0f; var transitionSubtractMultiplier = 1f / m_TransitionDuration; while (alphaTransitionAmount < 1f) { var alphaSmoothTransition = MathUtilsExt.SmoothInOutLerpFloat(alphaTransitionAmount); var positionSmoothTransition = MathUtilsExt.SmoothInOutLerpFloat(positionTransitionAmount); m_CanvasGroup.alpha = Mathf.Lerp(currentAlpha, targetAlpha, alphaSmoothTransition); textTransform.localPosition = Vector3.Lerp(textCurrentLocalPosition, textTargetLocalPosition, positionSmoothTransition); alphaTransitionAmount += Time.deltaTime * transitionSubtractMultiplier; positionTransitionAmount += alphaTransitionAmount * 1.35f; yield return(null); } textTransform.localPosition = textTargetLocalPosition; m_CanvasGroup.alpha = targetAlpha; m_VisibilityCoroutine = null; }
/// <summary> /// Performs the animated beginning of a button's highlighted state /// </summary> IEnumerator BeginHighlight() { this.StopCoroutine(ref m_IconHighlightCoroutine); m_IconHighlightCoroutine = StartCoroutine(IconContainerContentsBeginHighlight()); var transitionAmount = Time.deltaTime; var currentGradientPair = GetMaterialColors(); var targetGradientPair = highlightGradientPair; var currentLocalScale = m_ContentContainer.localScale; var highlightedLocalScale = m_HighlightContentContainerLocalScale; var highlightDuration = m_BeginHighlightDuration; while (transitionAmount < highlightDuration) // Skip while look if user has set the m_BeginHighlightDuration to a value at or below zero { var shapedTransitionAmount = MathUtilsExt.SmoothInOutLerpFloat(transitionAmount += Time.unscaledDeltaTime / highlightDuration); m_ContentContainer.localScale = Vector3.Lerp(currentLocalScale, highlightedLocalScale, shapedTransitionAmount); currentGradientPair = GradientPair.Lerp(currentGradientPair, targetGradientPair, shapedTransitionAmount); SetMaterialColors(currentGradientPair); yield return(null); } SetMaterialColors(targetGradientPair); m_ContentContainer.localScale = highlightedLocalScale; m_HighlightCoroutine = null; }
/// <summary> /// Performs the animated ending of a button's highlighted state /// </summary> IEnumerator EndHighlight() { this.StopCoroutine(ref m_IconHighlightCoroutine); m_IconHighlightCoroutine = StartCoroutine(IconContainerContentsEndHighlight()); var transitionAmount = Time.deltaTime; var originalGradientPair = GetMaterialColors(); var targetGradientPair = normalGradientPair; var currentLocalScale = m_ContentContainer.localScale; var targetScale = m_OriginalContentContainerLocalScale; var highlightDuration = m_EndHighlightDuration > 0f ? m_EndHighlightDuration : 0.01f; // Add sane default if highlight duration is zero while (transitionAmount < highlightDuration) { var shapedTransitionAmount = MathUtilsExt.SmoothInOutLerpFloat(transitionAmount += Time.unscaledDeltaTime / highlightDuration); var transitioningGradientPair = GradientPair.Lerp(originalGradientPair, targetGradientPair, shapedTransitionAmount); SetMaterialColors(transitioningGradientPair); m_ContentContainer.localScale = Vector3.Lerp(currentLocalScale, targetScale, shapedTransitionAmount); yield return(null); } SetMaterialColors(normalGradientPair); m_ContentContainer.localScale = targetScale; m_HighlightCoroutine = null; }
IEnumerator AnimatePulseColor() { const float kTargetDuration = 1f; m_PulseDuration = 0f; var currentColor = m_Icon.color; while (m_PulseDuration < kTargetDuration) { var shapedDuration = MathUtilsExt.SmoothInOutLerpFloat(m_PulseDuration / kTargetDuration); m_Icon.color = Color.Lerp(currentColor, m_PulseColor, shapedDuration); m_PulseDuration += Time.unscaledDeltaTime * 5; yield return(null); } while (m_PulseDuration > 0f) { var shapedDuration = MathUtilsExt.SmoothInOutLerpFloat(m_PulseDuration / kTargetDuration); m_Icon.color = Color.Lerp(m_VisibleColor, m_PulseColor, shapedDuration); m_PulseDuration -= Time.unscaledDeltaTime * 2; yield return(null); } m_Icon.color = m_VisibleColor; m_PulseDuration = 0f; }
IEnumerator AnimateVisibility(bool show = true) { const float kSpeedScalar = 8f; var targetPosition = show ? (moveToAlternatePosition ? m_AlternateLocalPosition : m_OriginalLocalPosition) : Vector3.zero; var targetScale = show ? (moveToAlternatePosition ? m_OriginalLocalScale : m_OriginalLocalScale * k_AlternateLocalScaleMultiplier) : Vector3.zero; var currentPosition = transform.localPosition; var currentIconScale = m_IconContainer.localScale; var targetIconContainerScale = show ? m_OriginalIconContainerLocalScale : Vector3.zero; var transitionAmount = 0f; var currentScale = transform.localScale; while (transitionAmount < 1) { var shapedAmount = MathUtilsExt.SmoothInOutLerpFloat(transitionAmount += Time.unscaledDeltaTime * kSpeedScalar); m_IconContainer.localScale = Vector3.Lerp(currentIconScale, targetIconContainerScale, shapedAmount); transform.localPosition = Vector3.Lerp(currentPosition, targetPosition, shapedAmount); transform.localScale = Vector3.Lerp(currentScale, targetScale, shapedAmount); yield return(null); } m_IconContainer.localScale = targetIconContainerScale; transform.localScale = targetScale; transform.localPosition = targetPosition; m_VisibilityCoroutine = null; }
IEnumerator AnimateHideAndDestroy() { this.StopCoroutine(ref m_PositionCoroutine); this.StopCoroutine(ref m_HighlightCoroutine); this.StopCoroutine(ref m_ActivatorMoveCoroutine); this.StopCoroutine(ref m_HoverCheckCoroutine); this.StopCoroutine(ref m_SecondaryButtonVisibilityCoroutine); this.HideTooltip(this); const int kDurationScalar = 3; var duration = 0f; var currentScale = transform.localScale; var targetScale = Vector3.zero; while (duration < 1) { var durationShaped = Mathf.Pow(MathUtilsExt.SmoothInOutLerpFloat(duration += Time.unscaledDeltaTime * kDurationScalar), 4); transform.localScale = Vector3.Lerp(currentScale, targetScale, durationShaped); yield return(null); } transform.localScale = targetScale; m_VisibilityCoroutine = null; ObjectUtils.Destroy(gameObject, 0.1f); }
IEnumerator MoveToLocation(Vector3 targetPosition, Vector3 targetScale) { const float kPrimaryButtonUIAlternatePositionScalar = 0.65f; const int kDurationMultiplier = 6; const int kShapeMultiplier = 4; var currentPosition = transform.localPosition; var currentScale = transform.localScale; var currentPrimaryButtonUIContainerLocalScale = m_OrderedButtons[0].primaryUIContentContainerLocalScale; var targetPrimaryButtonUIContainerLocalScale = Vector3.one * (m_MoveToAlternatePosition ? kPrimaryButtonUIAlternatePositionScalar : 1f); var duration = 0f; while (duration < 1) { duration += Time.unscaledDeltaTime * kDurationMultiplier; var durationShaped = Mathf.Pow(MathUtilsExt.SmoothInOutLerpFloat(duration), kShapeMultiplier); transform.localScale = Vector3.Lerp(currentScale, targetScale, durationShaped); transform.localPosition = Vector3.Lerp(currentPosition, targetPosition, durationShaped); var newPrimaryButtonScale = Vector3.Lerp(currentPrimaryButtonUIContainerLocalScale, targetPrimaryButtonUIContainerLocalScale, durationShaped); for (int i = 0; i < m_OrderedButtons.Count; ++i) { m_OrderedButtons[i].primaryUIContentContainerLocalScale = newPrimaryButtonScale; } yield return(null); } transform.localScale = targetScale; transform.localPosition = targetPosition; m_MoveCoroutine = null; }
IEnumerator AnimateVisibility(bool visible, Action <PolyGridItem> callback) { var currentTime = 0f; // Item should always be at a scale of zero before becoming visible if (visible) { transform.localScale = Vector3.zero; } else { data.modelImportCompleted -= OnModelImportCompleted; data.thumbnailImportCompleted -= OnThumbnailImportCompleted; } var currentScale = transform.localScale; var targetScale = visible ? m_IconScale * scaleFactor : Vector3.zero; while (currentTime < k_TransitionDuration) { currentTime += Time.deltaTime; transform.localScale = Vector3.Lerp(currentScale, targetScale, MathUtilsExt.SmoothInOutLerpFloat(currentTime / k_TransitionDuration)); yield return(null); } transform.localScale = targetScale; if (callback != null) { callback(this); } m_VisibilityCoroutine = null; }
IEnumerator AnimateReturnToPreviousMenuLevelVisuals(bool visible) { if (visible) { this.Pulse(Node.None, m_HighlightUIElementPulse); } m_BackButton.highlighted = visible; m_BackButtonVisualsContainer.SetActive(true); const float kArrowsSlightZOffset = -0.02f; var currentArrowsContainerLocalPosition = m_SurroundingArrowsContainer.localPosition; var targetArrowsContainerLocalPosition = visible ? new Vector3(0f, 0f, kArrowsSlightZOffset) : m_OriginalSurroundingArrowsContainerLocalPosition; const string kBlurPropertyName = "_Blur"; const float kHiddenTextLocalPosition = 0.125f; const float kBlurIncreaseScalar = 10f; var currentAlpha = m_BackButtonVisualsCanvasGroup.alpha; var targetAlpha = visible ? 1f : 0f; var transitionAmount = 0f; var transitionSpeedMultiplier = visible ? 10f : 5f; // Faster when revealing, slower when hiding var currentTextLocalPosition = m_ReturnToPreviousLevelText.localPosition; var targetTextLocalPosition = visible ? Vector3.zero : new Vector3(0f, 0f, kHiddenTextLocalPosition); // recede when hiding while (transitionAmount < 1f) { var smoothTransition = MathUtilsExt.SmoothInOutLerpFloat(transitionAmount); var newAlpha = Mathf.Lerp(currentAlpha, targetAlpha, smoothTransition); m_BackButtonVisualsCanvasGroup.alpha = newAlpha; m_ReturnToPreviousLevelText.localPosition = Vector3.Lerp(currentTextLocalPosition, targetTextLocalPosition, smoothTransition); m_SurroundingArrowsContainer.localPosition = Vector3.Lerp(currentArrowsContainerLocalPosition, targetArrowsContainerLocalPosition, smoothTransition); m_ReturnToPreviousBackgroundMaterial.SetFloat(kBlurPropertyName, newAlpha * kBlurIncreaseScalar); transitionAmount += Time.deltaTime * transitionSpeedMultiplier; // Perform the sustained pulse here, in order to have a proper blending between the initial hover pulse, and the sustained (on hover) pulse this.Pulse(Node.None, m_SustainedHoverUIElementPulse); yield return(null); } m_ReturnToPreviousLevelText.localPosition = targetTextLocalPosition; m_SurroundingArrowsContainer.localPosition = targetArrowsContainerLocalPosition; m_BackButtonVisualsContainer.SetActive(visible); m_BackButtonVisualsCanvasGroup.alpha = targetAlpha; while (visible) { // Continuously looping when visible is intentional // Maintain the sustained pulse while hovering the back button // When disabling the return-to-previous UI, the coroutine restart will stop the pulse this.Pulse(Node.None, m_SustainedHoverUIElementPulse); yield return(null); } m_ReturnToPreviousLevelTransitionCoroutine = null; }
IEnumerator ShowScrollVisuals() { // Display two arrows denoting the positive and negative directions allow for spatial scrolling, as defined by the drag vector scrollArrowsVisible = true; preScrollArrowsVisible = false; secondaryArrowsVisible = false; transform.localScale = Vector3.one * this.GetViewerScale(); m_ScrollVisualsTransform.LookAt(m_ScrollVisualsRotation, Vector3.up); // Scroll arrows should face/billboard the user. m_ScrollVisualsCanvasGroup.alpha = 1f; // remove m_ScrollVisualsDragTargetArrowTransform.localPosition = Vector3.zero; const float kTargetDuration = 1f; var currentDuration = 0f; var currentLocalScale = m_ScrollVisualsTransform.localScale; var targetLocalScale = Vector3.one; var currentAlpha = m_ScrollVisualsCanvasGroup.alpha; var secondArrowCurrentPosition = m_ScrollVisualsDragTargetArrowTransform.position; while (currentDuration < kTargetDuration) { var shapedDuration = MathUtilsExt.SmoothInOutLerpFloat(currentDuration / kTargetDuration); m_ScrollVisualsCanvasGroup.alpha = Mathf.Lerp(currentAlpha, 1f, shapedDuration); // Only validate movement in the initial direction with which the user began the drag m_ScrollVisualsDragTargetArrowTransform.position = Vector3.Lerp(secondArrowCurrentPosition, scrollVisualsDragThresholdTriggerPosition, shapedDuration); currentDuration += Time.unscaledDeltaTime * 2f; m_ScrollVisualsDragTargetArrowTransform.LookAt(m_ScrollVisualsDragTargetArrowTransform.position - m_ScrollVisualsTransform.position); m_ScrollVisualsDragTargetArrowTransform.LookAt(m_ScrollVisualsTransform.position - m_ScrollVisualsDragTargetArrowTransform.position); m_ScrollVisualsTransform.localScale = Vector3.Lerp(currentLocalScale, targetLocalScale, shapedDuration); var scrollVisualsDragTargetArrowTransformOrigin = m_ScrollVisualsTransform.position; var scrollVisualsDragTargetArrowTransformDestination = m_ScrollVisualsDragTargetArrowTransform.position; if (centeredScrolling) { Vector3 offset = (scrollVisualsDragTargetArrowTransformOrigin - scrollVisualsDragTargetArrowTransformDestination) * -1; var distance = (scrollVisualsDragTargetArrowTransformOrigin - scrollVisualsDragTargetArrowTransformDestination).magnitude; // Increase the initial line position separation for scrolls of a smaller magnitude // This mandates a sully visible scroll line, regardless of scroll start/end magnitude var distanceShaped = Mathf.Clamp(2 - distance * 0.175f, 0.75f, 2f); offset *= distanceShaped; scrollVisualsDragTargetArrowTransformOrigin -= offset; scrollVisualsDragTargetArrowTransformDestination += offset; } var lineRendererPositions = new[] { scrollVisualsDragTargetArrowTransformOrigin, scrollVisualsDragTargetArrowTransformDestination }; m_ScrollHintLine.Positions = lineRendererPositions; m_ScrollHintLine.LineWidth = shapedDuration * this.GetViewerScale(); this.Pulse(controllingNode, m_ScrollBarDefineHapticPulse, 1f, 1f + 8 * currentDuration); yield return(null); } m_ScrollVisualsCanvasGroup.alpha = 1f; }
IEnumerator ShowSecondaryButton() { // Don't perform additional animated visuals if already in a fully revealed state if (Mathf.Approximately(m_CloseButtonContainerCanvasGroup.alpha, 1f)) { m_SecondaryButtonVisibilityCoroutine = null; yield break; } const float kSecondaryButtonFrameVisibleBlendShapeWeight = 16f; // The extra amount of the frame to show on hover-before the full reveal of the secondary button const float kTargetDuration = 1f; const int kIntroDurationMultiplier = 10; var currentVisibilityAmount = m_FrameRenderer.GetBlendShapeWeight(1); var currentDuration = 0f; while (currentDuration < kTargetDuration) { var shapedAmount = MathUtilsExt.SmoothInOutLerpFloat(currentDuration += Time.unscaledDeltaTime * kIntroDurationMultiplier); m_FrameRenderer.SetBlendShapeWeight(1, Mathf.Lerp(currentVisibilityAmount, kSecondaryButtonFrameVisibleBlendShapeWeight, shapedAmount)); yield return(null); } const float kDelayBeforeSecondaryButtonReveal = 0.25f; currentDuration = 0f; // Reset current duration while (currentDuration < kDelayBeforeSecondaryButtonReveal) { currentDuration += Time.unscaledDeltaTime; yield return(null); } const float kFrameSecondaryButtonVisibleBlendShapeWeight = 61f; const float kSecondaryButtonVisibleBlendShapeWeight = 46f; const int kDurationMultiplier = 25; this.StopCoroutine(ref m_HighlightCoroutine); var currentSecondaryButtonVisibilityAmount = m_CloseInsetMeshRenderer.GetBlendShapeWeight(0); var currentSecondaryCanvasGroupAlpha = m_CloseButtonContainerCanvasGroup.alpha; currentVisibilityAmount = m_FrameRenderer.GetBlendShapeWeight(1); currentDuration = 0f; while (currentDuration < 1f) { var shapedAmount = MathUtilsExt.SmoothInOutLerpFloat(currentDuration += Time.unscaledDeltaTime * kDurationMultiplier); m_FrameRenderer.SetBlendShapeWeight(1, Mathf.Lerp(currentVisibilityAmount, kFrameSecondaryButtonVisibleBlendShapeWeight, shapedAmount)); m_CloseInsetMeshRenderer.SetBlendShapeWeight(0, Mathf.Lerp(currentSecondaryButtonVisibilityAmount, kSecondaryButtonVisibleBlendShapeWeight, shapedAmount)); m_CloseInsetMaskMeshRenderer.SetBlendShapeWeight(0, Mathf.Lerp(currentSecondaryButtonVisibilityAmount, kSecondaryButtonVisibleBlendShapeWeight, shapedAmount)); m_CloseButtonContainerCanvasGroup.alpha = Mathf.Lerp(currentSecondaryCanvasGroupAlpha, 1f, shapedAmount); yield return(null); } m_SecondaryButtonVisibilityCoroutine = null; }
IEnumerator AnimateShow() { UpdateRadialSlots(); for (int i = 0; i < m_RadialMenuSlots.Count; ++i) { if (i < m_Actions.Count) { m_RadialMenuSlots[i].visible = true; } else { m_RadialMenuSlots[i].visible = false; } } semiTransparent = false; semiTransparent = true; const float kSpeedScalar = 8f; var revealAmount = 0f; var hiddenSlotRotation = RadialMenuSlot.hiddenLocalRotation; while (revealAmount < 1) { revealAmount += Time.unscaledDeltaTime * kSpeedScalar; var shapedAmount = MathUtilsExt.SmoothInOutLerpFloat(revealAmount); for (int i = 0; i < m_RadialMenuSlots.Count; ++i) { if (i < m_Actions.Count) { m_RadialMenuSlots[i].transform.localRotation = Quaternion.Lerp(hiddenSlotRotation, m_RadialMenuSlots[i].visibleLocalRotation, shapedAmount); m_RadialMenuSlots[i].CorrectIconRotation(); } } yield return(null); } revealAmount = 0; while (revealAmount < 1) { revealAmount += Time.deltaTime; yield return(null); } m_VisibilityCoroutine = null; }
IEnumerator AnimatePosition(int orderPosition) { primaryButtonCollidersEnabled = false; secondaryButtonCollidersEnabled = false; this.RestartCoroutine(ref m_SecondaryButtonVisibilityCoroutine, HideSecondaryButton()); visible = orderPosition != -1; const float kTimeScalar = 6f; const float kCenterLocationAmount = 0.5f; const float kCircularRange = 360f; const int kDurationShapeAmount = 3; var rotationSpacing = kCircularRange / maxButtonCount; // dividend should be the count of tool buttons showing at this time // Center the MainMenu & Active tool buttons at the bottom of the RadialMenu var phaseOffset = orderPosition > -1 ? rotationSpacing * kCenterLocationAmount - (visibleButtonCount(m_ToolType) * kCenterLocationAmount) * rotationSpacing : 0; var targetRotation = orderPosition > -1 ? Quaternion.AngleAxis(phaseOffset + rotationSpacing * Mathf.Max(0f, orderPosition), Vector3.down) : Quaternion.identity; var duration = 0f; var currentCanvasAlpha = m_IconContainerCanvasGroup.alpha; var targetCanvasAlpha = orderPosition > -1 ? 1f : 0f; var currentRotation = transform.localRotation; var positionWait = 1f; while (duration < 1) { duration += Time.unscaledDeltaTime * kTimeScalar * positionWait; var durationShaped = Mathf.Pow(MathUtilsExt.SmoothInOutLerpFloat(duration), kDurationShapeAmount); transform.localRotation = Quaternion.Lerp(currentRotation, targetRotation, durationShaped); m_IconContainerCanvasGroup.alpha = Mathf.Lerp(currentCanvasAlpha, targetCanvasAlpha, durationShaped); CorrectIconRotation(); yield return(null); } transform.localRotation = targetRotation; CorrectIconRotation(); primaryButtonCollidersEnabled = orderPosition > -1; secondaryButtonCollidersEnabled = orderPosition > -1; m_PositionCoroutine = null; if (implementsSecondaryButton && orderPosition > -1 && m_GradientButton.highlighted) { this.RestartCoroutine(ref m_SecondaryButtonVisibilityCoroutine, ShowSecondaryButton()); } }
IEnumerator AnimateTooltipVisualsVisibility(bool fadeIn) { var initialWaitBeforeDisplayDuration = fadeIn ? 1f : 0f; var currentAlpha = fadeIn ? 0f : m_TooltipVisualsCanvasGroup.alpha; var targetAlpha = fadeIn ? 1f : 0f; var alphaTransitionAmount = 0f; var currentSize = m_RectTransform.sizeDelta; var targetSize = fadeIn ? m_ExpandedTooltipDisplaySize : m_OriginalSize; var sizeTransitionAmount = 0f; var transitionDuration = fadeIn ? m_TooltipTransitionDuration : m_TooltipTransitionDuration * 0.2f; // faster fade out var transitionMultiplier = 1f / transitionDuration; while (initialWaitBeforeDisplayDuration > 0f) { initialWaitBeforeDisplayDuration -= Time.unscaledDeltaTime; yield return(null); } if (fadeIn) { this.Pulse(Node.None, m_TooltipDisplayPulse); } var currentBordersLocalScale = m_TopBorder.localScale; while (alphaTransitionAmount < 1f) { var alphaSmoothTransition = MathUtilsExt.SmoothInOutLerpFloat(alphaTransitionAmount); var newBorderLocalScale = Vector3.Lerp(currentBordersLocalScale, m_OriginalBordersLocalScale, alphaSmoothTransition); m_TopBorder.localScale = newBorderLocalScale; m_BottomBorder.localScale = newBorderLocalScale; m_TooltipVisualsCanvasGroup.alpha = Mathf.Lerp(currentAlpha, targetAlpha, alphaSmoothTransition); m_RectTransform.sizeDelta = Vector2.Lerp(currentSize, targetSize, sizeTransitionAmount); alphaTransitionAmount += Time.deltaTime * transitionMultiplier; sizeTransitionAmount += alphaTransitionAmount * 1.35f; LayoutRebuilder.ForceRebuildLayoutImmediate(m_TooltipVisualsCanvasGroup.transform.parent as RectTransform); yield return(null); } m_TooltipVisualsCanvasGroup.alpha = targetAlpha; m_RectTransform.sizeDelta = targetSize; m_TopBorder.localScale = m_OriginalBordersLocalScale; m_BottomBorder.localScale = m_OriginalBordersLocalScale; m_TooltipVisualsVisibilityCoroutine = null; }
IEnumerator AnimateHighlight(bool isHighlighted) { this.RestartCoroutine(ref m_TooltipVisualsVisibilityCoroutine, AnimateTooltipVisualsVisibility(isHighlighted)); var currentAlpha = m_CanvasGroup.alpha; var targetAlpha = 1f; var alphaTransitionAmount = 0f; var textTransform = m_Text.transform; var textCurrentLocalPosition = textTransform.localPosition; var textTargetLocalPosition = isHighlighted ? new Vector3(m_TextOriginalLocalPosition.x, m_TextOriginalLocalPosition.y, m_HighlightedZOffset) : m_TextOriginalLocalPosition; var positionTransitionAmount = 0f; var currentTextLocalScale = textTransform.localScale; var targetTextLocalScale = isHighlighted ? Vector3.one * 1.15f : Vector3.one; var currentBackgroundColor = m_BackgroundImage.color; var targetBackgroundColor = isHighlighted ? Color.black : m_OriginalBackgroundColor; var currentBordersLocalScale = m_TopBorder.localScale; var targetBordersLocalScale = isHighlighted ? new Vector3(m_OriginalBordersLocalScale.x * 0.65f, m_OriginalBordersLocalScale.y * 8, m_OriginalBordersLocalScale.z) : m_OriginalBordersLocalScale; var currentBordersCanvasGroupAlpha = m_BordersCanvasGroup.alpha; var targetBordersCanvasGroupAlpha = isHighlighted ? 1f : m_BordersOriginalAlpha; var speedMultiplier = isHighlighted ? 3f : 6f; while (alphaTransitionAmount < 1f) { var alphaSmoothTransition = MathUtilsExt.SmoothInOutLerpFloat(alphaTransitionAmount); var positionSmoothTransition = MathUtilsExt.SmoothInOutLerpFloat(positionTransitionAmount); m_CanvasGroup.alpha = Mathf.Lerp(currentAlpha, targetAlpha, alphaSmoothTransition * 1.5f); textTransform.localPosition = Vector3.Lerp(textCurrentLocalPosition, textTargetLocalPosition, positionSmoothTransition); textTransform.localScale = Vector3.Lerp(currentTextLocalScale, targetTextLocalScale, alphaSmoothTransition); alphaTransitionAmount += Time.deltaTime * speedMultiplier; positionTransitionAmount += alphaTransitionAmount * 1.35f; m_BackgroundImage.color = Color.Lerp(currentBackgroundColor, targetBackgroundColor, alphaSmoothTransition * 4); m_TopBorder.localScale = Vector3.Lerp(currentBordersLocalScale, targetBordersLocalScale, alphaSmoothTransition); m_BottomBorder.localScale = Vector3.Lerp(currentBordersLocalScale, targetBordersLocalScale, alphaSmoothTransition); m_BordersCanvasGroup.alpha = Mathf.Lerp(currentBordersCanvasGroupAlpha, targetBordersCanvasGroupAlpha, alphaSmoothTransition); yield return(null); } m_BordersCanvasGroup.alpha = targetBordersCanvasGroupAlpha; textTransform.localPosition = textTargetLocalPosition; textTransform.localScale = targetTextLocalScale; m_BackgroundImage.color = targetBackgroundColor; m_CanvasGroup.alpha = targetAlpha; m_TopBorder.localScale = targetBordersLocalScale; m_BottomBorder.localScale = targetBordersLocalScale; m_VisibilityCoroutine = null; }
IEnumerator AnimateHighlight() { const float kLargerSizeScalar = 2.5f; var currentBackButtonIconSize = transform.localScale; var targetBackButtonIconLocalScale = m_Highlighted ? m_VisibleLocalScale * kLargerSizeScalar : m_VisibleLocalScale; // Larger if highlighted var transitionAmount = 0f; var transitionSpeedMultiplier = m_Highlighted ? 10f : 5f; // Faster when revealing, slower when hiding while (transitionAmount < 1) { var smoothTransition = MathUtilsExt.SmoothInOutLerpFloat(transitionAmount); transform.localScale = Vector3.Lerp(currentBackButtonIconSize, targetBackButtonIconLocalScale, smoothTransition); transitionAmount += Time.unscaledDeltaTime * transitionSpeedMultiplier; yield return(null); } transform.localScale = targetBackButtonIconLocalScale; m_AllowInteractionCoroutine = null; }
IEnumerator AnimateInteractionState() { var allowInteraction = m_ButtonImage.raycastTarget; var currentLocalScale = transform.localScale; var targetLocalScale = allowInteraction ? m_VisibleLocalScale : Vector3.zero; var transitionAmount = 0f; var transitionSpeedMultiplier = allowInteraction ? 3f : 4f; // faster hide, slower reveal while (transitionAmount < 1) { var smoothTransition = MathUtilsExt.SmoothInOutLerpFloat(transitionAmount); transform.localScale = Vector3.Lerp(currentLocalScale, targetLocalScale, smoothTransition); transitionAmount += Time.unscaledDeltaTime * transitionSpeedMultiplier; yield return(null); } transform.localScale = targetLocalScale; m_AllowInteractionCoroutine = null; }
IEnumerator AnimateVisibility(bool show = true) { var currentDuration = 0f; float targetDuration; var currentLocalScale = m_IconTransform.localScale; var targetLocalScale = show ? m_VisibleLocalScale : k_HiddenScale; // Only perform this wait if showing/revealing, not hiding if (show && currentLocalScale == k_HiddenScale) { // Only perform delay if fully hidden; otherwise resume showing targetDuration = Random.Range(0.125f, 0.175f); // Set an initial random wait duration while (currentDuration < targetDuration) { currentDuration += Time.unscaledDeltaTime; yield return(null); } } currentDuration = 0f; targetDuration = show ? m_ShowDuration : m_HideDuration + (m_SlightlyRandomizeHideDuration ? 0f : Random.Range(0.125f, 0.2f)); // Set an initial random wait duration const int kAdditionalDurationShaping = 4; const int kAdditionalHideSpeedScalar = 3; var currentColor = m_Icon.color; var targetColor = show ? m_VisibleColor : m_HiddenColor; while (currentDuration < targetDuration) { var shapedDuration = MathUtilsExt.SmoothInOutLerpFloat(currentDuration / targetDuration); shapedDuration = Mathf.Pow(shapedDuration, kAdditionalDurationShaping); var colorLerpAmount = show ? shapedDuration : currentDuration * kAdditionalHideSpeedScalar; m_IconTransform.localScale = Vector3.Lerp(currentLocalScale, targetLocalScale, shapedDuration); m_Icon.color = Color.Lerp(currentColor, targetColor, colorLerpAmount); currentDuration += Time.unscaledDeltaTime; yield return(null); } m_IconTransform.localScale = targetLocalScale; }
IEnumerator HideSecondaryButton() { const float kMaxDelayDuration = 0.125f; var delayDuration = 0f; while (delayDuration < kMaxDelayDuration) { delayDuration += Time.unscaledDeltaTime; yield return(null); } const float kSecondaryButtonHiddenBlendShapeWeight = 100f; const int kDurationMultiplier = 12; var currentVisibilityAmount = m_FrameRenderer.GetBlendShapeWeight(1); var currentSecondaryButtonVisibilityAmount = m_CloseInsetMeshRenderer.GetBlendShapeWeight(0); var currentSecondaryCanvasGroupAlpha = m_CloseButtonContainerCanvasGroup.alpha; var amount = 0f; while (amount < 1f) { yield return(null); if (m_CloseButton.highlighted) { m_SecondaryButtonVisibilityCoroutine = null; yield break; } this.StopCoroutine(ref m_HighlightCoroutine); var shapedAmount = MathUtilsExt.SmoothInOutLerpFloat(amount += Time.unscaledDeltaTime * kDurationMultiplier); m_FrameRenderer.SetBlendShapeWeight(1, Mathf.Lerp(currentVisibilityAmount, 0f, shapedAmount)); m_CloseInsetMeshRenderer.SetBlendShapeWeight(0, Mathf.Lerp(currentSecondaryButtonVisibilityAmount, kSecondaryButtonHiddenBlendShapeWeight, shapedAmount)); m_CloseInsetMaskMeshRenderer.SetBlendShapeWeight(0, Mathf.Lerp(currentSecondaryButtonVisibilityAmount, kSecondaryButtonHiddenBlendShapeWeight, shapedAmount)); m_CloseButtonContainerCanvasGroup.alpha = Mathf.Lerp(currentSecondaryCanvasGroupAlpha, 0f, shapedAmount); } m_SecondaryButtonVisibilityCoroutine = null; }
IEnumerator AnimateMoveActivatorButton(bool moveToAlternatePosition = true) { const float kSpeedDecreaseScalar = 0.275f; var amount = 0f; var currentPosition = transform.localPosition; var targetPosition = moveToAlternatePosition ? m_AlternateLocalPosition : m_OriginalLocalPosition; var currentLocalScale = transform.localScale; var targetLocalScale = moveToAlternatePosition ? m_OriginalLocalScale : m_OriginalLocalScale * k_AlternateLocalScaleMultiplier; var speed = moveToAlternatePosition ? 5f : 4.5f; // Perform faster is returning to original position speed += (order + 1) * kSpeedDecreaseScalar; while (amount < 1f) { var shapedAmount = MathUtilsExt.SmoothInOutLerpFloat(amount += Time.unscaledDeltaTime * speed); transform.localPosition = Vector3.Lerp(currentPosition, targetPosition, shapedAmount); transform.localScale = Vector3.Lerp(currentLocalScale, targetLocalScale, shapedAmount); yield return(null); } transform.localPosition = targetPosition; transform.localScale = targetLocalScale; m_ActivatorMoveCoroutine = null; }
IEnumerator HideScrollVisuals() { scrollArrowsVisible = false; const float kTargetDuration = 1f; var hiddenLocalScale = Vector3.zero; var currentDuration = 0f; var currentLocalScale = m_ScrollVisualsTransform.localScale; var currentAlpha = m_ScrollVisualsCanvasGroup.alpha; while (currentDuration < kTargetDuration) { var shapedDuration = MathUtilsExt.SmoothInOutLerpFloat(currentDuration / kTargetDuration); m_ScrollVisualsTransform.localScale = Vector3.Lerp(currentLocalScale, hiddenLocalScale, shapedDuration); m_ScrollVisualsCanvasGroup.alpha = Mathf.Lerp(currentAlpha, 0f, shapedDuration); currentDuration += Time.unscaledDeltaTime * 3.5f; m_ScrollHintLine.LineWidth = (1 - shapedDuration) * this.GetViewerScale(); yield return(null); } m_ScrollVisualsCanvasGroup.alpha = 0; m_ScrollVisualsTransform.localScale = hiddenLocalScale; }
IEnumerator AnimateEngage(bool engaging) { var undoStartingColor = m_UndoButtonMaterial.GetColor(k_MaterialColorProperty); var redoStartingColor = m_RedoButtonMaterial.GetColor(k_MaterialColorProperty); var targetColor = Color.white; targetColor.a = engaging ? k_EngagedAlpha : k_DisengagedAlpha; var transitionAmount = 0f; var currentDuration = 0f; while (transitionAmount < 1f) { var smoothAmont = MathUtilsExt.SmoothInOutLerpFloat(transitionAmount); m_UndoButtonMaterial.SetColor(k_MaterialColorProperty, Color.Lerp(undoStartingColor, targetColor, smoothAmont)); m_RedoButtonMaterial.SetColor(k_MaterialColorProperty, Color.Lerp(redoStartingColor, targetColor, smoothAmont)); currentDuration += Time.deltaTime; transitionAmount = currentDuration / k_EngageAnimationDuration; yield return(null); } m_UndoButtonMaterial.SetColor(k_MaterialColorProperty, targetColor); m_RedoButtonMaterial.SetColor(k_MaterialColorProperty, targetColor); }
IEnumerator AnimateTopAndBottomCenterBackgroundBorders(bool visible) { var currentAlpha = m_HomeSectionCanvasGroup.alpha; var targetAlpha = visible ? 1f : 0f; var transitionAmount = 0f; const float kTransitionSubtractMultiplier = 5f; while (transitionAmount < 1f) { var smoothTransition = MathUtilsExt.SmoothInOutLerpFloat(transitionAmount); var newAlpha = Mathf.Lerp(currentAlpha, targetAlpha, smoothTransition); m_HomeSectionCanvasGroup.alpha = newAlpha; m_HomeTextBackgroundInnerCanvasGroup.alpha = newAlpha; m_HomeSectionTitlesBackgroundBorderCanvasGroup.alpha = newAlpha; transitionAmount += Time.deltaTime * kTransitionSubtractMultiplier; yield return(null); } m_HomeSectionTitlesBackgroundBorderCanvasGroup.alpha = targetAlpha; m_HomeTextBackgroundInnerCanvasGroup.alpha = targetAlpha; m_HomeSectionCanvasGroup.alpha = targetAlpha; m_HomeSectionTitlesBackgroundBordersTransitionCoroutine = null; }
void UpdateVisuals(ITooltip tooltip, TooltipData tooltipData, float lerp) { var target = tooltipData.GetTooltipTarget(tooltip); var tooltipUI = tooltipData.tooltipUI; var placement = tooltipData.placement; var orientationWeight = tooltipData.orientationWeight; var tooltipTransform = tooltipUI.transform; lerp = MathUtilsExt.SmoothInOutLerpFloat(lerp); // shape the lerp for better presentation var transitionLerp = MathUtilsExt.SmoothInOutLerpFloat(1.0f - Mathf.Clamp01((Time.time - tooltipData.transitionTime) / k_ChangeTransitionDuration)); var viewerScale = this.GetViewerScale(); tooltipTransform.localScale = m_TooltipScale * lerp * viewerScale; // Adjust for alignment var offset = GetTooltipOffset(tooltipUI, placement, tooltipData.transitionOffset * transitionLerp); // The rectTransform expansion is handled in the Tooltip dynamically, based on alignment & text length var rotationOffset = Quaternion.identity; var camTransform = CameraUtils.GetMainCamera().transform; if (Vector3.Dot(camTransform.forward, target.forward) < 0) { rotationOffset *= k_FlipYRotation; } if (Vector3.Dot(camTransform.up, target.up) + orientationWeight < 0) { rotationOffset *= k_FlipZRotation; tooltipData.orientationWeight = -k_TextOrientationWeight; } else { tooltipData.orientationWeight = k_TextOrientationWeight; } MathUtilsExt.SetTransformOffset(target, tooltipTransform, offset * lerp, rotationOffset); if (placement != null) { //TODO: Figure out why rect gives us different height/width than GetWorldCorners tooltipUI.rectTransform.GetWorldCorners(k_Corners); var bottomLeft = k_Corners[0]; var halfWidth = (bottomLeft - k_Corners[2]).magnitude * 0.5f; var halfHeight = (bottomLeft - k_Corners[1]).magnitude * 0.5f; var source = placement.tooltipSource; var toSource = tooltipTransform.InverseTransformPoint(source.position); // Position spheres: one at source, one on the closest edge of the tooltip var spheres = tooltipUI.spheres; spheres[0].position = source.position; var attachedSphere = spheres[1]; var boxSlope = halfHeight / halfWidth; var toSourceSlope = Mathf.Abs(toSource.y / toSource.x); var parentScale = attachedSphere.parent.lossyScale; halfHeight *= Mathf.Sign(toSource.y) / parentScale.x; halfWidth *= Mathf.Sign(toSource.x) / parentScale.y; attachedSphere.localPosition = toSourceSlope > boxSlope ? new Vector3(0, halfHeight) : new Vector3(halfWidth, 0); // Align dotted line var attachedSpherePosition = attachedSphere.position; toSource = source.position - attachedSpherePosition; var midPoint = attachedSpherePosition + toSource * 0.5f; var dottedLine = tooltipUI.dottedLine; var length = toSource.magnitude; var uvRect = dottedLine.uvRect; var worldScale = 1 / viewerScale; uvRect.width = length * k_UVScale * worldScale; uvRect.xMin += k_UVScrollSpeed * Time.deltaTime; dottedLine.uvRect = uvRect; var dottedLineTransform = dottedLine.transform.parent.GetComponent <RectTransform>(); dottedLineTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, length / tooltipTransform.lossyScale.x); dottedLineTransform.position = midPoint; dottedLineTransform.rotation = Quaternion.LookRotation(toSource, -tooltipTransform.forward); } }
// Animate the LocalScale of the asset towards a common/unified scale // used when the asset is magnetized/attached to the proxy, after grabbing it from the asset grid IEnumerator ShowGrabbedObject() { var currentLocalScale = m_DragObject.localScale; var currentPreviewOffset = Vector3.zero; var currentPreviewRotationOffset = Quaternion.identity; if (m_PreviewObjectClone) { currentPreviewOffset = m_PreviewObjectClone.localPosition; } var currentTime = 0f; const float duration = 1f; var targetScale = Vector3.one * k_IconPreviewScale; var pivotOffset = Vector3.zero; var rotationOffset = Quaternion.AngleAxis(30, Vector3.right); if (m_PreviewObjectClone) { var viewerScale = this.GetViewerScale(); var maxComponent = m_PreviewBounds.size.MaxComponent() / viewerScale; targetScale = Vector3.one * maxComponent; // Object will preview at the same size when grabbed var previewExtents = m_PreviewBounds.extents / viewerScale; pivotOffset = m_PreviewPivotOffset / viewerScale; // If bounds are greater than offset, set to bounds if (previewExtents.y > pivotOffset.y) { pivotOffset.y = previewExtents.y; } if (previewExtents.z > pivotOffset.z) { pivotOffset.z = previewExtents.z; } if (maxComponent < k_MinPreviewScale) { // Object will be preview at the minimum scale targetScale = Vector3.one * k_MinPreviewScale; pivotOffset = pivotOffset * scaleFactor + (Vector3.up + Vector3.forward) * 0.5f * k_MinPreviewScale; } if (maxComponent > k_MaxPreviewScale) { // Object will be preview at the maximum scale targetScale = Vector3.one * k_MaxPreviewScale; pivotOffset = pivotOffset * scaleFactor + (Vector3.up + Vector3.forward) * 0.5f * k_MaxPreviewScale; } } while (currentTime < duration) { if (m_DragObject == null) { yield break; // Exit coroutine if m_GrabbedObject is destroyed before the loop is finished } currentTime += Time.deltaTime; m_DragObject.localScale = Vector3.Lerp(currentLocalScale, targetScale, MathUtilsExt.SmoothInOutLerpFloat(currentTime / duration)); if (m_PreviewObjectClone) { m_PreviewObjectClone.localPosition = Vector3.Lerp(currentPreviewOffset, pivotOffset, currentTime); m_PreviewObjectClone.localRotation = Quaternion.Lerp(currentPreviewRotationOffset, rotationOffset, currentTime); // Compensate for preview origin rotation } yield return(null); } m_DragObject.localScale = targetScale; //No need to hard-set the preview object position/rotation because they will set in OnDragging in parent class }