87 lines
2.5 KiB
C#
87 lines
2.5 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
/// <summary>
|
|
/// Runtime text HUD for generation parameters, counters and short status messages.
|
|
/// </summary>
|
|
public class LevelGenUI : MonoBehaviour
|
|
{
|
|
public Text titleText;
|
|
public Text hintsText;
|
|
public Text parametersText;
|
|
public Text statusText;
|
|
public Text messageText;
|
|
public float refreshInterval = 0.2f;
|
|
|
|
public LevelGenerator generator;
|
|
private float nextRefreshTime;
|
|
private float messageHideTime;
|
|
|
|
private void Start()
|
|
{
|
|
UpdateInfo();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Time.time >= nextRefreshTime)
|
|
{
|
|
UpdateInfo();
|
|
nextRefreshTime = Time.time + refreshInterval;
|
|
}
|
|
|
|
if (messageText != null && messageText.gameObject.activeSelf && Time.time > messageHideTime)
|
|
{
|
|
messageText.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
public void SetGenerator(LevelGenerator generator)
|
|
{
|
|
this.generator = generator;
|
|
UpdateInfo();
|
|
}
|
|
|
|
public void UpdateInfo()
|
|
{
|
|
if (titleText != null)
|
|
{
|
|
titleText.text = "Лабораторная работа №1 — Процедурная генерация уровня";
|
|
}
|
|
|
|
if (hintsText != null)
|
|
{
|
|
hintsText.text = "WASD — движение\nSpace — прыжок\nR — пересоздать уровень";
|
|
}
|
|
|
|
if (parametersText != null && generator != null)
|
|
{
|
|
parametersText.text =
|
|
"Initial Platforms: " + generator.initialPlatformCount + "\n" +
|
|
"Step Distance: " + generator.stepDistance.ToString("0.0") + "\n" +
|
|
"Obstacle Chance: " + generator.obstacleChance.ToString("0.00") + "\n" +
|
|
"Alive Platforms: " + generator.GetAlivePlatformCount() + "\n" +
|
|
"Generated Total: " + generator.GetGeneratedCount();
|
|
}
|
|
|
|
if (statusText != null && generator != null)
|
|
{
|
|
statusText.text =
|
|
"Бесконечный режим: " + (generator.infiniteMode ? "включён" : "выключен") + "\n" +
|
|
"Старые платформы удаляются позади игрока";
|
|
}
|
|
}
|
|
|
|
public void ShowMessage(string message)
|
|
{
|
|
if (messageText == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
messageText.text = message;
|
|
messageText.gameObject.SetActive(true);
|
|
messageHideTime = Time.time + 2f;
|
|
}
|
|
}
|