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); }
public void LateUpdate() { for (int i = 0; i < _textList.Count; i++) { var t = _textList[i]; if (t.rectTransform.anchoredPosition.x < (-_gameCanvas.GetCanvasWidth() - t.rectTransform.rect.width)) { _textList.RemoveAt(i); Destroy(t.gameObject); i--; } } }
/// <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(); } }