SHADE_Y3/Assets/Scripts/UI/SC_Results.cs

112 lines
3.0 KiB
C#
Raw Permalink Normal View History

2023-04-01 00:35:16 +08:00
using SHADE;
using SHADE_Scripting.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class Results : Script
{
public GameObject score;
public GameObject timeLeft;
public GameObject maxCombo;
public GameObject finalScore;
public GameObject contiuneBtn;
2023-04-01 18:07:22 +08:00
public GameObject levelTransition;
2023-04-01 00:35:16 +08:00
public uint nextScene;
public float scoreTweenDur = 2.0f;
private TextRenderable scoreText;
private TextRenderable timeLeftText;
private TextRenderable maxComboText;
private TextRenderable finalScoreText;
private int scoreCount = 0;
private bool once = true;
[NonSerialized]
private TweenThread scoreTween;
private bool waitForTransition;
protected override void awake()
{
scoreText = score.GetComponent<TextRenderable>();
if (!scoreText)
Debug.LogError("MISSING SCORE TEXT");
timeLeftText = timeLeft.GetComponent<TextRenderable>();
if (!timeLeftText)
Debug.LogError("MISSING TIME LEFT TEXT");
maxComboText = maxCombo.GetComponent<TextRenderable>();
if (!maxComboText)
Debug.LogError("MISSING MAX COMBO TEXT");
finalScoreText = finalScore.GetComponent<TextRenderable>();
if (!finalScoreText)
Debug.LogError("MISSING FINAL SCORE TEXT");
if (!contiuneBtn)
Debug.LogError("MISSING CONTIUNE BTN");
else
contiuneBtn.SetActive(false);
waitForTransition = false;
}
protected override void start()
{
scoreCount = GameManager.Instance.Score + (GameManager.Instance.finalTime * 100);
if(scoreText)
scoreText.Text = $"{GameManager.Instance.Score}";
if (timeLeftText)
timeLeftText.Text = $"{GameManager.Instance.finalTime}s";
if (maxComboText)
maxComboText.Text = $"X{GameManager.Instance.MaxComboAccquired}";
if (finalScoreText)
finalScoreText.Text = $"{scoreCount}";
UIElement contiune = contiuneBtn.GetComponent<UIElement>();
if (contiune != null)
{
contiune.OnRelease.RegisterAction(() =>
{
2023-04-01 18:07:22 +08:00
levelTransition.GetScript<LevelTransistion>().resetToLeft();
2023-04-01 00:35:16 +08:00
waitForTransition = true;
GameManager.Instance.GamePause = false;
Application.FixDeltaTime = Time.DefaultFixDeltaTime;
AnimationSystem.TimeScale = AnimationSystem.DefaultTimeScale;
});
}
else
{
Debug.LogError("Failed to register contiune button.");
}
scoreTween = TweenManager.CreateTweenThread(scoreTweenDur, 0, scoreCount, EASING_METHOD.EASE_IN_SINE);
}
protected override void update()
{
2023-04-01 18:07:22 +08:00
if (levelTransition.GetScript<LevelTransistion>().complete && waitForTransition)
2023-04-01 00:35:16 +08:00
{
Audio.StopAllSounds();
SceneManager.ChangeScene(nextScene);
}
if (finalScoreText && !scoreTween.IsCompleted())
finalScoreText.Text = $"{(int)scoreTween.GetValue()}";
else if(scoreTween.IsCompleted() && once)
{
contiuneBtn.SetActive(true);
finalScoreText.Text = $"{scoreCount}";
once = false;
}
}
}