// When you press the "Save Level as..." button public void OnSaveLevelAsButtonPressed() { // Initializes SaveFileDialog with some values SaveFileDialog dialog = new SaveFileDialog(); dialog.Filter = "Level Save Files (*.sav)|*.sav"; dialog.FileName = "newLevel.sav"; dialog.RestoreDirectory = true; dialog.InitialDirectory = UnityEngine.Application.dataPath + "/Saved Levels"; DialogResult result = dialog.ShowDialog(); switch(result) { case DialogResult.OK: LevelObjectEditor.current.DeselectObject(); loadSaveUtility.SaveGame(dialog.FileName, Path.GetFileNameWithoutExtension(dialog.FileName)); //Debug.Log("Save filed as: " + dialog.FileName); LevelSaveManager.RecordSave(dialog.FileName); YesNoDialog.current.CancelDialog(); break; case DialogResult.Cancel: YesNoDialog.current.CloseDialog(); break; } }
private void LoadLevel() { // Windows forms OpenFileDialog OpenFileDialog dialog = new OpenFileDialog(); // Asks for .sav files only dialog.Filter = "Level Save Files (*.sav)|*.sav"; dialog.RestoreDirectory = true; dialog.InitialDirectory = UnityEngine.Application.dataPath + "/Saved Levels"; // Gets path from dialog if (dialog.ShowDialog() == DialogResult.OK) { LevelObjectEditor.current.DeselectObject(); string path = dialog.FileName; loadSaveUtility.LoadGame(path); LevelSaveManager.RecordSave(path); YesNoDialog.current.CancelDialog(); } else { YesNoDialog.current.CloseDialog(); } }
// When you press the "Save Level..." button public void OnSaveLevelButtonPressed() { // Checks if the level has a path already or if we need to set a location and name first if (!LevelSaveManager.loadedFromPath) { OnSaveLevelAsButtonPressed(); return; } LevelObjectEditor.current.DeselectObject(); string fileName = Path.GetFileNameWithoutExtension(LevelSaveManager.levelSaveFullPath); //Debug.Log("Full Path: " + LevelSaveManager.levelSaveFullPath + ", Filename only: " + fileName); loadSaveUtility.SaveGame(LevelSaveManager.levelSaveFullPath, fileName); LevelSaveManager.RecordSave(LevelSaveManager.levelSaveFullPath); YesNoDialog.current.CancelDialog(); }