public void DrawMotionSpheres() { // We estimate how much we should correct our curve time by with a guess step for (int i = 0; i < m_MotionSphereCount; ++i) { var t = i / (float)m_MotionSphereCount + m_MotionSphereOffset; var motionSphere = m_MotionSpheres[i]; motionSphere.position = MathUtilsExt.CalculateCubicBezierPoint(t, m_BezierControlPoints); var motionSphereScale = visible ? (validTarget ? m_MotionSphereOriginalScale.x : 0.05f) : 0f; var smoothVelocity = 0f; const float scaleCoefficient = 4f; motionSphereScale = MathUtilsExt.SmoothDamp(motionSphere.localScale.x, motionSphereScale, ref smoothVelocity, 3f, Mathf.Infinity, Time.unscaledDeltaTime) * Mathf.Min((m_Transform.position - motionSphere.position).magnitude * scaleCoefficient / viewerScale, 1f); motionSphere.localScale = Vector3.one * motionSphereScale; motionSphere.localRotation = Quaternion.identity; // If we're not at the starting point, we apply a correction factor if (t > 0.0f) { // We have how long we *think* the curve should be var lengthEstimate = m_CurveLengthEstimate * t; // We compare that to how long our distance actually is var correctionFactor = lengthEstimate / (motionSphere.position - m_BezierControlPoints[0]).magnitude; // We then scale our time value by this correction factor var correctedTime = Mathf.Clamp01(t * correctionFactor); motionSphere.position = MathUtilsExt.CalculateCubicBezierPoint(correctedTime, m_BezierControlPoints); } } }
private IEnumerator HideMallet() { m_Open = false; var stemScale = m_StemOrigin.localScale; var startLength = m_StemOrigin.localScale.y; var currentLength = m_StemOrigin.localScale.y; // cache current length for smooth animation to target value without snapping var bulbStartScale = m_Bulb.localScale; var smoothVelocity = 0f; var currentDuration = 0f; const float kTargetDuration = 0.3f; while (currentDuration < kTargetDuration) { currentLength = MathUtilsExt.SmoothDamp(currentLength, 0f, ref smoothVelocity, kTargetDuration, Mathf.Infinity, Time.deltaTime); m_StemOrigin.localScale = new Vector3(stemScale.x, currentLength, stemScale.z); m_Bulb.transform.localPosition = new Vector3(0f, 0f, currentLength * 2f); var alpha = currentLength / startLength; m_Bulb.transform.localScale = bulbStartScale * alpha; currentDuration += Time.deltaTime; yield return(null); } m_Bulb.transform.localPosition = Vector3.zero; m_Bulb.transform.localScale = Vector3.zero; m_ShowHideCoroutine = null; }
void Update() { if (visible) { const float kMotionSphereSpeed = 0.125f; m_MotionSphereOffset = (m_MotionSphereOffset + (Time.unscaledDeltaTime * kMotionSphereSpeed)) % (1.0f / (float)m_MotionSphereCount); if (m_LastPosition != m_Transform.position || m_LastRotation != m_Transform.rotation) { DrawArc(); m_LastPosition = m_Transform.position; m_LastRotation = m_Transform.rotation; } DrawMotionSpheres(); m_RoomScaleTransform.position = MathUtilsExt.SmoothDamp(m_RoomScaleLazyPosition, m_LocatorRoot.position, ref m_MovementVelocityDelta, 0.2625f, 100f * viewerScale, Time.unscaledDeltaTime); // Since the room scale visuals are parented under the locator root it is necessary to cache the position each frame before the locator root gets updated m_RoomScaleLazyPosition = m_RoomScaleTransform.position; m_MovementMagnitudeDelta = (m_RoomScaleTransform.position - m_LocatorRoot.position).magnitude; const float kTubeHiddenDistanceThreshold = 6f; m_TubeTransform.localScale = Vector3.Lerp(m_TubeTransformOriginalScale, m_TubeTransformHiddenScale, m_MovementMagnitudeDelta / kTubeHiddenDistanceThreshold); } else if (!outOfMaxRange && m_State == State.Inactive) { ShowVisuals(); } }
IEnumerator HideDropDownContents() { const float kTargetDuration = 0.25f; var currentAlpha = m_CanvasGroup.alpha; var kTargetAlpha = 0f; var transitionAmount = 0f; var currentSpacing = m_OptionsList.spacing.y; var velocity = 0f; var currentDuration = 0f; var currentBackgroundLocalScale = m_BackgroundMeshTransform.localScale; var targetBackgroundLocalScale = new Vector3(m_BackgroundMeshTransform.localScale.x, 0f, m_BackgroundMeshTransform.localScale.z); while (currentDuration < kTargetDuration) { currentDuration += Time.unscaledDeltaTime; transitionAmount = MathUtilsExt.SmoothDamp(transitionAmount, 1f, ref velocity, kTargetDuration, Mathf.Infinity, Time.unscaledDeltaTime); m_OptionsList.spacing = new Vector2(0f, Mathf.Lerp(currentSpacing, m_HiddenDropdownItemYSpacing, transitionAmount)); m_CanvasGroup.alpha = Mathf.Lerp(currentAlpha, kTargetAlpha, transitionAmount * transitionAmount); m_BackgroundMeshTransform.localScale = Vector3.Lerp(currentBackgroundLocalScale, targetBackgroundLocalScale, transitionAmount); yield return(null); } m_OptionsPanel.gameObject.SetActive(false); m_BackgroundMeshTransform.gameObject.SetActive(false); m_HideDropdownCoroutine = null; }
IEnumerator AnimateVisibility(bool show) { if (show) { m_BorderOutlineTransform.localScale = m_BorderOutlineOriginalLocalScale; } m_CanvasGroup.interactable = false; var smoothTime = show ? 0.35f : 0.125f; var startingOpacity = m_CanvasGroup.alpha; var targetOpacity = show ? 1f : 0f; var smoothVelocity = 0f; var currentDuration = 0f; while (currentDuration < smoothTime) { startingOpacity = MathUtilsExt.SmoothDamp(startingOpacity, targetOpacity, ref smoothVelocity, smoothTime, Mathf.Infinity, Time.deltaTime); currentDuration += Time.deltaTime; m_CanvasGroup.alpha = startingOpacity * startingOpacity; yield return(null); } m_CanvasGroup.alpha = targetOpacity; if (show) { m_CanvasGroup.interactable = true; } else { m_TitleIcon.SetBlendShapeWeight(0, 0); } }
private IEnumerator AnimateShowVisuals() { m_State = State.TransitioningIn; m_RoomScaleTransform.position = m_FinalPosition + k_GroundOffset; ShowLine(); for (int i = 0; i < m_MotionSphereCount; ++i) { m_MotionSpheres[i].localScale = m_MotionSphereOriginalScale; } const float kTargetScale = 1f; float scale = 0f; float tubeScale = m_TubeTransform.localScale.x; float smoothVelocity = 0f; const float kSmoothTime = 0.75f; var currentDuration = 0f; while (m_State == State.TransitioningIn && currentDuration < kSmoothTime) { scale = MathUtilsExt.SmoothDamp(scale, kTargetScale, ref smoothVelocity, kSmoothTime, Mathf.Infinity, Time.unscaledDeltaTime); var adjustedScale = scale * viewerScale; currentDuration += Time.unscaledDeltaTime; m_TubeTransform.localScale = new Vector3(tubeScale, scale, tubeScale); m_LocatorRoot.localScale = Vector3.one * scale; m_LineRenderer.SetWidth(adjustedScale, adjustedScale); yield return(null); } m_State = State.Active; }
/// <summary> /// Animate the hiding of this button's visual elements /// </summary> IEnumerator AnimateHide() { m_CanvasGroup.interactable = false; m_ButtonMaterial.SetFloat(k_MaterialAlphaProperty, 0f); const float kTotalDuration = 0.25f; var scale = transform.localScale; var smoothVelocity = Vector3.zero; var hiddenLocalScale = Vector3.zero; var currentDuration = 0f; while (currentDuration < kTotalDuration) { currentDuration += Time.deltaTime; scale = MathUtilsExt.SmoothDamp(scale, hiddenLocalScale, ref smoothVelocity, kTotalDuration, Mathf.Infinity, Time.deltaTime); transform.localScale = scale; m_ButtonMaterial.SetFloat(k_MaterialAlphaProperty, scale.z); yield return(null); } m_ButtonMaterial.SetFloat(k_MaterialAlphaProperty, 0f); transform.localScale = hiddenLocalScale; m_VisibilityCoroutine = null; gameObject.SetActive(false); }
IEnumerator VacuumToViewer(IVacuumable vacuumable) { var vacuumTransform = vacuumable.transform; var startPosition = vacuumTransform.position; var startRotation = vacuumTransform.rotation; var offset = defaultOffset; offset.z += vacuumable.vacuumBounds.extents.z; offset *= this.GetViewerScale(); var camera = CameraUtils.GetMainCamera().transform; var destPosition = camera.position + MathUtilsExt.ConstrainYawRotation(camera.rotation) * offset; var destRotation = Quaternion.LookRotation(camera.forward) * defaultTilt; var currentValue = 0f; var currentVelocity = 0f; var currentDuration = 0f; const float kTargetValue = 1f; const float kTargetDuration = 0.5f; while (currentDuration < kTargetDuration) { currentDuration += Time.deltaTime; currentValue = MathUtilsExt.SmoothDamp(currentValue, kTargetValue, ref currentVelocity, kTargetDuration, Mathf.Infinity, Time.deltaTime); vacuumTransform.position = Vector3.Lerp(startPosition, destPosition, currentValue); vacuumTransform.rotation = Quaternion.Lerp(startRotation, destRotation, currentValue); yield return(null); } m_VacuumingCoroutines.Remove(vacuumTransform); }
IEnumerator SnapToFace(int faceIndex, float snapSpeed) { if (m_RotationState == RotationState.Snapping) { yield break; } m_RotationState = RotationState.Snapping; // When the user releases their input while rotating the menu, snap to the nearest face StartCoroutine(AnimateFrameRotationShapeChange(m_RotationState)); var rotation = currentRotation; var faceTargetRotation = GetRotationForFaceIndex(faceIndex); var smoothVelocity = 0f; var smoothSnapSpeed = 0.5f; while (Mathf.Abs(Mathf.DeltaAngle(rotation, faceTargetRotation)) > k_RotationEpsilon) { smoothSnapSpeed = MathUtilsExt.SmoothDamp(smoothSnapSpeed, snapSpeed, ref smoothVelocity, 0.0625f, Mathf.Infinity, Time.deltaTime); rotation = Mathf.LerpAngle(rotation, faceTargetRotation, Time.deltaTime * smoothSnapSpeed); m_MenuFaceRotationOrigin.localRotation = Quaternion.Euler(new Vector3(0, rotation, 0)); yield return(null); } m_MenuFaceRotationOrigin.localRotation = Quaternion.Euler(new Vector3(0, faceTargetRotation, 0)); // Target face index and rotation can be set separately, so both, must be kept in sync targetRotation = faceTargetRotation; m_RotationState = RotationState.AtRest; }
IEnumerator ShowContent() { m_CanvasGroup.interactable = true; const float kTargetAlpha = 1f; const float kRevealDuration = 0.4f; const float kInitialDelayLengthenMultipler = 5f; // used to scale up the initial delay based on the m_InitialDelay value var delay = 0f; var targetDelay = Mathf.Clamp(m_DelayBeforeReveal * kInitialDelayLengthenMultipler, 0f, 2.5f); // scale the target delay, with a maximum clamp var alpha = 0f; var opacitySmoothVelocity = 1f; var currentDuration = 0f; var targetDuration = targetDelay + kRevealDuration; while (currentDuration < targetDuration) { currentDuration += Time.unscaledDeltaTime; m_CanvasGroup.alpha = alpha; while (delay < targetDelay) { delay += Time.unscaledDeltaTime; yield return(null); } alpha = MathUtilsExt.SmoothDamp(alpha, kTargetAlpha, ref opacitySmoothVelocity, targetDuration, Mathf.Infinity, Time.unscaledDeltaTime); yield return(null); } m_CanvasGroup.alpha = 1; m_ContentVisibilityCoroutine = null; }
IEnumerator AnimateResetSize() { var currentBoundsSize = contentBounds.size; var currentBoundsCenter = contentBounds.center; var targetBoundsSize = m_CustomStartingBounds ?? minBounds; var targetBoundsCenter = Vector3.zero; var smoothVelocitySize = Vector3.zero; var smoothVelocityCenter = Vector3.zero; var currentDuration = 0f; const float kTargetDuration = 0.75f; while (currentDuration < kTargetDuration) { currentDuration += Time.unscaledDeltaTime; currentBoundsCenter = MathUtilsExt.SmoothDamp(currentBoundsCenter, targetBoundsCenter, ref smoothVelocityCenter, kTargetDuration, Mathf.Infinity, Time.unscaledDeltaTime); currentBoundsSize = MathUtilsExt.SmoothDamp(currentBoundsSize, targetBoundsSize, ref smoothVelocitySize, kTargetDuration, Mathf.Infinity, Time.unscaledDeltaTime); contentBounds = new Bounds(currentBoundsCenter, currentBoundsSize); OnBoundsChanged(); yield return(null); } contentBounds = new Bounds(targetBoundsCenter, targetBoundsSize); OnBoundsChanged(); m_ResetSizeCoroutine = null; }
IEnumerator AnimateFrameReveal(VisibilityState visibilityState) { m_MenuFrameRenderer.SetBlendShapeWeight(1, 100f); const float zeroStartBlendShapePadding = 20f; // start the blendShape at a point slightly above the full hidden value for better visibility const float kLerpEmphasisWeight = 0.25f; var smoothTime = visibilityState == VisibilityState.TransitioningIn ? 0.1875f : 0.09375f; // slower if transitioning in var currentBlendShapeWeight = m_MenuFrameRenderer.GetBlendShapeWeight(1); var targetWeight = visibilityState == VisibilityState.TransitioningIn ? 0f : 100f; var smoothVelocity = 0f; currentBlendShapeWeight = currentBlendShapeWeight > 0 ? currentBlendShapeWeight : zeroStartBlendShapePadding; var currentDuration = 0f; while (m_VisibilityState != VisibilityState.Hidden && currentDuration < smoothTime) { currentBlendShapeWeight = MathUtilsExt.SmoothDamp(currentBlendShapeWeight, targetWeight, ref smoothVelocity, smoothTime, Mathf.Infinity, Time.deltaTime); currentDuration += Time.deltaTime; m_MenuFrameRenderer.SetBlendShapeWeight(1, currentBlendShapeWeight * currentBlendShapeWeight); m_MenuFacesMaterial.color = Color.Lerp(m_MenuFacesColor, k_MenuFacesHiddenColor, currentBlendShapeWeight * kLerpEmphasisWeight); yield return(null); } if (m_VisibilityState == visibilityState) { m_MenuFrameRenderer.SetBlendShapeWeight(1, targetWeight); m_MenuFacesMaterial.color = targetWeight > 0 ? m_MenuFacesColor : k_MenuFacesHiddenColor; } if (m_VisibilityState == VisibilityState.Hidden) { m_MenuFrameRenderer.SetBlendShapeWeight(0, 0); } }
IEnumerator ShowButtonList() { m_ButtonList.gameObject.SetActive(true); const float targetDuration = 0.5f; const float targetMinSpacing = 0.0015f; var currentAlpha = m_ButtonListCanvasGroup.alpha; var kTargetAlpha = 1f; var transitionAmount = 0f; var velocity = 0f; var currentDuration = 0f; while (currentDuration < targetDuration) { currentDuration += Time.deltaTime; transitionAmount = MathUtilsExt.SmoothDamp(transitionAmount, 1f, ref velocity, targetDuration, Mathf.Infinity, Time.deltaTime); m_ButtonListGrid.spacing = new Vector2(0f, Mathf.Lerp(m_HiddenButtonListYSpacing, targetMinSpacing, transitionAmount)); m_ButtonListCanvasGroup.alpha = Mathf.Lerp(currentAlpha, kTargetAlpha, transitionAmount); yield return(null); } m_ButtonListGrid.spacing = Vector2.one * targetMinSpacing; m_ButtonListCanvasGroup.alpha = 1f; m_ShowButtonListCoroutine = null; }
private IEnumerator ShowRay() { m_Tip.transform.localScale = m_TipStartScale; float viewerScale; float scaledWidth; var currentWidth = m_LineRenderer.widthStart; var smoothVelocity = 0f; const float kSmoothTime = 0.3125f; var currentDuration = 0f; while (currentDuration < kSmoothTime) { viewerScale = getViewerScale(); currentDuration += Time.unscaledDeltaTime; currentWidth = MathUtilsExt.SmoothDamp(currentWidth, m_LineWidth, ref smoothVelocity, kSmoothTime, Mathf.Infinity, Time.unscaledDeltaTime); scaledWidth = currentWidth * viewerScale; m_LineRenderer.SetWidth(scaledWidth, scaledWidth); yield return(null); } viewerScale = getViewerScale(); scaledWidth = m_LineWidth * viewerScale; m_LineRenderer.SetWidth(scaledWidth, scaledWidth); m_RayVisibilityCoroutine = null; }
private IEnumerator AnimateVisuals(bool focus) { if (m_RotationVisualsCoroutine != null) { yield break; } Vector3 targetBorderLocalScale = focus ? m_BorderOutlineOriginalLocalScale * k_BorderScaleMultiplier : m_BorderOutlineOriginalLocalScale; Vector3 currentBorderLocalScale = m_BorderOutlineTransform.localScale; const float kLerpEmphasisWeight = 0.2f; var currentBlendShapeWeight = m_TitleIcon.GetBlendShapeWeight(0); var targetWeight = focus ? 100f : 0f; var smoothTime = focus ? 0.25f : 0.5f; var smoothVelocity = 0f; var currentDuration = 0f; while (currentDuration < smoothTime) { currentBlendShapeWeight = MathUtilsExt.SmoothDamp(currentBlendShapeWeight, targetWeight, ref smoothVelocity, smoothTime, Mathf.Infinity, Time.unscaledDeltaTime); currentDuration += Time.unscaledDeltaTime; currentBorderLocalScale = Vector3.Lerp(currentBorderLocalScale, targetBorderLocalScale, currentBlendShapeWeight * kLerpEmphasisWeight); m_BorderOutlineTransform.localScale = currentBorderLocalScale; m_TitleIcon.SetBlendShapeWeight(0, currentBlendShapeWeight); yield return(null); } m_TitleIcon.SetBlendShapeWeight(0, targetWeight); m_BorderOutlineTransform.localScale = targetBorderLocalScale; m_RotationVisualsCoroutine = null; }
// 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; if (m_PreviewObjectClone) { currentPreviewOffset = m_PreviewObjectClone.localPosition; } var currentTime = 0f; var currentVelocity = 0f; const float kDuration = 1f; while (currentTime < kDuration - 0.05f) { if (m_DragObject == null) { yield break; // Exit coroutine if m_GrabbedObject is destroyed before the loop is finished } currentTime = MathUtilsExt.SmoothDamp(currentTime, kDuration, ref currentVelocity, 0.5f, Mathf.Infinity, Time.unscaledDeltaTime); m_DragObject.localScale = Vector3.Lerp(currentLocalScale, m_GrabPreviewTargetScale, currentTime); if (m_PreviewObjectClone) { m_PreviewObjectClone.localPosition = Vector3.Lerp(currentPreviewOffset, m_GrabPreviewPivotOffset, currentTime); } yield return(null); } m_DragObject.localScale = m_GrabPreviewTargetScale; }
private IEnumerator ShowMallet() { var stemScale = m_StemOrigin.localScale; var currentLength = m_StemOrigin.localScale.y; var targetBulbScale = Vector3.one * m_BulbRadius * 2f; var smoothVelocity = 0f; const float kTargetDuration = 0.3f; var currentDuration = 0f; while (currentDuration < kTargetDuration) { currentLength = MathUtilsExt.SmoothDamp(currentLength, m_StemLength, ref smoothVelocity, kTargetDuration, Mathf.Infinity, Time.deltaTime); m_StemOrigin.localScale = new Vector3(stemScale.x, currentLength, stemScale.z); m_Bulb.transform.localPosition = new Vector3(0f, 0f, currentLength * 2f); var alpha = currentLength / m_StemLength; m_Bulb.transform.localScale = targetBulbScale * alpha; currentDuration += Time.deltaTime; yield return(null); } m_Bulb.transform.localPosition = new Vector3(0f, 0f, m_StemLength * 2f); m_Bulb.transform.localScale = targetBulbScale; m_Open = true; m_ShowHideCoroutine = null; }
IEnumerator AnimateHide() { if (m_VisibilityCoroutine != null) { yield break; } m_VisibilityState = VisibilityState.TransitioningOut; foreach (var face in m_MenuFaces) { face.Hide(); } foreach (var submenus in m_FaceSubmenus) { foreach (var submenu in submenus.Value) { ObjectUtils.Destroy(submenu); } } m_FaceSubmenus.Clear(); if (m_FrameRevealCoroutine != null) { StopCoroutine(m_FrameRevealCoroutine); } m_FrameRevealCoroutine = StartCoroutine(AnimateFrameReveal(m_VisibilityState)); const float kTargetScale = 0f; const float kSmoothTime = 0.06875f; var scale = transform.localScale.x; var smoothVelocity = 0f; var currentDuration = 0f; while (currentDuration < kSmoothTime) { scale = MathUtilsExt.SmoothDamp(scale, kTargetScale, ref smoothVelocity, kSmoothTime, Mathf.Infinity, Time.deltaTime); currentDuration += Time.deltaTime; transform.localScale = Vector3.one * scale; m_AlternateMenu.localScale = m_AlternateMenuOriginOriginalLocalScale * scale; yield return(null); } gameObject.SetActive(false); m_VisibilityState = VisibilityState.Hidden; var snapRotation = GetRotationForFaceIndex(GetClosestFaceIndexForRotation(currentRotation)); m_MenuFaceRotationOrigin.localRotation = Quaternion.Euler(new Vector3(0, snapRotation, 0)); // set intended target rotation m_RotationState = RotationState.AtRest; m_VisibilityCoroutine = null; }
public void SmoothDamp_DividesSmoothTimeBy3_Float() { var velocity = 1f; var damped = MathUtilsExt.SmoothDamp(2f, 8f, ref velocity, .3f, 10f, .1f); velocity = 1f; var dampedExpected = Mathf.SmoothDamp(2f, 8f, ref velocity, .1f, 10f, .1f); Assert.AreEqual(dampedExpected, damped); }
void UpdateWorkspaceScales() { for (int i = 0; i < m_Workspaces.Count; i++) { var workspaceTransform = m_Workspaces[i].transform; var targetScale = m_WorkspaceLocalScales[i] * m_TargetScale; workspaceTransform.localScale = MathUtilsExt.SmoothDamp(workspaceTransform.localScale, targetScale, ref m_ScaleVelocities[i], 0.25f, Mathf.Infinity, Time.deltaTime); } }
public void SmoothDamp_DividesSmoothTimeBy3_Vector3() { var velocity = new Vector3(2, 1, 0); var current = new Vector3(0, 0, 0); var target = new Vector3(2, 4, 8); var damped = MathUtilsExt.SmoothDamp(current, target, ref velocity, .3f, 10f, .1f); velocity = new Vector3(2, 1, 0); var dampedExpected = Vector3.SmoothDamp(current, target, ref velocity, .1f, 10f, .1f); Assert.AreEqual(dampedExpected, damped); }
IEnumerator AnimateShow() { m_CanvasGroup.interactable = false; m_ButtonMaterial.SetFloat(k_MaterialAlphaProperty, 0f); this.StopCoroutine(ref m_ContentVisibilityCoroutine); m_ContentVisibilityCoroutine = StartCoroutine(ShowContent()); const float kInitialRevealDuration = 0.5f; const float kScaleRevealDuration = 0.25f; var delay = 0f; var scale = m_HiddenLocalScale; var smoothVelocity = Vector3.zero; var hiddenLocalYScale = new Vector3(m_HiddenLocalScale.x, 0f, 0f); var currentDuration = 0f; var totalDuration = m_DelayBeforeReveal + kInitialRevealDuration + kScaleRevealDuration; var visibleLocalScale = new Vector3(transform.localScale.x, transform.localScale.y, m_VisibleLocalZScale); while (currentDuration < totalDuration) { currentDuration += Time.unscaledDeltaTime; transform.localScale = scale; m_ButtonMaterial.SetFloat(k_MaterialAlphaProperty, scale.z); // Perform initial delay while (delay < m_DelayBeforeReveal) { delay += Time.unscaledDeltaTime; yield return(null); } // Perform the button vertical button reveal, after the initial wait while (delay < kInitialRevealDuration + m_DelayBeforeReveal) { delay += Time.unscaledDeltaTime; var shapedDelayLerp = delay / m_DelayBeforeReveal; transform.localScale = Vector3.Lerp(hiddenLocalYScale, m_HiddenLocalScale, shapedDelayLerp * shapedDelayLerp); yield return(null); } // Perform the button depth reveal scale = MathUtilsExt.SmoothDamp(scale, visibleLocalScale, ref smoothVelocity, kScaleRevealDuration, Mathf.Infinity, Time.unscaledDeltaTime); yield return(null); } m_ButtonMaterial.SetFloat(k_MaterialAlphaProperty, 1); m_VisibilityCoroutine = null; }
IEnumerator UpdateLocation(Vector3 targetPosition) { const float kTargetDuration = 0.25f; var transform = m_MiniWorld.referenceTransform; var smoothVelocity = Vector3.zero; var currentDuration = 0f; while (currentDuration < kTargetDuration) { currentDuration += Time.unscaledDeltaTime; transform.position = MathUtilsExt.SmoothDamp(transform.position, targetPosition, ref smoothVelocity, kTargetDuration, Mathf.Infinity, Time.unscaledDeltaTime); yield return(null); } transform.position = targetPosition; }
IEnumerator ChangeFrameThickness(float targetBlendAmount) { const float kTargetDuration = 0.25f; var currentDuration = 0f; var currentBlendAmount = m_Frame.GetBlendShapeWeight(k_ThinFrameBlendShapeIndex); var currentVelocity = 0f; while (currentDuration < kTargetDuration) { currentDuration += Time.unscaledDeltaTime; currentBlendAmount = MathUtilsExt.SmoothDamp(currentBlendAmount, targetBlendAmount, ref currentVelocity, kTargetDuration, Mathf.Infinity, Time.unscaledDeltaTime); m_Frame.SetBlendShapeWeight(k_ThinFrameBlendShapeIndex, currentBlendAmount); yield return(null); } m_FrameThicknessCoroutine = null; }
private IEnumerator AnimateShow() { if (m_VisibilityCoroutine != null) { yield break; } m_VisibilityState = VisibilityState.TransitioningIn; foreach (var face in m_MenuFaces) { face.Show(); } if (m_FrameRevealCoroutine != null) { StopCoroutine(m_FrameRevealCoroutine); } m_FrameRevealCoroutine = StartCoroutine(AnimateFrameReveal(m_VisibilityState)); for (int i = 0; i < m_MenuFaceContainers.Length; ++i) { StartCoroutine(AnimateFaceReveal(i)); } const float kTargetScale = 1f; const float kSmoothTime = 0.125f; var scale = 0f; var smoothVelocity = 0f; var currentDuration = 0f; while (currentDuration < kSmoothTime) { scale = MathUtilsExt.SmoothDamp(scale, kTargetScale, ref smoothVelocity, kSmoothTime, Mathf.Infinity, Time.unscaledDeltaTime); currentDuration += Time.unscaledDeltaTime; transform.localScale = Vector3.one * scale; m_AlternateMenu.localScale = m_AlternateMenuOriginOriginalLocalScale * scale; yield return(null); } m_VisibilityState = VisibilityState.Visible; m_VisibilityCoroutine = null; }
IEnumerator ShowCone() { var currentScale = m_ConeTransform.localScale; var smoothVelocity = Vector3.zero; const float kSmoothTime = 0.3125f; var currentDuration = 0f; while (currentDuration < kSmoothTime) { currentDuration += Time.unscaledDeltaTime; currentScale = MathUtilsExt.SmoothDamp(currentScale, m_OriginalConeLocalScale, ref smoothVelocity, kSmoothTime, Mathf.Infinity, Time.unscaledDeltaTime); m_ConeTransform.localScale = currentScale; yield return(null); } m_ConeTransform.localScale = m_OriginalConeLocalScale; m_ConeVisibilityCoroutine = null; }
IEnumerator MoveToPositionOverTime(Vector3 targetPos, float duration) { var currentPosition = transform.position; var transitionAmount = 0f; var speed = 0f; var currentDuration = 0f; while (currentDuration < duration) { currentDuration += Time.unscaledDeltaTime; transitionAmount = MathUtilsExt.SmoothDamp(transitionAmount, 1f, ref speed, duration, Mathf.Infinity, Time.unscaledDeltaTime); transform.position = Vector3.Lerp(currentPosition, targetPos, transitionAmount); yield return(null); } transform.position = targetPos; m_MoveCoroutine = null; }
IEnumerator HideCone() { var currentScale = m_ConeTransform.localScale; var smoothVelocity = Vector3.one; const float kSmoothTime = 0.1875f; var currentDuration = 0f; while (currentDuration < kSmoothTime) { currentDuration += Time.deltaTime; currentScale = MathUtilsExt.SmoothDamp(currentScale, Vector3.zero, ref smoothVelocity, kSmoothTime, Mathf.Infinity, Time.deltaTime); m_ConeTransform.localScale = currentScale; yield return(null); } m_ConeTransform.localScale = Vector3.zero; m_ConeVisibilityCoroutine = null; }
IEnumerator HideTopFace() { const string kMaterialHighlightAlphaProperty = "_Alpha"; const float kTargetAlpha = 0f; const float kTargetDuration = 0.2f; var currentDuration = 0f; var currentAlpha = m_TopFaceMaterial.GetFloat(kMaterialHighlightAlphaProperty); var currentVelocity = 0f; while (currentDuration < kTargetDuration) { currentDuration += Time.deltaTime; currentAlpha = MathUtilsExt.SmoothDamp(currentAlpha, kTargetAlpha, ref currentVelocity, kTargetDuration, Mathf.Infinity, Time.deltaTime); m_TopFaceMaterial.SetFloat(kMaterialHighlightAlphaProperty, currentAlpha); yield return(null); } m_TopFaceVisibleCoroutine = null; }
IEnumerator HideHighlight() { const float kTargetAlpha = 0f; var currentAlpha = m_TopHighlightMaterial.GetFloat(k_AlphaProperty); var smoothVelocity = 0f; var currentDuration = 0f; const float kTargetDuration = 0.35f; while (currentDuration < kTargetDuration) { currentDuration += Time.deltaTime; currentAlpha = MathUtilsExt.SmoothDamp(currentAlpha, kTargetAlpha, ref smoothVelocity, kTargetDuration, Mathf.Infinity, Time.deltaTime); m_TopHighlightMaterial.SetFloat(k_AlphaProperty, currentAlpha); yield return(null); } m_TopHighlightMaterial.SetFloat(k_AlphaProperty, kTargetAlpha); // set value after loop because precision matters in this case m_HighlightCoroutine = null; }