전체소스
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using GooglePlayGames.BasicApi.SavedGame;
using UnityEngine.SocialPlatforms;
using UnityEngine;
using UnityEngine.UI;
public class Save : MonoBehaviour
{
public Text debugText;
public Text text1;
public Text text2;
public const string dataName = "Save";
public CloudVariables c;
public bool isSaving = true;
// Use this for initialization
void Start()
{
c = new CloudVariables();
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
// enables saving game progress.
.EnableSavedGames()
.Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.Activate();
//Login();
}
public void Saver()
{
isSaving = true;
OpenSavedGame(dataName);
}
public void Loader()
{
isSaving = false;
OpenSavedGame(dataName);
}
void OpenSavedGame(string filename)
{
if (!Social.localUser.authenticated)
{
debugText.text = "You should login first";
return;
}
debugText.text = "OpenSavedGame..";
ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;
savedGameClient.OpenWithAutomaticConflictResolution(filename, DataSource.ReadCacheOrNetwork,
ConflictResolutionStrategy.UseLongestPlaytime, OnSavedGameOpened);
}
public void OnSavedGameOpened(SavedGameRequestStatus status, ISavedGameMetadata game)
{
if (status == SavedGameRequestStatus.Success)
{
debugText.text = "SavedGameRequesSucces..";
// handle reading or writing of saved game.
if (isSaving)
{
CloudVariables cv = new CloudVariables();
cv.test1 = 50;
cv.test2 = 20;
debugText.text = "CheckisSaving..";
ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;
SavedGameMetadataUpdate.Builder builder = new SavedGameMetadataUpdate.Builder();
SavedGameMetadataUpdate updatedMeta>
debugText.text = "SaveGame..";
//((PlayGamesPlatform)Social.Active).SavedGame.CommitUpdate(game, updatedMetadata, ClassToByteArray(cv), OnSavedGameWritten);
savedGameClient.CommitUpdate(game, updatedMetadata, ClassToByteArray(cv), OnSavedGameWritten);
debugText.text = "CommitUpdateComplete..";
//SaveGame(game, ClassToByteArray(cv));
}
else
LoadGameData(game);
}
else
{
// handle error
}
}
void SaveGame(ISavedGameMetadata game, byte[] savedData)
{
ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;
SavedGameMetadataUpdate.Builder builder = new SavedGameMetadataUpdate.Builder();
SavedGameMetadataUpdate updatedMeta>
savedGameClient.CommitUpdate(game, updatedMetadata, savedData, OnSavedGameWritten);
}
public void OnSavedGameWritten(SavedGameRequestStatus status, ISavedGameMetadata game)
{
if (status == SavedGameRequestStatus.Success)
{
debugText.text = "SaveGameWrittenSuccess..";
// handle reading or writing of saved game.
}
else
{
// handle error
}
}
void LoadGameData(ISavedGameMetadata game)
{
debugText.text = "LoadGameData..";
ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;
savedGameClient.ReadBinaryData(game, OnSavedGameDataRead);
}
public void OnSavedGameDataRead(SavedGameRequestStatus status, byte[] data)
{
if (status == SavedGameRequestStatus.Success)
{
BinaryFormatter bf = new BinaryFormatter();
debugText.text = "SaveGameDataReadSuccess..";
CloudVariables cv = (CloudVariables)bf.Deserialize(new MemoryStream(data));
c = cv;
}
else
{
// handle error
}
}
public byte[] ClassToByteArray(CloudVariables cv)
{
using (var memoryStream = new MemoryStream())
{
BinaryFormatter bf = new BinaryFormatter();
memoryStream.Flush();
memoryStream.Position = 0;
bf.Serialize(memoryStream, cv);
return memoryStream.ToArray();
}
}
}
[System.Serializable]
public class CloudVariables
{
public int test1;
public int test2;
}
문제일것 같은 소스
savedGameClient.OpenWithAutomaticConflictResolution(filename, DataSource.ReadCacheOrNetwork,
ConflictResolutionStrategy.UseLongestPlaytime, OnSavedGameOpened);
여기서 막히는것 같은데 해결방법좀...
참고로 당연히 다른데서 주워온 소스인데 안됨...
구글 드라이브라 해야하나 그냥 구글이라 해야하나 쨋든 저장하는법좀...
코드는 문제 없어보이는데? 구글콘솔>게임서비스>게임세부정보 에서 "저장된게임" On되어있는지 봐봐
debugText.text를 성공한 뒤에서야 "SavedGameRequesSucces.." 로 찍지 말고 함수 들어오자마자 찍어봐 실패했는지 성공했는지
ㄴ 분명 켯는데 그거 출시해야 사용 가능한거야???
알파출시도 안함?OnSavedGameWritten함수 파라미터 전부 디버그 찍어봐 원인이 나올꺼임~
알파 출시는 했는데 그 게임서비스 설정하는데서 출시는 안했는데 일단 ㄱㅅ