IEnumerable _RunTransitions(IGameView pLeaving, IGameView pEntering, IViewTransition pTransition, StringKeyDictionary pInfo) { if (pTransition != null) { //get transitions. ITransition transitionIntro = null; TransitionOutro transitionOutro = null; if (pEntering != null) { transitionIntro = pEntering.TransitionIntro(pTransition.TransitionInName, pInfo); } if (pLeaving != null) { transitionOutro = pLeaving.TransitionOutro(pTransition.TransitionOutName, pInfo); } //run transitions. if (pTransition.Simultaneous && transitionIntro != null && transitionOutro != null) { //Run both at the same time var startOut = StartCoroutine(transitionOutro.GetEnumerator(pInfo)); var startIn = StartCoroutine(transitionIntro.GetEnumerator(pInfo)); yield return(startOut); yield return(startIn); } else { if (transitionOutro != null) { var enumeratorOut = transitionOutro.GetEnumerator(pInfo); if (enumeratorOut != null) { while (enumeratorOut.MoveNext()) { yield return(enumeratorOut.Current); } } transitionOutro.moveViewToBackground(); } if (transitionIntro != null) { var enumeratorIn = transitionIntro.GetEnumerator(pInfo); if (enumeratorIn != null) { while (enumeratorIn.MoveNext()) { yield return(enumeratorIn.Current); } } } } } }
internal static void Execute(IView from, IView to, TransitionType type) { _fromView = from; _toView = to; switch (type) { case TransitionType.Basic: _currentTransition = _basicTransition; break; case TransitionType.SlideLeft: _slideTransition.SlideDirection = TransitionType.SlideLeft; _currentTransition = _slideTransition; break; case TransitionType.SlideRight: _slideTransition.SlideDirection = TransitionType.SlideRight; _currentTransition = _slideTransition; break; case TransitionType.FlipLeft: _flipTransition.FlipDirection = TransitionType.FlipLeft; _currentTransition = _flipTransition; break; case TransitionType.FlipRight: _flipTransition.FlipDirection = TransitionType.FlipRight; _currentTransition = _flipTransition; break; } if (!_currentTransition.IsTransitionAvailable()) { _currentTransition = _basicTransition; } _currentTransition.Execute(); }
internal static void Execute(IView from, IView to, TransitionType type) { _fromView = from; _toView = to; switch (type) { case TransitionType.Basic: _currentTransition = _basicTransition; break; case TransitionType.SlideLeft: _slideTransition.SlideDirection = TransitionType.SlideLeft; _currentTransition = _slideTransition; break; case TransitionType.SlideRight: _slideTransition.SlideDirection = TransitionType.SlideRight; _currentTransition = _slideTransition; break; case TransitionType.FlipLeft: _flipTransition.FlipDirection = TransitionType.FlipLeft; _currentTransition = _flipTransition; break; case TransitionType.FlipRight: _flipTransition.FlipDirection = TransitionType.FlipRight; _currentTransition = _flipTransition; break; } if (!_currentTransition.IsTransitionAvailable()) _currentTransition = _basicTransition; _currentTransition.Execute(); }
public IEnumerable _GoBack(int pGoBack = 1, StringKeyDictionary pInfo = null, string pTransitionName = null, bool pWaitIfBusy = false) { while (!_initialized) { yield return(null); } if (pWaitIfBusy) { while (_coroutineLock.IsLocked) { yield return(null); } } else if (_coroutineLock.IsLocked) { //Exit. Don't wait yield break; } using (_coroutineLock.Lock()) { if (pGoBack < 1) { //Do Nothing. Exit yield break; } Assert.IsTrue(pGoBack <= _viewStack.Count, System.String.Format(NOT_ENOUGH_VIEWS_TO_GO_BACK_ERROR_FORMAT, pGoBack)); Debug.Assert(pGoBack <= _viewStack.Count, System.String.Format(NOT_ENOUGH_VIEWS_TO_GO_BACK_ERROR_FORMAT, pGoBack)); System.Diagnostics.Debug.Assert(pGoBack <= _viewStack.Count, System.String.Format(NOT_ENOUGH_VIEWS_TO_GO_BACK_ERROR_FORMAT, pGoBack)); //get rid of views in the middle. for (int ii = 1; ii < pGoBack; ii++) { //add it to the cache dictionary. //do not remove it from the view stack yet. It's done in bulk if (_viewStack[ii].CanBeCached) { //Cache it _cacheView(_viewStack[ii], false); } else { GameObject.Destroy(_viewStack[ii].gameObject); _viewStack[ii] = null; } } //Bulk remove the views from the stack if (pGoBack > 1) { _viewStack.RemoveRange(1, pGoBack - 1); } //Warning if the stack will be left empty if (_viewStack.Count == 1) { Debug.LogWarning(NO_VIEW_TO_DISPLAY_WARNING); } IGameView current = CurrentView; IGameView next = _GetByIndexOrNull(1, _viewStack); IViewTransition transition = this._GetTransition(pTransitionName); if (next != null) { next.gameObject.SetActive(true); TransitionIntro transitionIntro; if (transition != null) { transitionIntro = next.TransitionIntro(transition.TransitionInName); if (transitionIntro != null && !transitionIntro.BeginsInTheBackground) { next.gameObject.transform.SetAsLastSibling(); } } } if (current != null) { IWillDisappear[] disappearHandlers = current.gameObject.GetComponentsInChildren <IWillDisappear>(false); foreach (var handler in disappearHandlers) { handler.WillDisappear(pInfo); } //current willDisappear. foreach (var it in current.WillDisappear(pInfo)) { yield return(it); } } //previous willAppear. if (next != null) { foreach (var it in next.WillAppear(pInfo)) { yield return(it); } } //run transitions foreach (var step in _RunTransitions(current, next, transition, pInfo)) { yield return(step); } //previous didAppear if (next != null) { IDidAppear[] appearHandlers = next.gameObject.GetComponentsInChildren <IDidAppear>(false); foreach (var handler in appearHandlers) { handler.DidAppear(pInfo); } foreach (var it in next.DidAppear(pInfo)) { yield return(it); } } //current didDisappear if (current != null) { foreach (var it in current.DidDisappear(pInfo)) { yield return(it); } if (current.TransitionOutro(transition.TransitionOutName) != null) { current.TransitionOutro(transition.TransitionOutName).Rewind(); } } //current goes to the cache. if (current != null) { GameObject currentViewGameObject = current.gameObject; currentViewGameObject.SetActive(false); if (current.CanBeCached) { //add it to the cache dictionary. _cacheView(current, true); } else { GameObject.Destroy(currentViewGameObject); _viewStack.RemoveAt(0); current = null; currentViewGameObject = null; } } } }
IEnumerable _LoadView(string pViewName, StringKeyDictionary pInfo = null, string pTransitionName = null, bool pWaitIfBusy = false, bool pReplaceCurrent = false) { while (!_initialized) { yield return(null); } if (pWaitIfBusy) { while (_coroutineLock.IsLocked) { yield return(null); } } else if (_coroutineLock.IsLocked) { //Exit. Don't wait yield break; } using (_coroutineLock.Lock()) { //keep reference to current. IGameView current = CurrentView; //get reference to next. GameObject nextViewGameObject = _GetCachedOrCreateNew(pViewName); //Assert if there is no next view game object. Assert.IsNotNull(nextViewGameObject, NO_VIEW_EXCEPTION + pViewName); Debug.Assert(nextViewGameObject != null, NO_VIEW_EXCEPTION + pViewName); System.Diagnostics.Debug.Assert(nextViewGameObject != null, NO_VIEW_EXCEPTION + pViewName); //Get a reference to the next view's component IGameView next = nextViewGameObject.GetComponent <IGameView>(); //Add the next view to the view stack and enable the next view. nextViewGameObject.transform.SetParent(_activeViewStackGameObject.transform, false); nextViewGameObject.SetActive(true); //Get the transition to use. IViewTransition transition = this._GetTransition(pTransitionName); TransitionIntro transitionIntro = null; //If a transition is used, get a reference to the transition intro. if (transition != null) { transitionIntro = next.TransitionIntro(transition.TransitionInName); //Check if the new view must come from the background if (transitionIntro.BeginsInTheBackground) { transitionIntro.moveViewToBackground(); } } //run willDisappear on current. if (current != null) { //Run WillDisappear handlers IWillDisappear[] disappearHandlers = current.gameObject.GetComponentsInChildren <IWillDisappear>(false); foreach (var handler in disappearHandlers) { handler.WillDisappear(pInfo); } //Run the WillDisappear coroutine on the current view. foreach (var it in current.WillDisappear(pInfo)) { yield return(it); } } //run WillAppear on next. foreach (var it in next.WillAppear(pInfo)) { yield return(it); } //Rewind the out transition of the view that disappeared if (current != null && current.TransitionOutro(transition.TransitionOutName) != null) { current.TransitionOutro(transition.TransitionOutName).Rewind(); } //Run transitions foreach (var step in _RunTransitions(current, next, transition, pInfo)) { yield return(step); } //Run DidAppear handlers IDidAppear[] appearHandlers = nextViewGameObject.GetComponentsInChildren <IDidAppear>(false); foreach (var handler in appearHandlers) { handler.DidAppear(pInfo); } //run DidAppear on next. foreach (var it in next.DidAppear(pInfo)) { yield return(it); } //run DidDisappear on current. if (current != null) { foreach (var it in current.DidDisappear(pInfo)) { yield return(it); } //Rewind the out transition of the view that disappeared if (current.TransitionOutro(transition.TransitionOutName) != null) { current.TransitionOutro(transition.TransitionOutName).Rewind(); } } //disable current. if (current != null) { current.gameObject.SetActive(false); if (pReplaceCurrent) { _cacheView(current, true); current = null; } } //add next to the top of the view stack. nextViewGameObject.transform.SetAsLastSibling(); _viewStack.Insert(0, next); } }