Files
GeoSusGame/Assets/Scripts/hod_veci_do_diry/LevelManager.cs
2026-05-27 21:32:22 +02:00

126 lines
3.1 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.
<<<<<<< HEAD
using System;
using UnityEngine;
using UnityEngine.Events;
using GeoSus.Client;
=======
using UnityEngine;
using UnityEngine.Events;
using System;
>>>>>>> origin/main
public class LevelManager : MonoBehaviour, ITask
{
public static LevelManager Instance;
[Header("Nastavení levelu")]
[Tooltip("Kolik itemů musí hráč trefit pro splnění levelu")]
<<<<<<< HEAD
public int itemsToScore = 2;
=======
public int itemsToScore = 3;
>>>>>>> origin/main
[Header("Event vyvolá se po trefení všech itemů")]
public UnityEvent OnAllItemsScored;
private int scoredCount = 0;
<<<<<<< HEAD
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;
=======
// ── ITask ────────────────────────────────────────────────────────────────
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; }
private Action<ITask> _onCompleted;
private Action<ITask> _onExit;
public void Initialize(Action<ITask> onCompleted)
{
IsCompleted = false;
_onCompleted = onCompleted;
ResetCounter();
// Wire OnAllItemsScored to Complete() if not already wired
OnAllItemsScored.AddListener(Complete);
}
public void Complete()
{
if (IsCompleted) return;
IsCompleted = true;
Debug.Log("[LevelManager] Task complete!");
_onCompleted?.Invoke(this);
ExitTask(_onExit);
}
public void ExitTask(Action<ITask> onExit)
{
onExit?.Invoke(this);
}
// ─────────────────────────────────────────────────────────────────────────
void Awake()
{
if (Instance == null) Instance = this;
else Destroy(gameObject);
}
>>>>>>> origin/main
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;
<<<<<<< HEAD
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);
}
}
=======
}
>>>>>>> origin/main