0

Windows ストア 8.1 を対象とした Unity ゲームを構築しており、ゲームの進行状況を分離ストレージに保存する必要があります。しかし、ローカルストレージにアクセスする際に「await」演算子を使用すると、このエラーが発生します

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

どういうわけか「await」演算子を使用できる方法はありますか?

プロジェクトを Windows 8.1 にエクスポートした後に生成されたソリューションに Save メソッドを実装すると、正常に動作することがわかりました。問題は、メイン ソリューションの Unity スクリプトの変数とメソッド (ゲームの保存に必要) にアクセスする方法がわからないことです。

これらのアプローチのいずれかを手伝ってくれる人はいますか?

編集:これが私が使用しているコードです:

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
    }
}
4

3 に答える 3

2

分離ストレージを使用する必要がありますか。Unity でゲームを保存する最も簡単な方法は、playerprefs を使用することです。どのプラットフォームでも動作します。

PlayerPrefs.SetString("プレイヤー名", "Foobar");

于 2014-09-03T15:33:29.023 に答える
0

このようなものを使用できます。

// this is for loading
    BinaryFormatter binFormatter = new BinaryFormatter();
                string filename = Application.persistentDataPath + "/savedgame.dat";
                FileStream file = File.Open(filename, FileMode.Open,FileAccess.Read,FileShare.ReadWrite);
                GameData data = (GameData)binFormatter.Deserialize(file) ;
                file.Close();

GameData クラスは [Serializable] です。Deserialize した後、そのメンバーをゲーム内変数にロードできます。

//And this is for saving
BinaryFormatter binFormatter = new BinaryFormatter();
        string filename = Application.persistentDataPath + "/savedgame.dat";
        FileStream file = new FileStream(filename, FileMode.Create,FileAccess.Write,FileShare.ReadWrite);
        GameData data = new GameData();

// ここでは data.health = player.health file.Close(); のようになります。

于 2015-02-17T15:46:19.873 に答える