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;
try
{
savedGameClient.OpenWithAutomaticConflictResolution(filename, DataSource.ReadCacheOrNetwork,
ConflictResolutionStrategy.UseLongestPlaytime, OnSavedGameOpened);
}
catch(Exception e)
{
debugText.text = e.ToString();
}
}
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
{
debugText.text = "OpenSavedGameFailed";
// 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
{
debugText.text = "SaveGameWrittenFail..";
// 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
{
debugText.text = "SaveGameDataReadFail..";
// 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;
}
소스 조금 수정해왔어.
try
{
savedGameClient.OpenWithAutomaticConflictResolution(filename, DataSource.ReadCacheOrNetwork,
ConflictResolutionStrategy.UseLongestPlaytime, OnSavedGameOpened);
}
catch(Exception e)
{
debugText.text = e.ToString();
}
여기서 문제가 있다네.
이걸로 돌려보니까 debugText.text에
System.NotimplementedE(잘림)
이렇게 떠서 검색해보니까
System.NotimplementedException 인것 같은데
해결방법이 뭐야???
분명히 저장된게임 사용을 눌렀고 알파출시도 했는데
게임서비스에서 출시해야 가능한거야??
게임 내에서 구글플레이게임서비스 로그인은 잘 되던데???
그 에러는 PlayGamesPlatform.InitializeInstance() 안하면 발생할껄. 근데 코드는 문제 없어 보이니 서비스 출시 안해서 그런듯
아 게임서비스 출시 해야되는거야???
알파앱은 올렸는데