Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
LightController / LightMode: - Новый LightMode.cs: enum эффектов под протокол 85XXYY (13 эффектов + Off) значения enum = коды команд XX, Off=-1 генерирует просто '85' - Новый LightController.cs: управление подсветкой платы * SetLight(mode, duration) → строит команду 85XXYY, возвращает LightSequence * Blink() / StopBlink() / SetBlinkInterval() — мигание шляпы * StopSequence() / StopAllEffects() — остановка эффектов * Все параметры (hatOn/hatOff, blinkInterval, defaultMode/Duration) в инспекторе - Вложенный класс LightSequence — builder цепочек эффектов: SetLight(A,3).Then(B,3).Then(C,3).Loop() SetLight(A,3).Then(LightMode.Off) SetLight(A,5) — одиночный эффект GameManager: - Добавлено свойство Light (→ Plate.Light) - GameWin → SetLight(FinalWave, 30) - GameOver → SetLight(BlueWave, 30) - NewGame → SetLight(Rainbow, 99) - LoadScene MainMenu → SetLight(Off) + Blink() namespace (добавлены в файлы без namespace): - Editor/MouseWorldPositionOverlay.cs → RR.Common.InspectorOverrides - UI/StatsWindowUIController.cs → RR.Common.UI - Utilities/AdvancedLogging_Test.cs → RR.Common.Utility - Utilities/DebugSettings.cs → RR.Common.Utility
110 lines
3.2 KiB
C#
110 lines
3.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using RR.Common.Controls;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
namespace RR.Common.UI
|
|
{
|
|
|
|
public class StatsWindowUIController : MonoBehaviour
|
|
{
|
|
[Header("Управление")]
|
|
[SerializeField] private InputActionReference triggerKey;
|
|
|
|
[Header("Тексты статистики")]
|
|
[SerializeField] private string gamesPlayedTextPrefix = "Игр сыграно: ";
|
|
[SerializeField] private TextMeshProUGUI gamesPlayedText;
|
|
[SerializeField] private string prizesGivenTextPrefix = "Призов выдано: ";
|
|
[SerializeField] private TextMeshProUGUI prizesGivenText;
|
|
|
|
[Header("UI")]
|
|
[SerializeField] private CanvasGroup canvasGroup;
|
|
[SerializeField] private float fadeDuration = 0.15f;
|
|
|
|
private string _gamesPlayedKey;
|
|
private string _prizesGivenKey;
|
|
|
|
private void Awake()
|
|
{
|
|
_gamesPlayedKey = PrizeSystem.key_startsNul;
|
|
_prizesGivenKey = PrizeSystem.key_prizesgivenNul;
|
|
|
|
if (triggerKey != null) triggerKey.action.performed += Toggle;
|
|
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (triggerKey != null) triggerKey.action.performed -= Toggle;
|
|
}
|
|
|
|
private void Toggle(InputAction.CallbackContext ctx)
|
|
{
|
|
if (gameObject.activeSelf)
|
|
{
|
|
Close();
|
|
}
|
|
else
|
|
{
|
|
Open();
|
|
}
|
|
}
|
|
|
|
private void Open()
|
|
{
|
|
gameObject.SetActive(true);
|
|
UpdateText();
|
|
StopAllCoroutines();
|
|
StartCoroutine(Fade(0f, 1f, fadeDuration));
|
|
}
|
|
|
|
private void Close()
|
|
{
|
|
StopAllCoroutines();
|
|
StartCoroutine(Fade(1f, 0f, fadeDuration, () => { gameObject.SetActive(false); }));
|
|
}
|
|
|
|
private void UpdateText()
|
|
{
|
|
if (gamesPlayedText)
|
|
{
|
|
int gamesPlayed = PlayerPrefs.GetInt(_gamesPlayedKey, 0);
|
|
gamesPlayedText.text = gamesPlayedTextPrefix + gamesPlayed;
|
|
}
|
|
|
|
if (prizesGivenText)
|
|
{
|
|
int prizesGiven = PlayerPrefs.GetInt(_prizesGivenKey, 0);
|
|
prizesGivenText.text = prizesGivenTextPrefix + prizesGiven;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Метод для плавного перехода (затухания)
|
|
/// </summary>
|
|
/// <param name="from">Начальная прозрачность</param>
|
|
/// <param name="to">Конечная прозрачность</param>
|
|
/// <param name="time">Время перехода</param>
|
|
/// <param name="onDone">Действие при выполнении перехода</param>
|
|
private IEnumerator Fade(float from, float to, float time, System.Action onDone = null)
|
|
{
|
|
if (!canvasGroup) { onDone?.Invoke(); yield break; }
|
|
float t = 0f;
|
|
canvasGroup.alpha = from;
|
|
canvasGroup.blocksRaycasts = true;
|
|
while (t < time)
|
|
{
|
|
t += Time.unscaledDeltaTime;
|
|
canvasGroup.alpha = Mathf.Lerp(from, to, t / time);
|
|
yield return null;
|
|
}
|
|
canvasGroup.alpha = to;
|
|
canvasGroup.blocksRaycasts = to > 0.99f;
|
|
onDone?.Invoke();
|
|
}
|
|
}
|
|
} // namespace RR.Common.UI
|