public void LoadGame() { var savableObjects = FindObjectsOfType <MonoBehaviour>().Where(monoObject => monoObject is ISavable).ToList(); ISavable playerObject = savableObjects.First(monoObject => monoObject is PlayerController) as ISavable; playerObject?.LoadData(GameSave.playerSaveData); }
public void LoadGame() { var savableObjects = FindObjectsOfType <MonoBehaviour>().Where(monoObject => monoObject is ISavable).ToList(); ISavable playerObject = savableObjects.First(monoObject => monoObject is PlayerController) as ISavable; playerObject?.LoadData(GameSave.PlayerSaveData); foreach (SpawnerSaveData spawnerData in GameSave.SpawnerSaveDataList.SpawnerData) { ISavable saveObject = savableObjects.Find(savableObject => spawnerData.Name == savableObject.name) as ISavable; saveObject?.LoadData(spawnerData); } }