Playmaker Forum

Playmaker Help & Tips => Windows Phone 8 Help => Topic started by: drswoboda on April 05, 2014, 12:53:26 AM

Title: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
Post by: drswoboda on April 05, 2014, 12:53:26 AM
Hello,

This probably isn't a Playmaker issue, but a WP8 issue, but I figured I'd ask the wise souls here first and see what kind of answers I get.

I am using code based on Unity Training video from last month to save some user settings. But it appears that the WP8 Framework is missing some bits. See error and my code.

Does anyone here have a work around for this?

I just got my High Score persistent settings working only to find out it chokes on a WP8 build. It works well on the desktop...

Thanks,
-David

Code: [Select]
Error building Player: Exception: Error: type `System.Runtime.Serialization.Formatters.Binary.BinaryFormatter` doesn't exist in target framework. It is referenced from Assembly-CSharp.dll at System.Void GameControl::Save().

Code: [Select]
// Based on code from...
//
// Live Training 3 Mar 2014 - Data Persistence
// Published on Mar 4, 2014
// Watch this video in context on Unity's learning pages here: https://www.youtube.com/watch?v=J6FfcJpbPXE
//
//Do you want to know how to keep your data between scenes? How about between executions of your game? During this session we will learn how to do both.
//
//
using UnityEngine;
using System.Collections;
using System;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

public class GameControl : MonoBehaviour
{
// Singleton design pattern
//
public static GameControl control;

public float score;
public float highScore;

public GUISkin customScoreSkin;
public GUISkin customHighScoreSkin;

// Before everthing else
void Awake ()
{
if (control == null)
{
DontDestroyOnLoad (gameObject);
control = this;
}
else if(control != this)
{
Destroy(gameObject);
}

// Reload the saved game scores
GameControl.control.Load();
// Zero out the game score
GameControl.control.score = 0;
}
void OnGUI()
{
GUI.skin = customScoreSkin;
GUI.Label(new Rect(350, 0, 200, 50), "SCORE " + score);

GUI.skin = customHighScoreSkin;
GUI.Label(new Rect(350, 40, 150, 30), "High Score: " + highScore);

}

public void Save()
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Create(Application.persistentDataPath + "/playerInfo.dat");

PlayerData data = new PlayerData();
data.score = score;
data.highScore = highScore;

bf.Serialize(file, data);
file.Close();
}

public void Load()
{
if(File.Exists(Application.persistentDataPath + "/playerInfo.dat"))
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/playerInfo.dat", FileMode.Open);
PlayerData data = (PlayerData)bf.Deserialize(file);
file.Close();

score = data.score;
highScore = data.highScore;
}
}

}

[Serializable]
class PlayerData
{
public float score;
public float highScore;
}