using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace vnxbqy.UI { public class AchievementTipWin : 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; // 挂载往上移动位置的游戏物体 float openTime; AchievementModel model { get { return ModelCenter.Instance.GetModelEx(); } } private enum MoveState { MovingDown, Staying, MovingUp, Finished } MoveState currentState; #region Built-in protected override void AddListeners() { awardBtn.SetListener(() => { ILAchievementModel.Instance.GetAchievementReward(ILAchievementModel.Instance.newSuccID); WindowCenter.Instance.Close(); }); } protected override void BindController() { } protected override void OnAfterClose() { StopAllCoroutines(); } protected override void OnAfterOpen() { ResetAnimation(); } protected override void OnPreClose() { ILAchievementModel.Instance.OnNewSuccAward -= OnNewSuccAward; } protected override void OnPreOpen() { ILAchievementModel.Instance.OnNewSuccAward += OnNewSuccAward; 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() { awardtip.text = AchievementModel.ParseAchievementDescription(ILAchievementModel.Instance.newSuccID); DisplayItemCell(); } private void OnNewSuccAward() { ResetAnimation(); } private void DisplayItemCell() { int successID = ILAchievementModel.Instance.newSuccID; Achievement achievement; model.TryGetAchievement(successID, out achievement); if (achievement != null) { var config = SuccessConfig.Get(successID); for (int i = 0; i < itemCells.Count; i++) { if (i < achievement.rewardItem.Length) { itemCells[i].SetActive(true); var _item = achievement.rewardItem[i]; ItemCellModel _ItemData = new ItemCellModel(_item.id, true, (ulong)_item.count); itemCells[i].Init(_ItemData); } else { itemCells[i].SetActive(false); } } } } 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(); } } }