/// <summary> /// 生成目标窗口。 /// </summary> private void InstantiateTarget(UISwitchTask curTask) { if (curTask == null) { return; } if (curTask.ToWindow) { curTask.ToWindow.anchoredPosition = BornPosition; return; } var toType = curTask.ToWindowType; var to = GetWindow(toType); if (to) { curTask.ToWindow = to; curTask.ToWindow.anchoredPosition = BornPosition; } else { curTask.InstantiateCoroutine = StartCoroutine(InstantiateWindowCoroutine(toType, curTask)); } }
private void SwitchToTargetDirectly(UISwitchTask curTask) { if (curTask == null) { return; } StopAllAnimationAndDisableBlankCover(curTask); var from = curTask.FromWindow; var to = curTask.ToWindow; if (from && from.gameObject.activeSelf) { from.gameObject.SetActive(false); } if (to) { if (!to.gameObject.activeSelf) { to.gameObject.SetActive(true); } to.anchoredPosition = Vector2.zero; } }
/// <summary> /// 启动Blank动画。 /// </summary> /// <param name="curTask"></param> private void StartBlankAnimation(UISwitchTask curTask) { if (curTask == null) { return; } StopAllAnimationAndDisableBlankCover(curTask); var from = curTask.FromWindow; var to = curTask.ToWindow; var blankCover = _gameCanvas.GetWindowSwitchCover(); if (!blankCover.gameObject.activeSelf) { blankCover.gameObject.SetActive(true); } curTask.StopAllAnimation(); var blank = DOTween.Sequence(); blank .Append(blankCover.DOFade(1, BlankAppearTime)) .AppendCallback(() => { if (from) { from.anchoredPosition = BornPosition; } if (to) { if (!to.gameObject.activeSelf) { to.gameObject.SetActive(true); } to.anchoredPosition = Vector2.zero; if (curTask.OnEnableTarget != null) { curTask.OnEnableTarget(curTask); } } }) .Append(blankCover.DOFade(0, BlankFadeTime)) .OnComplete(() => { if (blankCover.gameObject.activeSelf) { blankCover.gameObject.SetActive(false); } }); blank.Play(); curTask.BlankSequence = blank; }
/// <summary> /// 检查目标窗口是否完成生成过程。 /// </summary> /// <param name="curTask"></param> /// <returns></returns> private bool CheckTargetStatus(UISwitchTask curTask) { if (curTask == null) { return(false); } return(curTask.ToWindow != null); }
private ActionSequenceGeneric <UISwitchTask> CreateNullSwitchSequence(UISwitchTask task) { var seq = new ActionSequenceGeneric <UISwitchTask>(task); seq.Append(InstantiateTarget, CheckTargetStatus); seq.Append(SwitchToTargetDirectly); seq.CompleteListener = CompleteLogic; return(seq); }
private ActionSequenceGeneric <UISwitchTask> CreateBlankSwitchSequence(UISwitchTask task) { var seq = new ActionSequenceGeneric <UISwitchTask>(task); seq.Append(InstantiateTarget, CheckTargetStatus); seq.Append(StartBlankAnimation, CheckBlankAnimationStatus); seq.CompleteListener = CompleteLogic; return(seq); }
private ActionSequenceGeneric <UISwitchTask> CreateSlideUpDownSwitchSequence(UISwitchTask task) { var seq = new ActionSequenceGeneric <UISwitchTask>(task); seq.Append(InstantiateTarget, CheckTargetStatus); seq.Append(EnableTarget); seq.Append(StartSlideUpDownAnimation, CheckSlideAnimationStatus); seq.CompleteListener = CompleteLogic; return(seq); }
private void StartSlideUpDownAnimation(UISwitchTask curTask) { if (curTask == null) { return; } StopAllAnimationAndDisableBlankCover(curTask); var from = curTask.FromWindow; var to = curTask.ToWindow; var type = curTask.SwitchType; var canvasHeight = _gameCanvas.GetCanvasHeight(); if (type != UISwitchType.SlideUp && type != UISwitchType.SlideDown) { return; } if (type == UISwitchType.SlideUp) { if (from) { from.anchoredPosition = Vector2.zero; curTask.FromTweener = @from.DOAnchorPos( new Vector2(0, canvasHeight), SlideTime) .SetEase(Ease.OutBack, 1.1f) .Play(); } if (to) { to.anchoredPosition = Vector2.zero; } if (from && to) { from.SetSiblingIndex(to.GetSiblingIndex() + 1); } } else if (type == UISwitchType.SlideDown) { if (to) { to.anchoredPosition = new Vector2(0, canvasHeight); curTask.ToTweener = to .DOAnchorPos(Vector2.zero, SlideTime) .SetEase(Ease.OutBack, 1.1f) .Play(); } } }
private void StopAllAnimationAndDisableBlankCover(UISwitchTask curTask) { if (curTask != null) { curTask.StopAllAnimation(); } var cover = _gameCanvas.GetWindowSwitchCover(); if (cover && cover.gameObject.activeSelf) { cover.gameObject.SetActive(false); } }
private bool CheckBlankAnimationStatus(UISwitchTask curTask) { if (curTask == null) { return(true); } var seq = curTask.BlankSequence; if (seq == null) { return(true); } return(!seq.IsPlaying()); }
private void CompleteLogic(UISwitchTask curTask) { if (curTask == null) { return; } _currentWindowType = curTask.ToWindowType; SetInstantiatedWindow(curTask.ToWindowType, curTask.ToWindow); DestroyOtherWindow(); var complete = curTask.OnUISwitchComplete; if (complete != null) { complete(curTask); } }
/// <summary> /// Enable目标窗口。 /// 单独使用一个方法开启是为了防止在开始动画那一帧造成卡顿。 /// </summary> /// <param name="curTask"></param> private void EnableTarget(UISwitchTask curTask) { if (curTask == null) { return; } var target = curTask.ToWindow; if (target && !target.gameObject.activeSelf) { target.gameObject.SetActive(true); } if (curTask.OnEnableTarget != null) { curTask.OnEnableTarget(curTask); } }
/// <summary> /// 启动左右滑动的动画。 /// </summary> /// <param name="curTask"></param> private void StartSlideLeftRightAnimation(UISwitchTask curTask) { if (curTask == null) { return; } StopAllAnimationAndDisableBlankCover(curTask); var from = curTask.FromWindow; var to = curTask.ToWindow; var type = curTask.SwitchType; var canvasWidth = _gameCanvas.GetCanvasWidth(); if (type != UISwitchType.SlideLeft && type != UISwitchType.SlideRight) { return; } if (from) { from.anchoredPosition = Vector2.zero; curTask.FromTweener = @from.DOAnchorPos( new Vector2( type == UISwitchType.SlideLeft ? -canvasWidth : canvasWidth, 0), SlideTime) .SetEase(Ease.OutBack, 1.1f) .Play(); } if (to) { to.anchoredPosition = new Vector2( type == UISwitchType.SlideLeft ? canvasWidth : -canvasWidth, 0); curTask.ToTweener = to .DOAnchorPos(Vector2.zero, SlideTime) .SetEase(Ease.OutBack, 1.1f) .Play(); } }
private bool CheckSlideAnimationStatus(UISwitchTask task) { if (task == null) { return(true); } var from = task.FromTweener; var to = task.ToTweener; if (from != null && from.IsPlaying()) { return(false); } if (to != null && to.IsPlaying()) { return(false); } return(true); }
private IEnumerator InstantiateWindowCoroutine(UIWindowType windowType, UISwitchTask curTask) { if (curTask == null) { yield break; } if (windowType == UIWindowType.Null) { yield break; } if (!NeedInstantiate(windowType)) { yield break; } var prefabPath = GetPrefabPath(windowType); var prefabName = GetPrefabName(windowType); if (string.IsNullOrEmpty(prefabPath) || string.IsNullOrEmpty(prefabName)) { yield break; } _dialogManager.ShowWaitingDialog(true, 10); _resource.StartLoadResource(prefabPath, prefabName); while (!_resource.HasCached(prefabPath)) { yield return(null); } var prefab = _resource.GetResource <GameObject>(prefabPath, prefabName); RectTransform target = null; switch (windowType) { case UIWindowType.Game: var game = _gameWindowFactory.Create(prefab); target = game.GetComponent <RectTransform>(); break; case UIWindowType.LoginMode: var loginMode = _loginModeWindowFactory.Create(prefab); target = loginMode.GetComponent <RectTransform>(); break; case UIWindowType.Portal: var portal = _portalWindowFactory.Create(prefab); target = portal.GetComponent <RectTransform>(); break; case UIWindowType.Room: var room = _roomWindowFactory.Create(prefab); target = room.GetComponent <RectTransform>(); break; case UIWindowType.Seat: var seat = _seatWindowFactory.Create(prefab); target = seat.GetComponent <RectTransform>(); break; } _dialogManager.ShowWaitingDialog(false); if (target == null) { yield break; } target.SetParent(_gameCanvas.GetWindowParent(), false); target.anchoredPosition = BornPosition; curTask.ToWindow = target; yield return(null); }
public void SwitchTo( UIWindowType targetWindow, Action <UISwitchTask> onEnableTarget = null, Action <UISwitchTask> onUISwitchComplete = null) { MyLog.InfoWithFrame( name, string.Format("try switch {0}-->{1}", _currentWindowType, targetWindow) ); _dialogManager.ShowWaitingDialog(false); if (_curSwitchTask != null && _curSwitchTask.Status == UISwitchStatus.Switching) { MyLog.WarnWithFrame( name, string.Format("curTask: {0}-->{1}", _curSwitchTask.FromWindowType, _curSwitchTask.ToWindowType) ); if (targetWindow == _curSwitchTask.ToWindowType) { MyLog.InfoWithFrame(name, "same target contine switch."); // 继续上一个任务的执行。 _curSwitchTask.OnEnableTarget = onEnableTarget; _curSwitchTask.OnUISwitchComplete = onUISwitchComplete; return; } if (targetWindow == _currentWindowType) { MyLog.WarnWithFrame(name, "switch to current window, stop switch."); // 如果新的目标与当前窗口类型相同。 // 则直接将当前窗口恢复正常位置。 // TODO 实现更牛叉的动画方式,就是反向切换回来。 var destroyToWindow = _curSwitchTask.ToWindowType != _currentWindowType; _curSwitchTask.Cancel(destroyToWindow); ResetCurrentWindow(); if (onEnableTarget != null) { onEnableTarget(_curSwitchTask); } if (onUISwitchComplete != null) { onUISwitchComplete(_curSwitchTask); } return; } MyLog.WarnWithFrame( name, string.Format("cancel curTask: {0}-->{1}", _curSwitchTask.FromWindowType, _curSwitchTask.ToWindowType) ); _curSwitchTask.Cancel(); _curSwitchTask = null; ResetCurrentWindow(); } if (_currentWindowType == targetWindow) { MyLog.WarnWithFrame(name, "switch to current window, finish."); if (onEnableTarget != null) { onEnableTarget(_curSwitchTask); } if (onUISwitchComplete != null) { onUISwitchComplete(_curSwitchTask); } return; } var type = DetermineSwitchType(_currentWindowType, targetWindow); _curSwitchTask = new UISwitchTask(); _curSwitchTask.Parent = this; switch (type) { case UISwitchType.Blank: _curSwitchTask.SwitchAction = CreateBlankSwitchSequence(_curSwitchTask); break; case UISwitchType.SlideLeft: case UISwitchType.SlideRight: _curSwitchTask.SwitchAction = CreateSlideLeftRightSwitchSequence(_curSwitchTask); break; case UISwitchType.SlideUp: case UISwitchType.SlideDown: _curSwitchTask.SwitchAction = CreateSlideUpDownSwitchSequence(_curSwitchTask); break; case UISwitchType.Null: _curSwitchTask.SwitchAction = CreateNullSwitchSequence(_curSwitchTask); break; } _curSwitchTask.FromWindowType = _currentWindowType; _curSwitchTask.FromWindow = GetWindow(_currentWindowType); _curSwitchTask.ToWindowType = targetWindow; _curSwitchTask.ToWindow = GetWindow(targetWindow); _curSwitchTask.SwitchType = type; _curSwitchTask.OnEnableTarget = onEnableTarget; _curSwitchTask.OnUISwitchComplete = onUISwitchComplete; _curSwitchTask.Start(); }