From 6ee3d925a561c128570b3a37a187240ad520995f Mon Sep 17 00:00:00 2001 From: yangjing Date: Fri, 11 Feb 2022 12:04:53 +0800 Subject: [PATCH] =?UTF-8?q?=E8=83=B6=E7=89=87=E6=BB=9A=E5=8A=A8=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/UI/PanelMain.cs | 158 +++++++++++++++++++++++++++++---- 1 file changed, 141 insertions(+), 17 deletions(-) diff --git a/Assets/Scripts/UI/PanelMain.cs b/Assets/Scripts/UI/PanelMain.cs index 36bf3392..99d2d391 100644 --- a/Assets/Scripts/UI/PanelMain.cs +++ b/Assets/Scripts/UI/PanelMain.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; +using DG.Tweening; public class PanelMain : BasePanel { @@ -20,6 +21,18 @@ public class PanelMain : BasePanel private int mTotalLevel; private const int FOCUS_IDX = 2; + private int mWaftDir = 1; + private bool mIsWafting = false; + + private bool mIsRolling = false; + private TimerUnit mRollTimer; + + private const float FIX_DURATION = 0.2f; + private const float FIX_WAIT = 10; + + private const float ROLL_DURATION = 0.3f; + private const float WAFT_DURATION = 4f; + private void Awake() { UIUtils.BindBtn(mBtnLast, OnClickLast); @@ -32,9 +45,31 @@ public class PanelMain : BasePanel { base.OnOpen(); + mRollTimer = TimerManager.Instance.CreateTimerUnit(); + InitLevelIcons(); } + public override void OnClose() + { + base.OnClose(); + + if (mRollTimer != null) + { + mRollTimer.Destroy(); + mRollTimer = null; + } + } + + private void OnDestroy() + { + if (mRollTimer != null) + { + mRollTimer.Destroy(); + mRollTimer = null; + } + } + private void InitLevelIcons() { mTotalLevel = GameConfig.Instance.LevelSort.Count; @@ -48,6 +83,8 @@ public class PanelMain : BasePanel mImgLevelIcons[i].sprite = ResourceManager.Instance.LoadRes(Const.Path.GetLevelIconBig(GameConfig.Instance.LevelSort[(tLevel - 1) % mTotalLevel])); mLevelIconList.Add(mImgLevelIcons[i]); } + + Waft(); } private int GetLevelInCircle(int pLevelNum, int pTotalLevel) @@ -60,7 +97,7 @@ public class PanelMain : BasePanel tFinalLevel += pTotalLevel; } } - else if(tFinalLevel > pTotalLevel) + else if (tFinalLevel > pTotalLevel) { tFinalLevel = (tFinalLevel - 1) % pTotalLevel + 1; } @@ -68,28 +105,45 @@ public class PanelMain : BasePanel return tFinalLevel; } - private void OnClickLast() + private void FixRolling() { - for (int i = 0; i < mLevelList.Count; i++) + mIsWafting = false; + mIsRolling = false; + + for (int i = 1; i < mLevelIconList.Count - 1; i++) { - mLevelList[i] = GetLevelInCircle(mLevelList[i] - 1, mTotalLevel); + mLevelIconList[i].GetComponent().DOKill(); + mLevelIconList[i].GetComponent().DOAnchorPosX(mIconPosX[i], FIX_DURATION).SetEase(Ease.OutSine); } - Image tEndImg = mLevelIconList[mLevelIconList.Count - 1]; - for (int i = mLevelIconList.Count - 2; i >= 0; i--) - { - int tNextIndex = (i + 1) % mLevelIconList.Count; - - mLevelIconList[tNextIndex] = mLevelIconList[i]; - mLevelIconList[tNextIndex].GetComponent().anchoredPosition = new Vector2(mIconPosX[tNextIndex], 0); - } - mLevelIconList[0] = tEndImg; - mLevelIconList[0].sprite = ResourceManager.Instance.LoadRes(Const.Path.GetLevelIconBig(GameConfig.Instance.LevelSort[mLevelList[0] - 1])); - mLevelIconList[0].GetComponent().anchoredPosition = new Vector2(mIconPosX[0], 0); + mRollTimer.StartTimer(Waft, FIX_WAIT); } - private void OnClickNext() + private void Waft() { + mIsWafting = true; + mIsRolling = false; + + for (int i = 1; i < mLevelIconList.Count - 1; i++) + { + mLevelIconList[i].GetComponent().DOKill(); + mLevelIconList[i].GetComponent().DOAnchorPosX(mIconPosX[i] + mWaftDir * 80, WAFT_DURATION).SetEase(Ease.Linear); + } + + if (mWaftDir == 1) + { + mRollTimer.StartTimer(RollRight, WAFT_DURATION); + } + else + { + mRollTimer.StartTimer(RollLeft, WAFT_DURATION); + } + } + + private void RollLeft() + { + mIsRolling = true; + for (int i = 0; i < mLevelList.Count; i++) { mLevelList[i] = GetLevelInCircle(mLevelList[i] + 1, mTotalLevel); @@ -101,11 +155,81 @@ public class PanelMain : BasePanel int tLastIndex = (i - 1) % mLevelIconList.Count; mLevelIconList[tLastIndex] = mLevelIconList[i]; - mLevelIconList[tLastIndex].GetComponent().anchoredPosition = new Vector2(mIconPosX[tLastIndex], 0); + mLevelIconList[tLastIndex].GetComponent().DOKill(); + mLevelIconList[tLastIndex].GetComponent().DOAnchorPosX(mIconPosX[tLastIndex], ROLL_DURATION).SetEase(Ease.OutSine); } mLevelIconList[mLevelIconList.Count - 1] = tStartImg; mLevelIconList[mLevelIconList.Count - 1].sprite = ResourceManager.Instance.LoadRes(Const.Path.GetLevelIconBig(GameConfig.Instance.LevelSort[mLevelList[mLevelIconList.Count - 1] - 1])); mLevelIconList[mLevelIconList.Count - 1].GetComponent().anchoredPosition = new Vector2(mIconPosX[mLevelIconList.Count - 1], 0); + + mRollTimer.StartTimer(RollOver, ROLL_DURATION); + } + + private void RollRight() + { + mIsRolling = true; + + for (int i = 0; i < mLevelList.Count; i++) + { + mLevelList[i] = GetLevelInCircle(mLevelList[i] - 1, mTotalLevel); + } + + Image tEndImg = mLevelIconList[mLevelIconList.Count - 1]; + for (int i = mLevelIconList.Count - 2; i >= 0; i--) + { + int tNextIndex = (i + 1) % mLevelIconList.Count; + + mLevelIconList[tNextIndex] = mLevelIconList[i]; + mLevelIconList[tNextIndex].GetComponent().DOKill(); + mLevelIconList[tNextIndex].GetComponent().DOAnchorPosX(mIconPosX[tNextIndex], ROLL_DURATION).SetEase(Ease.OutSine); + } + mLevelIconList[0] = tEndImg; + mLevelIconList[0].sprite = ResourceManager.Instance.LoadRes(Const.Path.GetLevelIconBig(GameConfig.Instance.LevelSort[mLevelList[0] - 1])); + mLevelIconList[0].GetComponent().anchoredPosition = new Vector2(mIconPosX[0], 0); + + mRollTimer.StartTimer(RollOver, ROLL_DURATION); + } + + private void RollOver() + { + mIsRolling = false; + mRollTimer.StartTimer(Waft, mIsWafting ? -1 : FIX_WAIT); + } + + private void OnClickLast() + { + if (mIsRolling) + return; + + if (mIsWafting && mWaftDir == -1)//turn around + { + FixRolling(); + } + else + { + mIsWafting = false; + RollRight(); + } + + mWaftDir = 1; + } + + private void OnClickNext() + { + if (mIsRolling) + return; + + if (mIsWafting && mWaftDir == 1)//turn around + { + FixRolling(); + } + else + { + mIsWafting = false; + RollLeft(); + } + + mWaftDir = -1; } private void OnClickStart()