|
|
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- using NaughtyAttributes;
- using Variables;
-
- public class LevelManager : MonoBehaviour
- {
- [SerializeField, Header("References")]
- Reference<bool> m_isPlayerDead;
-
- [SerializeField]
- Reference<bool> m_freezePlayer;
-
- [SerializeField]
- Reference<bool> m_isVictory;
-
- [SerializeField]
- Reference<float> m_timer;
-
-
- [SerializeField, BoxGroup("Level Settings")]
- private string m_levelName = "Level 1";
-
- [SerializeField, BoxGroup("Level Settings")]
- private float m_timeInLevel = 10;
-
- [SerializeField]
- private float m_resetTime = 1;
-
- [SerializeField]
- private string m_nextSceneToLoad = "Level 2";
-
-
- private IResettable[] m_allResetable;
-
- private void Start()
- {
- m_allResetable = FindObjectsOfType<MonoBehaviour>().OfType<IResettable>().ToArray();
- m_timer.Value = m_timeInLevel;
-
- foreach (IResettable resettable in m_allResetable)
- {
- resettable.OnLevelLoad();
- }
- }
-
- private void Update()
- {
- if (!m_freezePlayer)
- m_timer.Value -= Time.deltaTime;
- }
-
-
-
- private void OnEnable()
- {
- m_isPlayerDead.OnValueChanged += OnPlayerDeadChange;
- m_isVictory.OnValueChanged += OnPlayerVictoryChange;
- }
-
- private void OnDisable()
- {
- m_isPlayerDead.OnValueChanged -= OnPlayerDeadChange;
- m_isVictory.OnValueChanged -= OnPlayerVictoryChange;
- }
-
-
- private IEnumerator DeathRoutine()
- {
- m_freezePlayer.Value = true;
-
-
-
- m_timer.Value = m_timeInLevel;
- foreach (IResettable resettable in m_allResetable)
- StartCoroutine(resettable.OnResetStart(m_resetTime));
-
- yield return new WaitForSeconds(m_resetTime);
-
- foreach (IResettable resettable in m_allResetable)
- resettable.OnResetEnd();
-
-
- m_freezePlayer.Value = false;
- }
-
-
-
-
-
- private void OnPlayerDeadChange(bool value)
- {
- if (value)
- {
- StartCoroutine(DeathRoutine());
- }
-
-
- }
-
- private void OnPlayerVictoryChange(bool value)
- {
-
- }
-
-
-
-
-
-
- }
|