Can someone explain what serializing your game state to a byte array means? This is the plugin implementation of Google Play Games for Unity. It’s quite vague on details unfortunately.
using GooglePlayGames;
using UnityEngine.SocialPlatforms;
using GooglePlayGames.BasicApi;
public class MyClass : OnStateLoadedListener {
void SaveState() {
// serialize your game state to a byte array:
byte[] mySaveState = ...;
int slot = 0; // slot number to use
((PlayGamesPlatform) Social.Active).UpdateState(slot,
mySaveState, this);
}
public void OnStateSaved(bool success, int slot) {
// handle success or failure
}
...
I am not familiar with that particular project but it looks like your game state can be whatever data you need to persist converted to a byte array. When you serialize something you are converting an object in code to binary (usually to be stored or sent somewhere). The byte array is just chunks of that same binary in an array.
Something like this would work to achieve that task:
// assuming SaveState is your own implementation for the state and is Serializable
SaveState state = new SaveState();
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, state);
byte[] myByteArray = ms.ToArray();
If you are unfamiliar with serialization I would suggest you watch this live training video.
In Google Play Games your turn -based game (each player) can have one of several states like :active, complete etc… Serialization is a conversion of that state (string?) into an stream of bytes (byte array) to be send to other players in current game. Read the documentation and check another examples in the webpage to see how its done. You are using prime31 plugin right?
Here more description:
https://developers.google.com/games/services/common/concepts/turnbasedMultiplayer#turn-taking
After a few hours of trial and error, I managed to implement cloud saving. Check it out: https://play.google.com/store/apps/details?id=com.pycabit.squabomb
Thank you to both of you guys. I ended up using System.BitConvertor in order to convert the int into a byte.