- Home /
How to save playerprefs data into Google PlayGames (unity) plugin?
Hello,
I successfully configured and using the login and Save Load feature in Google PlayGames plugin with the guide in the github of the plugin.. Then, recently when I'm uninstall, clean data with Cleaner apps and fresh install my game.. I press Load Button and then press Play.. Sadly, there is no data loaded.. My coins in game supposed to be 30 started from zero.. So i'm know that I'm missing something.. Then I tried to edit this CubicPilot GameProgress.cs.. Then I got error.. Hope can guide me.. Thank you in advance..
Information :
Unity 5.2
Google PlayGames plugin 0.9.27 (unity)
My game using own playerprefs and coinsPlayer is the INT name in there..
Error Code here :
IndexOutOfRangeException: Array index is out of range.
CubicPilot.GameLogic.LevelProgress.SetFromString (System.String s) (at Assets/CubicPilot/GameLogic/LevelProgress.cs:96)
CubicPilot.GameLogic.GameProgress.FromString (System.String s) (at Assets/CubicPilot/GameLogic/GameProgress.cs:156)
CubicPilot.GameLogic.GameProgress.LoadFromDisk () (at Assets/CubicPilot/GameLogic/GameProgress.cs:82)
CubicPilot.GameLogic.GameManager..ctor () (at Assets/CubicPilot/GameLogic/GameManager.cs:71)
CubicPilot.GameLogic.GameManager..cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for CubicPilot.GameLogic.GameManager
CubicPilot.Gui.MainMenuEvents.Start () (at Assets/CubicPilot/Gui/MainMenuEvents.cs:50)
Here is the line of error :
mCoins = Convert.ToInt32(p[3]);
Here is the code.. But somehow error..
/*
* Copyright (C) 2014 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace CubicPilot.GameLogic
{
using System;
using UnityEngine;
public class LevelProgress
{
private int mScore, mStars, mCoins;
public int Score
{
get
{
return mScore;
}
set
{
mScore = value;
}
}
public int Stars
{
get
{
return mStars;
}
set
{
mStars = value;
}
}
public int coinsPlayer
{
get
{
return mCoins;
}
set
{
mCoins = value;
}
}
public bool Cleared
{
get
{
return mScore > 0;
}
}
public LevelProgress()
{
mScore = mStars = mCoins = 0;
}
public LevelProgress(int score, int stars, int coinsPlayer)
{
mScore = score;
mStars = stars;
mCoins = coinsPlayer;
}
public override string ToString()
{
return string.Format("LP {0} {1} {2}", Score, Stars, coinsPlayer);
}
public void SetFromString(string s)
{
string[] p = s.Split(new char[] { ' ' });
if (p.Length != 3 || !p[0].Equals("LP"))
{
Debug.LogError("Failed to parse level progress from: " + s);
mStars = mScore = mCoins = 0;
}
mScore = Convert.ToInt32(p[1]);
mStars = Convert.ToInt32(p[2]);
mCoins = Convert.ToInt32(p[3]);
}
public static LevelProgress FromString(string s)
{
LevelProgress lp = new LevelProgress();
lp.SetFromString(s);
return lp;
}
public bool MergeWith(LevelProgress other)
{
bool modified = false;
if (other.mScore > mScore) {
mScore = other.mScore;
modified = true;
}
if (other.mStars > mStars) {
mStars = other.mStars;
modified = true;
}
if (other.mCoins > mCoins) {
mCoins = other.mCoins;
modified = true;
}
return modified;
}
}
}
Your answer
Follow this Question
Related Questions
Google play services saved games highscore error 0 Answers
PlayerPrefs.GetString not saving past values 0 Answers
PlayerPrefs string variables 1 Answer
Save Time Button Settings in Player Prefs 2 Answers
PlayerPrefs Script Problem 1 Answer