IEnumerator HideRoutine(float hideSpeedInSeconds) { _textUI.ForceMeshUpdate(); float currentAlpha = 1; for (float t = 0f; t < 1.0f; t += Time.deltaTime / hideSpeedInSeconds) { // opacity animate currentAlpha = Mathf.Lerp(1, 0, t); _textUI.alpha = currentAlpha; yield return(null); } _textUI.alpha = 0; HideCompleted?.Invoke(); }
/// <summary> /// Hide /// </summary> public void Hide() { if (CustomTitlebar != null) { CustomTitlebar.BackRequested -= CustomTitlebar_BackRequested; } // 自定义TitleBar在平板模式下仍然需要这个事件 SystemNavigationManager.GetForCurrentView().BackRequested -= View_BackRequested; Listener?.RegisterBackKeyPress(); HideCompleted?.Invoke(this, null); _showTcs?.SetResult(0); var scaleAnimation = _compositor.CreateVector3KeyFrameAnimation(); scaleAnimation.InsertKeyFrame(0f, new Vector3(1f, 1f, 0f)); scaleAnimation.InsertKeyFrame(1f, new Vector3(1.3f, 1.3f, 0f)); scaleAnimation.Duration = TimeSpan.FromMilliseconds(600); _dialogVisual.CenterPoint = new Vector3((float)_dialogPresenter.ActualWidth / 2, (float)_dialogPresenter.ActualHeight / 2, 0f); _dialogVisual.StartAnimation("Scale", scaleAnimation); var opacityAnimation = _compositor.CreateScalarKeyFrameAnimation(); opacityAnimation.InsertKeyFrame(0f, 1f); opacityAnimation.InsertKeyFrame(1f, 0f); opacityAnimation.Duration = TimeSpan.FromMilliseconds(600); var batch = _compositor.CreateScopedBatch(CompositionBatchTypes.Animation); _rootGridVisual.StartAnimation("Opacity", opacityAnimation); batch.Completed += (s, e) => { _rootGridVisual.IsVisible = false; Container.Children.Remove(this); }; batch.End(); }
IEnumerator AnimateHideRoutine(float startDelay, float hideSpeedInSeconds) { IsRevealed = true; float currentAlpha = 1; _canvasGroup.alpha = 1; _imageUI.raycastTarget = false; //yield return new WaitForSeconds(startDelay); for (float t = 1f; t > 0; t -= Time.deltaTime / hideSpeedInSeconds) { currentAlpha = Mathf.Lerp(0, 1, t); _canvasGroup.alpha = currentAlpha; yield return(null); } // ensure we hit our final value _canvasGroup.alpha = 0; // set reveal state, now that we're completed IsRevealed = false; HideCompleted?.Invoke(); }