public void Restart() { saveGame.Delete(); score.Reset(); characterProvider.Clear(); pathFinder.DestroyPathMarkers(); RandomSpawn(); gameWorldInput.enabled = true; }
public void Load() { if (!File.Exists(filePath)) { Debug.Log("Нет сохранения"); _gameWorld.Restart(); return; } Save save; try { string json = File.ReadAllText(filePath); save = JsonUtility.FromJson <Save>(json); } catch (Exception ex) { Debug.LogWarning(ex); Debug.LogWarning("сохранения не подходят"); _gameWorld.Restart(); return; } if (save.allCharacters == null || save.nextCharacters == null) { Debug.LogWarning("в файле сохраниения нет данных"); _gameWorld.Restart(); return; } _score.Reset(); _characterProvider.Clear(); _score.Add(save.score); SaveCharacter[] savedCharacters = save.allCharacters; foreach (var item in savedCharacters) { _characterProvider.Create(item.x, item.y, item.prefabIndex); } _gameWorld.SetNextCharacters(save.nextCharacters); if (_characterProvider.GetAllFillPosition().Count == 0) { _gameWorld.RandomSpawn(); } }