You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have problem with saving data on cloud. I don't know if the problem is with sending the date or with receiving it. I only know that i open the functions with saving and loading. Below is the code that i'm using
`
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using GooglePlayGames.BasicApi.Multiplayer;
using GooglePlayGames.OurUtils;
using UnityEngine.SocialPlatforms;
using Com.Google.Android.Gms.Games;
using GooglePlayGames.BasicApi.SavedGame;
using UnityEngine.UI;
using System;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using TMPro;
using System.Text;
public class Saving : MonoBehaviour
{
void Start()
{
Opensave(true);
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
.EnableSavedGames()
.Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.Activate();
Social.localUser.Authenticate((bool success) =>
{
if (!success)
{
SSTools.ShowMessage("Failed to login!", SSTools.Position.bottom, SSTools.Time.twoSecond);
}
else
{
OpenSave(false);
}
});
}
//saving
private int lvl = 1;
private int experiance = 500;
private int win = 300;
private int lose = 200;
private Boolean characterowned = true;
private int money = 100;
private Boolean selectedcharcters = false;
private string GetSaveString()
{
string r = "";
r += lvl.ToString();
r += "|";
r += experiance.ToString();
r += "|";
r += win.ToString();
r += "|";
r += lose.ToString();
r += "|";
r += characterowned.ToString();
r += "|";
r += money.ToString();
r += "|";
r += selectedcharcters.ToString();
return r;
}
private int number;
private void LoadSaveString(string save)
{
string[] data = save.Split('|');
PlayerPrefs.SetInt("lvl", int.Parse(data[0]));
number = int.Parse(data[1]);
lvl = int.Parse(data[0]);
experiance = int.Parse(data[1]);
win = int.Parse(data[2]);
lose = int.Parse(data[3]);
characterowned = Boolean.Parse(data[4]);
money = int.Parse(data[5]);
selectedcharcters = Boolean.Parse(data[6]);
lvl++;
// name_text.text = "LVL: " + lvl.ToString();
SSTools.ShowMessage("wygrane" + win, SSTools.Position.top, SSTools.Time.twoSecond);
}
//cloud saving
private bool isSaving = false;
public void OpenSave(bool saving)
{
Debug.Log("Open Save");
if (Social.localUser.authenticated)
{
isSaving = saving;
((PlayGamesPlatform)Social.Active).SavedGame.OpenWithAutomaticConflictResolution("Simple"
, GooglePlayGames.BasicApi.DataSource.ReadCacheOrNetwork, ConflictResolutionStrategy.UseLongestPlaytime, SaveGameOpened);
}
}
private void SaveGameOpened(SavedGameRequestStatus status, ISavedGameMetadata meta)
{
if (status == SavedGameRequestStatus.Success)
{
if (isSaving)//writting
{
/// Debug.Log("writing");
SSTools.ShowMessage("Data saved:", SSTools.Position.top, SSTools.Time.twoSecond);
// name_text.text = "Dane zapisane ";
byte[] data = System.Text.ASCIIEncoding.ASCII.GetBytes(GetSaveString());
SavedGameMetadataUpdate update = new SavedGameMetadataUpdate.Builder().WithUpdatedDescription("Saved").Build();
((PlayGamesPlatform)Social.Active).SavedGame.CommitUpdate(meta, update, data, saveupdate);
// ((PlayGamesPlatform)Social.Active).SavedGame.ReadBinaryData(meta, SaveRead);
}
else//reading
{
// Debug.Log("saving");
SSTools.ShowMessage("Data read" , SSTools.Position.top, SSTools.Time.twoSecond);
((PlayGamesPlatform)Social.Active).SavedGame.ReadBinaryData(meta, SaveRead);
}
}
}
//load
private void SaveRead(SavedGameRequestStatus status, byte[] data)
{
if (status == SavedGameRequestStatus.Success)
{
string saveData = System.Text.ASCIIEncoding.ASCII.GetString(data);
LoadSaveString(saveData);
}
}
//success save
private void saveupdate(SavedGameRequestStatus status, ISavedGameMetadata meta)
{
Debug.Log(status);
}
}
`
The text was updated successfully, but these errors were encountered:
Hello
I have problem with saving data on cloud. I don't know if the problem is with sending the date or with receiving it. I only know that i open the functions with saving and loading. Below is the code that i'm using
`
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using GooglePlayGames.BasicApi.Multiplayer;
using GooglePlayGames.OurUtils;
using UnityEngine.SocialPlatforms;
using Com.Google.Android.Gms.Games;
using GooglePlayGames.BasicApi.SavedGame;
using UnityEngine.UI;
using System;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using TMPro;
using System.Text;
public class Saving : MonoBehaviour
{
`
The text was updated successfully, but these errors were encountered: