Closed AnderX003 closed 3 years ago
So I found the solution of this bug. Eventually I realized that byte[] data = new byte[localData.Length * sizeof(int)]; Buffer.BlockCopy(localData, 0, data, 0, data.Length);
doesn't work right for converting from int[]
to byte[]
and from byte[]
to int[]
. I found those methods on the internet and added them to my game and everything worked perfectly:
private static int[] ConvertByteArrayToIntArray(byte[] inputElements)
{
int[] myFinalIntegerArray = new int[inputElements.Length / 4];
for (int cnt = 0; cnt < inputElements.Length; cnt += 4)
{
myFinalIntegerArray[cnt / 4] = BitConverter.ToInt32(inputElements, cnt);
}
return myFinalIntegerArray;
}
public static byte[] ConvertIntArrayToByteArray(int[] inputElements)
{
byte[] myFinalBytes = new byte[inputElements.Length * 4];
for(int cnt = 0 ; cnt<inputElements.Length; cnt ++)
{
byte[] myBytes = BitConverter.GetBytes(inputElements[cnt]);
Array.Copy(myBytes, 0, myFinalBytes, cnt*4, 4);
}
return myFinalBytes;
}
Hi everyone! I'm implementing Saved Games in my game (achievements and leaderboards work fine already).
Here is my problem: When I save my data to cloud for the first time everything is okay and I can successfully read it from cloud. But if I write data to cloud again and try to read data from cloud I get my old data.
I guess my problem is
ConflictResolutionStrategy
. I don't actually know how these stategys work, but I tried many differend ways and got the same result. Also, I don't know whatDataSource
do, but I triedDataSource.ReadNetworkOnly
andDataSource.ReadCacheOrNetwork
as well, but it didn't help me.My code:
So I got a few questions:
ConflictResolutionStrategy
do i need to use if i just want to write data to cloud and then read last written data?DataSource
is better to use.ReadCacheOrNetwork
orReadNetworkOnly
?SavedGameMetadataUpdate
affect save?