Search code examples
c#unity-game-enginewindows-8.1modern-ui

Saving the progress of a Unity game in isolated storage


I am building a Unity game targetted for Windows Store 8.1 and I need to save game progress in isolated storage. But using 'await' operator in accessing the local storage gives me this error

'await' requires that the type 'Windows.Foundation.IAsyncOperation<Windows.Storage.StorageFile>' have a suitable GetAwaiter method. Are you missing a using directive for 'System'?

Is there a way i can use 'await' operator somehow?

I figured if I implement my Save method in the solution generated after exporting the project to Windows 8.1 it would work fine. Trouble is I am not sure how to access the variables and methods(required in saving the game) of the unity script in the main solution.

Can anyone help with any of these approaches or if there is a better one?

EDIT: Here is the code I am using:

public async void save_game()
{
    StorageFile destiFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("Merged.png", CreationCollisionOption.ReplaceExisting);
    using (IRandomAccessStream stream = await destiFile.OpenAsync(FileAccessMode.ReadWrite))
    {
        //you can manipulate this stream object here
    }
}

Solution

  • Is it necessary to use isolated storage. easiest way to save game in unity is using playerprefs. it works on any platform.

    PlayerPrefs.SetString("Player Name", "Foobar");