胶片滚动逻辑
This commit is contained in:
parent
be7c315928
commit
6ee3d925a5
|
|
@ -2,6 +2,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
using DG.Tweening;
|
||||||
|
|
||||||
public class PanelMain : BasePanel
|
public class PanelMain : BasePanel
|
||||||
{
|
{
|
||||||
|
|
@ -20,6 +21,18 @@ public class PanelMain : BasePanel
|
||||||
private int mTotalLevel;
|
private int mTotalLevel;
|
||||||
private const int FOCUS_IDX = 2;
|
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()
|
private void Awake()
|
||||||
{
|
{
|
||||||
UIUtils.BindBtn(mBtnLast, OnClickLast);
|
UIUtils.BindBtn(mBtnLast, OnClickLast);
|
||||||
|
|
@ -32,9 +45,31 @@ public class PanelMain : BasePanel
|
||||||
{
|
{
|
||||||
base.OnOpen();
|
base.OnOpen();
|
||||||
|
|
||||||
|
mRollTimer = TimerManager.Instance.CreateTimerUnit();
|
||||||
|
|
||||||
InitLevelIcons();
|
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()
|
private void InitLevelIcons()
|
||||||
{
|
{
|
||||||
mTotalLevel = GameConfig.Instance.LevelSort.Count;
|
mTotalLevel = GameConfig.Instance.LevelSort.Count;
|
||||||
|
|
@ -48,6 +83,8 @@ public class PanelMain : BasePanel
|
||||||
mImgLevelIcons[i].sprite = ResourceManager.Instance.LoadRes<Sprite>(Const.Path.GetLevelIconBig(GameConfig.Instance.LevelSort[(tLevel - 1) % mTotalLevel]));
|
mImgLevelIcons[i].sprite = ResourceManager.Instance.LoadRes<Sprite>(Const.Path.GetLevelIconBig(GameConfig.Instance.LevelSort[(tLevel - 1) % mTotalLevel]));
|
||||||
mLevelIconList.Add(mImgLevelIcons[i]);
|
mLevelIconList.Add(mImgLevelIcons[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Waft();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int GetLevelInCircle(int pLevelNum, int pTotalLevel)
|
private int GetLevelInCircle(int pLevelNum, int pTotalLevel)
|
||||||
|
|
@ -68,28 +105,45 @@ public class PanelMain : BasePanel
|
||||||
return tFinalLevel;
|
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<RectTransform>().DOKill();
|
||||||
|
mLevelIconList[i].GetComponent<RectTransform>().DOAnchorPosX(mIconPosX[i], FIX_DURATION).SetEase(Ease.OutSine);
|
||||||
}
|
}
|
||||||
|
|
||||||
Image tEndImg = mLevelIconList[mLevelIconList.Count - 1];
|
mRollTimer.StartTimer(Waft, FIX_WAIT);
|
||||||
for (int i = mLevelIconList.Count - 2; i >= 0; i--)
|
|
||||||
{
|
|
||||||
int tNextIndex = (i + 1) % mLevelIconList.Count;
|
|
||||||
|
|
||||||
mLevelIconList[tNextIndex] = mLevelIconList[i];
|
|
||||||
mLevelIconList[tNextIndex].GetComponent<RectTransform>().anchoredPosition = new Vector2(mIconPosX[tNextIndex], 0);
|
|
||||||
}
|
|
||||||
mLevelIconList[0] = tEndImg;
|
|
||||||
mLevelIconList[0].sprite = ResourceManager.Instance.LoadRes<Sprite>(Const.Path.GetLevelIconBig(GameConfig.Instance.LevelSort[mLevelList[0] - 1]));
|
|
||||||
mLevelIconList[0].GetComponent<RectTransform>().anchoredPosition = new Vector2(mIconPosX[0], 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnClickNext()
|
private void Waft()
|
||||||
{
|
{
|
||||||
|
mIsWafting = true;
|
||||||
|
mIsRolling = false;
|
||||||
|
|
||||||
|
for (int i = 1; i < mLevelIconList.Count - 1; i++)
|
||||||
|
{
|
||||||
|
mLevelIconList[i].GetComponent<RectTransform>().DOKill();
|
||||||
|
mLevelIconList[i].GetComponent<RectTransform>().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++)
|
for (int i = 0; i < mLevelList.Count; i++)
|
||||||
{
|
{
|
||||||
mLevelList[i] = GetLevelInCircle(mLevelList[i] + 1, mTotalLevel);
|
mLevelList[i] = GetLevelInCircle(mLevelList[i] + 1, mTotalLevel);
|
||||||
|
|
@ -101,11 +155,81 @@ public class PanelMain : BasePanel
|
||||||
int tLastIndex = (i - 1) % mLevelIconList.Count;
|
int tLastIndex = (i - 1) % mLevelIconList.Count;
|
||||||
|
|
||||||
mLevelIconList[tLastIndex] = mLevelIconList[i];
|
mLevelIconList[tLastIndex] = mLevelIconList[i];
|
||||||
mLevelIconList[tLastIndex].GetComponent<RectTransform>().anchoredPosition = new Vector2(mIconPosX[tLastIndex], 0);
|
mLevelIconList[tLastIndex].GetComponent<RectTransform>().DOKill();
|
||||||
|
mLevelIconList[tLastIndex].GetComponent<RectTransform>().DOAnchorPosX(mIconPosX[tLastIndex], ROLL_DURATION).SetEase(Ease.OutSine);
|
||||||
}
|
}
|
||||||
mLevelIconList[mLevelIconList.Count - 1] = tStartImg;
|
mLevelIconList[mLevelIconList.Count - 1] = tStartImg;
|
||||||
mLevelIconList[mLevelIconList.Count - 1].sprite = ResourceManager.Instance.LoadRes<Sprite>(Const.Path.GetLevelIconBig(GameConfig.Instance.LevelSort[mLevelList[mLevelIconList.Count - 1] - 1]));
|
mLevelIconList[mLevelIconList.Count - 1].sprite = ResourceManager.Instance.LoadRes<Sprite>(Const.Path.GetLevelIconBig(GameConfig.Instance.LevelSort[mLevelList[mLevelIconList.Count - 1] - 1]));
|
||||||
mLevelIconList[mLevelIconList.Count - 1].GetComponent<RectTransform>().anchoredPosition = new Vector2(mIconPosX[mLevelIconList.Count - 1], 0);
|
mLevelIconList[mLevelIconList.Count - 1].GetComponent<RectTransform>().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<RectTransform>().DOKill();
|
||||||
|
mLevelIconList[tNextIndex].GetComponent<RectTransform>().DOAnchorPosX(mIconPosX[tNextIndex], ROLL_DURATION).SetEase(Ease.OutSine);
|
||||||
|
}
|
||||||
|
mLevelIconList[0] = tEndImg;
|
||||||
|
mLevelIconList[0].sprite = ResourceManager.Instance.LoadRes<Sprite>(Const.Path.GetLevelIconBig(GameConfig.Instance.LevelSort[mLevelList[0] - 1]));
|
||||||
|
mLevelIconList[0].GetComponent<RectTransform>().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()
|
private void OnClickStart()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue