/// <summary> /// loads in the level data if it exists /// </summary> private void LoadLevel() { GameSaver.levelDataObjects = FindObjectsOfType <MonoBehaviour>().OfType <ILevelData>(); LevelSaveData levelData = null; if ((levelData = GameSaver.LoadLevelData(areaName)) != null) { //create a dictionary of all the loaded in level dat Dictionary <string, bool> stateLookup = new Dictionary <string, bool>(); for (int i = 0; i < levelData.objectNames.Count; i++) { stateLookup.Add(levelData.objectNames[i], levelData.objectStates[i]); } //Debug.Log((FindObjectsOfType<MonoBehaviour>().OfType<ILevelData>()).Count<ILevelData>()); //loop through all the level data objects foreach (ILevelData data in GameSaver.levelDataObjects) { //load objects based on state from the dictionary if (stateLookup.ContainsKey(data.Name)) { data.OnLevelLoad(stateLookup[data.Name]); } } BreakableTilemap breakable = FindObjectOfType <BreakableTilemap>(); if (breakable) { List <Vector2Int> tempBroken = new List <Vector2Int>(); foreach (int[] pos in levelData.broken) { tempBroken.Add(new Vector2Int(pos[0], pos[1])); } breakable.Broken = tempBroken; } } }