SamsonGame/Assets/Scripts/Game/UI/Elements/LevelProgression.cs

93 lines
3.2 KiB
C#
Raw Normal View History

2021-12-29 20:50:11 +03:00
using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;
public class LevelProgression : MonoBehaviour
{
[SerializeField] private Text levelText;
[SerializeField] private Image filler;
[SerializeField] private Image currentLeague;
[SerializeField] private Image nextLeague;
[SerializeField] private GameObject[] currentLevelDots;
private int _sequenceLength;
private const float FillOffset = 0.1f;
public void InitProgression(bool isWin = false)
{
/*_sequenceLength = G.Instance.Game.Progress.MiniSequenceLength;
if (isWin)
{
int sequencePosition = G.Instance.Game.Progress.ProgressInMiniSequence;
int prevSequencePosition = sequencePosition - 1 < 0 ? 4 : sequencePosition - 1;
filler.fillAmount = (prevSequencePosition) / (float) _sequenceLength + FillOffset;
ShowCurrentDot(prevSequencePosition);
int prevLeagueNumber =
Mathf.FloorToInt((G.Instance.Game.Progress.CompletedLevels - 1) / (float) _sequenceLength) - 1;
ShowLeagueIcons(prevLeagueNumber);
int currentLeagueNumber =
Mathf.FloorToInt(G.Instance.Game.Progress.CompletedLevels / (float) _sequenceLength) - 1;
Sequence seq = DOTween.Sequence();
seq.AppendCallback(() => { ShowCurrentDot(sequencePosition); }).SetDelay(1f);
seq.Join(filler
.DOFillAmount((sequencePosition) / (float) _sequenceLength + FillOffset, 1f)
.SetDelay(0.5f)
.SetEase(Ease.InOutCubic)
);
if (prevLeagueNumber != currentLeagueNumber)
{
seq.AppendCallback(() =>
{
ShowLeagueIcons(currentLeagueNumber);
currentLeague.transform.DOPunchScale(Vector3.one * 0.5f, 0.3f);
nextLeague.transform.DOPunchScale(Vector3.one * 0.5f, 0.3f);
});
}
seq.Play();
}
else
{
filler.fillAmount = (G.Instance.Game.Progress.ProgressInMiniSequence) / (float) _sequenceLength +
FillOffset;
ShowCurrentDot(G.Instance.Game.Progress.ProgressInMiniSequence);
int currentLeagueNumber =
Mathf.FloorToInt(G.Instance.Game.Progress.CompletedLevels / (float) _sequenceLength) - 1;
ShowLeagueIcons(currentLeagueNumber);
}*/
}
/*private void ShowLeagueIcons(int currentLeagueIndex)
{
bool needShowCurrent = currentLeagueIndex >= 0;
bool needShowNext = currentLeagueIndex + 1 < leagueSet.leagues.Count;
currentLeague.gameObject.SetActive(needShowCurrent);
if (needShowCurrent)
currentLeague.sprite = leagueSet.leagues[Mathf.Min(leagueSet.leagues.Count - 1, currentLeagueIndex)].icon;
nextLeague.gameObject.SetActive(needShowNext);
if (needShowNext)
nextLeague.sprite = leagueSet.leagues[currentLeagueIndex + 1].icon;
}
private void ShowCurrentDot(int index)
{
foreach (GameObject currentLevelDot in currentLevelDots)
currentLevelDot.SetActive(false);
currentLevelDots[index].SetActive(true);
}*/
}