using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace vnxbqy.UI { public class CycleHallAchievementTipWin : Window { [SerializeField] RectTransform winShow; [SerializeField] ButtonEx awardBtn; [SerializeField] Text awardtip; [SerializeField] List itemCells = new List(); [SerializeField] PositionTween positionTween; [SerializeField] float waitTime = 1.0f; [SerializeField] float moveDurationTime = 1.0f; // 移动持续时间 [SerializeField] RectTransform startPosObject; // 挂载初始位置的游戏物体 [SerializeField] RectTransform downPosObject; // 挂载往下移动位置的游戏物体 [SerializeField] RectTransform upPosObject; // 挂载往上移动位置的游戏物体 int roundType; int awardType; int awardTypeValue; int awardIndex; float openTime; CycleHallActModel model { get { return ModelCenter.Instance.GetModelEx(); } } private enum MoveState { MovingDown, Staying, MovingUp, Finished } MoveState currentState; #region Built-in protected override void AddListeners() { awardBtn.SetListener(() => { //WindowCenter.Instance.Close(); }); } protected override void BindController() { } protected override void OnAfterClose() { StopAllCoroutines(); } protected override void OnAfterOpen() { ResetAnimation(); } protected override void OnPreClose() { model.UpdateNewAwardHave -= OnUpdateNewAwardHave; } protected override void OnPreOpen() { model.UpdateNewAwardHave += OnUpdateNewAwardHave; winShow.anchoredPosition = startPosObject.anchoredPosition; } #endregion protected override void LateUpdate() { base.LateUpdate(); if (currentState == MoveState.Staying) { if (Time.time - openTime > waitTime) { currentState = MoveState.MovingUp; positionTween.reversal = true; positionTween.from = downPosObject.anchoredPosition; positionTween.to = upPosObject.anchoredPosition; positionTween.duration = moveDurationTime; positionTween.Play(OnMoveUpComplete); } } } private void OnMoveDownComplete() { currentState = MoveState.Staying; openTime = Time.time; } private void OnMoveUpComplete() { currentState = MoveState.Finished; WindowCenter.Instance.Close(); } private void Display() { roundType = model.newRoundType; awardType = model.newAwardType; awardTypeValue = model.newAwardTypeValue; awardIndex = model.newAwardIndex; var act = model.GetOperationInfo(); if (act == null || !act.TryGetRoundInfoByIndex(roundType, awardIndex, out var award, out int listIndex) || award.AwardItemList == null) return; awardtip.text = Language.Get(StringUtility.Contact("CycleHallMissionTitle", "_", awardType, "_", awardTypeValue), award.NeedValue); ; for (int i = 0; i < itemCells.Count; i++) { var itemBaisc = itemCells[i]; if (i < award.AwardItemList.Length) { var itemInfo = award.AwardItemList[i]; itemBaisc.SetActive(true); ItemCellModel cellModel = new ItemCellModel((int)itemInfo.ItemID, false, (ulong)itemInfo.ItemCount); itemBaisc.Init(cellModel); } else { itemBaisc.SetActive(false); } } } private void OnUpdateNewAwardHave() { ResetAnimation(); } private void ResetAnimation() { currentState = MoveState.MovingDown; openTime = Time.time; winShow.anchoredPosition = startPosObject.anchoredPosition; positionTween.reversal = false; positionTween.from = startPosObject.anchoredPosition; positionTween.to = downPosObject.anchoredPosition; positionTween.duration = moveDurationTime; positionTween.Play(OnMoveDownComplete); Display(); } } }