- добавил частицы при смерти игрока - Временно включил функцию выбора уровня
75 lines
2.4 KiB
C#
75 lines
2.4 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
|
|
using RR.Game2D.Core.Managers;
|
|
|
|
namespace RR.Common.UI
|
|
{
|
|
public class LevelButton : MonoBehaviour
|
|
{
|
|
[SerializeField] private TextMeshProUGUI title;
|
|
[SerializeField] private Button button;
|
|
|
|
private int _world;
|
|
private int _stage;
|
|
|
|
public void Setup(
|
|
string levelSceneName,
|
|
int levelWorld,
|
|
int levelStage,
|
|
Selectable onUp = null,
|
|
Selectable onDown = null,
|
|
Selectable onLeft = null,
|
|
Selectable onRight = null
|
|
)
|
|
{
|
|
_world = levelWorld;
|
|
_stage = levelStage;
|
|
if (title) title.text = levelSceneName; // "1-3, 1-1 и т.д."
|
|
|
|
if (!button)
|
|
{
|
|
button = GetComponentInChildren<Button>();
|
|
if (!button)
|
|
{
|
|
Debug.LogError($"[LevelButton] Button component is missing on {gameObject.name}!");
|
|
return;
|
|
}
|
|
}
|
|
|
|
button.interactable = true;
|
|
button.onClick.RemoveAllListeners();
|
|
button.onClick.AddListener(OnClick);
|
|
|
|
// Настройка навигации, если передан хотя бы один параметр
|
|
if (onUp == null && onDown == null && onLeft == null && onRight == null) return;
|
|
Navigation nav = button.navigation;
|
|
nav.mode = Navigation.Mode.Explicit;
|
|
if (onUp != null) nav.selectOnUp = onUp;
|
|
if (onDown != null) nav.selectOnDown = onDown;
|
|
if (onLeft != null) nav.selectOnLeft = onLeft;
|
|
if (onRight != null) nav.selectOnRight = onRight;
|
|
button.navigation = nav;
|
|
}
|
|
|
|
public void SetColor(Color newColor)
|
|
{
|
|
ColorBlock newColors = button.colors;
|
|
newColors.normalColor = Darken(newColor, 0.65f);
|
|
newColors.highlightedColor = Darken(newColor, 0.90f);
|
|
newColors.selectedColor = newColor;
|
|
newColors.pressedColor = Darken(newColor, 0.80f);
|
|
button.colors = newColors;
|
|
}
|
|
|
|
private void OnClick()
|
|
{
|
|
GameManager.Instance.LoadLevel(_world, _stage);
|
|
}
|
|
|
|
private static Color Darken(Color c, float factor)
|
|
=> new Color(c.r * factor, c.g * factor, c.b * factor, c.a);
|
|
}
|
|
}
|