PO/Assets/DataHolder.cs

134 lines
3.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class DataHolder : MonoBehaviour
{
public static DataHolder main;
public List<BattleConfig> easyLevels;
public List<BattleConfig> normalLevels;
public List<BattleConfig> hardLevels;
public List<GameObject> PlayerEquipment = new List<GameObject>();
public List<GameObject> AllEquipment = new List<GameObject>();
public MissionConfig mission;
[SerializeField] private string _currentScene;
private int score = 10;
private int missionChecker;
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;
missionChecker = 0;
}
public BattleConfig NextBattle()
{
missionChecker++;
if(missionChecker > mission.missionItems.Count)
{
return null;
}
return mission.missionItems[missionChecker - 1].battle;
}
public void ReturnInMainMenu()
{
ChangeScene("MainMenu");
}
public void AddEquipmentToPlayerInvaentary(GameObject _item)
{
AllEquipment.Add(_item);
}
}