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(); } } }
public void Update() { // 每帧刷新背景的高度。 var canvasHeight = _gameCanvas.GetCanvasHeight(); var canvasWidth = _gameCanvas.GetCanvasWidth(); var bg = Target; var bgHeight = bg.ContentHeight; var bgWidth = bg.ContentWidth; var scaleHeight = canvasHeight / bgHeight; var scaleWidth = canvasWidth / bgWidth; var scale = Mathf.Max(scaleHeight, scaleWidth); bg.transform.localScale = new Vector3(scale, scale, 1); }