44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using RR.Game2D.Core;
|
|
|
|
public class LevelButton : MonoBehaviour
|
|
{
|
|
[SerializeField] TextMeshProUGUI title;
|
|
[SerializeField] Button btn;
|
|
|
|
private int world;
|
|
private int stage;
|
|
|
|
public void Setup(string levelSceneName, int levelWorld, int levelStage)
|
|
{
|
|
world = levelWorld;
|
|
stage = levelStage;
|
|
if (title) title.text = levelSceneName; // "1-3, 1-1 и т.д."
|
|
if (btn) { btn.onClick.RemoveAllListeners(); btn.onClick.AddListener(OnClick); }
|
|
}
|
|
|
|
public void SetColor(Color newColor)
|
|
{
|
|
ColorBlock newColors = btn.colors;
|
|
newColors.normalColor = newColor;
|
|
newColors.highlightedColor = Darken(newColor, 0.90f);
|
|
newColors.selectedColor = Darken(newColor, 0.85f);
|
|
newColors.pressedColor = Darken(newColor, 0.80f);
|
|
btn.colors = newColors;
|
|
}
|
|
|
|
void OnClick()
|
|
{
|
|
// через GameManager (предпочтительно)
|
|
GameManager.Instance.LoadLevel(world, stage);
|
|
|
|
// Фоллбэк, если нужно:
|
|
// UnityEngine.SceneManagement.SceneManager.LoadScene(sceneName);
|
|
}
|
|
|
|
private static Color Darken(Color c, float factor)
|
|
=> new Color(c.r * factor, c.g * factor, c.b * factor, c.a);
|
|
}
|