using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class DataHolder : MonoBehaviour { public static DataHolder main; public List easyLevels; public List normalLevels; public List hardLevels; public List PlayerEquipment = new List(); public List AllEquipment = new List(); public MissionConfig mission; [SerializeField] private string _currentScene; public bool warning = true; private int score = 10; public enum complexityLevels { easy, normal, hard, all }; private void Awake() { if(_currentScene == null) { Debug.LogError("WARNING! _currentScene in DataHolder not found"); } if (main != null && main != this) { Debug.LogWarning("2 dataholders on the scene"); Destroy(this); return; } main = this; } public void SetScore(int _newScore) { score = _newScore; } public int GetScore() { return score; } public void ChangeScene(string _sceneName) { SceneManager.LoadScene(_sceneName, LoadSceneMode.Additive); SceneManager.UnloadSceneAsync(_currentScene); _currentScene = _sceneName; } //RANDOM LEVELS BLOCK public BattleConfig RandomLevel(complexityLevels _complexity) { switch (_complexity) { case complexityLevels.easy: return RandomEasyLevel(); case complexityLevels.normal: return RandomNormalLevel(); case complexityLevels.hard: return RandomHardLevel(); default: return RandomAllLevel(); } } private BattleConfig RandomEasyLevel() { return easyLevels[Random.Range(0, easyLevels.Count)]; } private BattleConfig RandomNormalLevel() { return normalLevels[Random.Range(0, normalLevels.Count)]; ; } private BattleConfig RandomHardLevel() { return hardLevels[Random.Range(0, hardLevels.Count)]; } private BattleConfig RandomAllLevel() { int _maxNumber = Random.Range(0, easyLevels.Count + normalLevels.Count + hardLevels.Count); if (_maxNumber < easyLevels.Count) { Debug.Log(_maxNumber); return easyLevels[_maxNumber]; } else if (_maxNumber - easyLevels.Count < normalLevels.Count) { return normalLevels[_maxNumber - easyLevels.Count]; } else { return hardLevels[_maxNumber - easyLevels.Count - normalLevels.Count]; } } //RANDOM LEVELS BLOCK END public void NewMission(MissionConfig _mission) { mission = _mission; } public void ReturnInMainMenu() { ChangeScene("MainMenu"); } public void AddEquipmentToPlayerInventory(GameObject _item) { AllEquipment.Add(_item); } }