public static bool CreateTemporaryGame(string gameName, int playerId, byte[] worldData) { // The activate game must be unloaded before a new game can be created if (Instance != null) { return(false); } string playerSavesDirectoryPath = Path.Combine(Application.persistentDataPath, playerId.ToString()); GetOrCreateDirectory(playerSavesDirectoryPath); string savesDirectoryPath = Path.Combine(playerSavesDirectoryPath, TemporaryCopyDirectoryName); GetOrCreateDirectory(savesDirectoryPath); string newSaveDirectoryPath = Path.Combine(savesDirectoryPath, gameName); Debug.Log(gameName); // If the new save game directory path exists, delete it as it is only temporary anyways // this will most likely happen with disconnects followed by reconnects OR default game names if (Directory.Exists(newSaveDirectoryPath)) { // Delete the folder and its contents recursively var directoryInfo = new DirectoryInfo(newSaveDirectoryPath); directoryInfo.Delete(true); } // Recreate the folders DirectoryInfo saveDirectory = Directory.CreateDirectory(newSaveDirectoryPath); DirectoryInfo playersDirectory = Directory.CreateDirectory(Path.Combine(newSaveDirectoryPath, PlayersDirectoryName)); DirectoryInfo chunksDirectory = Directory.CreateDirectory(Path.Combine(newSaveDirectoryPath, RegionsDirectoryName)); // Initialise the instance of game save Instance = new GameFile(saveDirectory, playersDirectory, chunksDirectory); Instance.SaveWorldBytes(worldData); return(true); }
public void ExitGame() { // unloaded Instance = null; }