Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Loki18000 · Mar 31 at 07:55 PM · savingapicloud

Play Services Cloud saving help.

Hello,

It doesn't look like there much recent help on this. I've started looking into Google Play Services. I've got to the point where I can have the user/player login to their Google play account, deal with achievements and so on without any issue now.

I am really struggling with the cloud saving. I have gotten it to work but it doesn't seem like it's the best way.

 private bool isSaving = false;
     private string SAVE_NAME = "mainSaveFile";
     public Text debugText;
     [SerializeField] InputField dataToCloud;
 
     public void openSaveToCloud(bool saving)
     {
         if (Social.localUser.authenticated)
         {
             isSaving = saving;
             ((PlayGamesPlatform)Social.Active).SavedGame.OpenWithAutomaticConflictResolution(SAVE_NAME, GooglePlayGames.BasicApi.DataSource.ReadCacheOrNetwork, ConflictResolutionStrategy.UseLongestPlaytime, savedgameopen);
         }
     }
 
     private void savedgameopen(SavedGameRequestStatus status, ISavedGameMetadata meta)
     {
         if (status == SavedGameRequestStatus.Success)
         {
             if (isSaving)
             {
                 byte[] data = System.Text.ASCIIEncoding.ASCII.GetBytes(GetDataToStoreInCloud());
                 SavedGameMetadataUpdate update = new SavedGameMetadataUpdate.Builder().Build();
                 ((PlayGamesPlatform)Social.Active).SavedGame.CommitUpdate(meta, update, data, saveUpdate);
             }
             else
             {
                 ((PlayGamesPlatform)Social.Active).SavedGame.ReadBinaryData(meta, ReadDataFromCloud);
             }
         }
     }
 
     private void ReadDataFromCloud(SavedGameRequestStatus status, byte[] data)
     {
         if (status == SavedGameRequestStatus.Success)
         {
             string saveData = System.Text.ASCIIEncoding.ASCII.GetString(data);
             LoadDataFromCloudToGame(saveData);
         }
     }
 
     private void LoadDataFromCloudToGame(string saveData)
     {
         string[] data = saveData.Split('|');
         GetComponent<InterstitialAdExample>().ads = data[0];
     }
 
     private void saveUpdate(SavedGameRequestStatus status, ISavedGameMetadata meta)
     {
         //Debug
         debugText.text = "Successfully added data to cloud";
     }
 
     private string GetDataToStoreInCloud()
     {
         string Data = "";
         Data += "string To Save";
         Data += "|";
         return Data;
     }

It does work but it feels like it would become very messy after awhile when having to save hitpoints, NPC's positions, NPC's hitpoints, and so on.

So I think the following would start to look like

     private string GetDataToStoreInCloud()
     {
         string Data = "";
         Data += "string To Save";
         Data += "|";
         Data += "another thing to save";
         Data += "|";
         Data += "another";
         Data += "|";
         return Data;
     } 

and so on.

I would use

     string[] data = saveData.Split('|');
     dataNeeded = Data[0];

to then get the data needed.

Is this nonsense?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

135 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is the Cloud Build API key machine specific? 0 Answers

What API does Unity use to start UnityCrashHandler.exe 0 Answers

One save for a free and premium version of the game on iOS 0 Answers

YAML support? 3 Answers

Can you save a user's in-game currency using google play cloud save? Is it a good idea to do so? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges