public async Task Create(ContainerVisual topContainer) { var compositor = topContainer.Compositor; Tile.Initialize(compositor); CommonAnimations.Initialize(compositor); _layoutManager = new LayoutManager(); await _layoutManager.Create(topContainer); _transitionLibrary = new TransitionLibrary(compositor, _layoutManager); _random = new Random(); NearSlideEntry = new TransitionEntry( TransitionKind.NearSlide, _layoutManager.GetNearNeighbor, _transitionLibrary.CreateNearSlideTransition, TransitionOptions.Select, TransitionDesaturationMode.None); FarSlideEntry = new TransitionEntry( TransitionKind.FarSlide, _layoutManager.GetFarNeighbor, _transitionLibrary.CreateFarSlideTransition, TransitionOptions.Select, TransitionDesaturationMode.ColorFlashlight); ZoomEntry = new TransitionEntry( TransitionKind.Zoom, _layoutManager.GetFarNeighbor, _transitionLibrary.CreateZoomAndPanTransition, TransitionOptions.Select, TransitionDesaturationMode.Regular); StackEntry = new TransitionEntry( TransitionKind.Stack, _layoutManager.GetCurrentPictureFrame, _transitionLibrary.CreateStackTransition, TransitionOptions.Select, TransitionDesaturationMode.None); UnstackEntry = new TransitionEntry( TransitionKind.Stack, _layoutManager.GetCurrentPictureFrame, _transitionLibrary.CreateUnstackTransition, TransitionOptions.Select, TransitionDesaturationMode.None); _entries = new TransitionEntry[] { NearSlideEntry, FarSlideEntry, ZoomEntry, StackEntry, UnstackEntry, }; }
public void PutSettings(CameraTransitionSettings settings) { // restore/put settings into this camera transition this.getCamPrevious = settings.getCamPrevious; this.onlyMoveCamera = settings.onlyMoveCamera; this.entry = (TransitionEntry)settings.entry; this.state = (TransitionState)settings.state; this.direction = (TransitionDirection)settings.direction; this.eventCallPreDelay = (TransitionEventCall)settings.eventCallPreDelay; this.eventCallPostDelay = (TransitionEventCall)settings.eventCallPostDelay; this.transitionDelay = settings.transitionDelay; this.preTransitionDelay = settings.preTransitionDelay; this.postTransitionDelay = settings.postTransitionDelay; this.cameraMinPosition = settings.cameraMinPosition; this.cameraMaxPosition = settings.cameraMaxPosition; this.playerChange = settings.playerChange; }
void Update() { if (transition) { switch (state) { case TransitionState.PreDelay: // run pre transition event before delay CallEventBeforePreDelay(); // wait out the pre delay if set transitionTimer -= Time.deltaTime; if (transitionTimer <= 0) { // run pre transition event after delay CallEventAfterPreDelay(); // start player animation player.GetComponent <Animator>().speed = 1; // set transition state and timer state = TransitionState.Transition; transitionTimer = 0; } break; case TransitionState.Transition: // track transition progress for lerp progress = Mathf.Clamp(transitionTimer, 0, transitionDelay) / transitionDelay; transitionTimer += Time.deltaTime; // move camera and player - animate player during transition cameraMoveProgress = Vector2.Lerp(cameraMoveStart, cameraMoveFinish, progress); cam.transform.position = new Vector3(cameraMoveProgress.x, cameraMoveProgress.y, cam.transform.position.z); player.transform.position = Vector2.Lerp(playerMoveStart, playerMoveFinish, progress); // end of transition if (progress >= 1) { // stop player animation player.GetComponent <Animator>().speed = 0; // set camera positions cam.boundsMin = (entry == TransitionEntry.Enter) ? cameraMinPosition : cameraMinPrevious; cam.boundsMax = (entry == TransitionEntry.Enter) ? cameraMaxPosition : cameraMaxPrevious; player.transform.position = playerMoveFinish; // attach players transform back on the camera cam.player = player.transform; // set transition state and timer state = TransitionState.PostDelay; transitionTimer = postTransitionDelay; } break; case TransitionState.PostDelay: // run post transition event before delay CallEventBeforePostDelay(); // wait out the post delay if set transitionTimer -= Time.deltaTime; if (transitionTimer <= 0) { // run post transition event after delay CallEventAfterPostDelay(); // toggle transition entry entry = (entry == TransitionEntry.Enter) ? TransitionEntry.Exit : TransitionEntry.Enter; // end the transition transition = false; // give control back to the player player.GetComponent <PlayerController>().FreezeInput(false); player.GetComponent <PlayerController>().FreezePlayer(false); // unfreeze enemies, explosions, bonus items, and weapons GameManager.Instance.FreezeEverything(false); // inform the game manager there is no transition GameManager.Instance.SetInCameraTransition(false); // allow the game to be paused GameManager.Instance.AllowGamePause(true); } break; } } }
public void NextTransition() { // // We don't want to play multiple transitions at the same time, or we will have // conflicting animations. // Debug.Assert(_transitionPlaying == TransitionKind.None, "Should not start new transition until previous one has completed"); // // Remember that the application has requested that we start: // - This is used to distinguish when we start the app with no transitions enabled vs. // we start with some enabled and the User subsequently disables all of them. // - This enables the caller to call UpdateTransitionEnabled() to configure the // TransitionController before calling NextTransition(). // _started = true; // // Determine the next transition and tile to display. // if ((_entries == null) || (_entries.Length <= 0)) { return; } TransitionEntry entry = ChooseNextTransition(); if (entry == null) { return; } Tile nextTile = entry.NextTile(); // // Update the selected tile. // if (_currentSelectedTile != null) { _currentSelectedTile.IsSelected = false; _currentSelectedTile = null; } if ((entry.Options & TransitionOptions.Select) != 0) { _currentSelectedTile = nextTile; _currentSelectedTile.IsSelected = true; } // // Update desaturation of all tiles: // - If this transition uses desaturation, desaturate all tiles except the nextTile. // - Otherwise, if we were using desaturation for previous transition, need to turn full // saturation back on. // switch (entry.DesaturationMode) { case TransitionDesaturationMode.None: foreach (var tile in _layoutManager.AllTiles) { tile.IsDesaturated = false; _transitionLibrary.ApplyDesaturation( tile, TransitionDesaturationMode.None); } break; case TransitionDesaturationMode.Regular: foreach (var tile in _layoutManager.AllTiles) { tile.IsDesaturated = (tile != nextTile); _transitionLibrary.ApplyDesaturation( tile, TransitionDesaturationMode.Regular); } break; case TransitionDesaturationMode.ColorFlashlight: if (!_isFlashlightEnabled) { goto case TransitionDesaturationMode.Regular; } foreach (var tile in _layoutManager.AllTiles) { //tile.IsDesaturated = (tile != nextTile); _transitionLibrary.ApplyDesaturation( tile, (tile == nextTile) ? TransitionDesaturationMode.None : TransitionDesaturationMode.ColorFlashlight); } break; } // // Create the Transition and begin playing animations. // var scopedBatch = _compositor.CreateScopedBatch(CompositionBatchTypes.Animation); entry.CreateTransition(nextTile.Frame); scopedBatch.Completed += Transition_Completed; scopedBatch.End(); _transitionPlaying = entry.Kind; }
public void NextTransition() { // Remember that the application has requested that we start: // - This is used to distinguish when we start the app with no transitions enabled vs. // we start with some enabled and the User subsequently disables all of them. // - This enables the caller to call UpdateTransitionEnabled() to configure the // TransitionController before calling NextTransition(). _started = true; // Determine the next transition and tile to display. if ((_entries == null) || (_entries.Length <= 0)) { return; } TransitionEntry entry = ChooseNextTransition(); if (entry == null) { return; } Tile nextTile = entry.NextTile(); // Update the selected tile. if (_currentSelectedTile != null) { _currentSelectedTile.IsSelected = false; _currentSelectedTile = null; } if ((entry.Options & TransitionOptions.Select) != 0) { _currentSelectedTile = nextTile; _currentSelectedTile.IsSelected = true; } // Update desaturation of all tiles: // - If this transition uses desaturation, desaturate all tiles except the nextTile. // - Otherwise, if we were using desaturation for previous transition, need to turn full // saturation back on. switch (entry.DesaturationMode) { case TransitionDesaturationMode.None: foreach (var tile in _layoutManager.AllTiles) { tile.IsDesaturated = false; _transitionLibrary.ApplyDesaturation( tile, TransitionDesaturationMode.None); } break; case TransitionDesaturationMode.Regular: foreach (var tile in _layoutManager.AllTiles) { tile.IsDesaturated = (tile != nextTile); _transitionLibrary.ApplyDesaturation( tile, TransitionDesaturationMode.Regular); } break; case TransitionDesaturationMode.ColorFlashlight: if (!_isFlashlightEnabled) { goto case TransitionDesaturationMode.Regular; } foreach (var tile in _layoutManager.AllTiles) { tile.IsDesaturated = (tile != nextTile); _transitionLibrary.ApplyDesaturation( tile, (tile == nextTile) ? TransitionDesaturationMode.None : TransitionDesaturationMode.ColorFlashlight); } break; } // Create the Transition and begin playing animations. Transition transition = entry.CreateTransition(nextTile.Frame); if (transition != null) { transition.TransitionFinished += Transition_TransitionFinished; transition.PlayAllAnimations(); _currentTransition = transition; } }