Files
GeoSusGame/Assets/Scripts/hod_veci_do_diry/LevelManager.cs
2026-04-26 12:55:21 +02:00

69 lines
1.5 KiB
C#
Raw 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 System;
using UnityEngine;
using UnityEngine.Events;
using GeoSus.Client;
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 Position 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);
}
}