Files
GeoSusGame/Assets/Scripts/hod_veci_do_diry/LevelManager.cs
2026-05-31 20:55:36 +02:00

71 lines
1.5 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using UnityEngine;
using UnityEngine.Events;
using System;
public class LevelManager : MonoBehaviour, ITask
{
public static LevelManager Instance;
[Header("Nastavení levelu")]
[Tooltip("Kolik itemů musí hráč trefit pro splnění levelu")]
public int itemsToScore = 3;
[Header("Event vyvolá se po trefení všech itemů")]
public UnityEvent OnAllItemsScored;
private int scoredCount = 0;
public string TaskID { get; set; }
public TaskType TaskType { get; set; }
public string TaskName { get; set; }
public (double, double) TaskLocation { get; set; }
public bool IsCompleted { get; private set; } = false;
protected Action<ITask> OnCompleted;
public void RegisterItem()
{
scoredCount++;
Debug.Log($"Trefeno: {scoredCount} / {itemsToScore}");
if (scoredCount >= itemsToScore)
{
OnAllItemsScored?.Invoke();
}
}
public void ResetCounter()
{
scoredCount = 0;
}
public int GetScoredCount() => scoredCount;
public int GetTotalCount() => itemsToScore;
public void Initialize(Action<ITask> onCompleted)
{
OnCompleted = onCompleted;
IsCompleted = false;
ResetCounter();
}
public void ExitTask(Action<ITask> onExit)
{
onExit?.Invoke(this);
}
public void Complete()
{
if (IsCompleted) return;
IsCompleted = true;
OnCompleted?.Invoke(this);
}
}