/// <summary> /// Is has saved game process. /// </summary> public bool IsHasGame() { bool isHasGame = false; if (PlayerPrefs.HasKey(_lastGameKey)) { string lastGameData = PlayerPrefs.GetString(_lastGameKey); UndoData data = JsonUtility.FromJson <UndoData>(lastGameData); if (data != null && data.States.Count > 0) { isHasGame = true; } } return(isHasGame); }
/// <summary> /// Load game if it exist. /// </summary> public void LoadGame() { //if a lastGameKey exists, the Player has played a last game if (PlayerPrefs.HasKey(_lastGameKey)) { //load the lastGame from the Json utility string lastGameData = PlayerPrefs.GetString(_lastGameKey); StatesData = JsonUtility.FromJson <UndoData>(lastGameData); //if StateData contains data, continue if (StatesData.States.Count > 0) { _hintComponent.IsHintWasUsed = false; _cardLogicComponent.IsNeedResetPack = false; IsCountable = StatesData.IsCountable; _availableUndoCounts = StatesData.AvailableUndoCounts; InitCardsNumberArray(); for (int i = 0; i < _cardLogicComponent.AllDeckArray.Length; i++) { Deck deck = _cardLogicComponent.AllDeckArray[i]; DeckRecord deckRecord = StatesData.States[StatesData.States.Count - 1].DecksRecord[i]; deck.CardsArray = new List <Card>(deckRecord.Cards); if (deck.CardsArray.Count > 0) { for (int j = 0; j < deckRecord.CardsRecord.Count; j++) { Card card = deck.CardsArray[j]; CardRecord cardRecord = deckRecord.CardsRecord[j]; card.CardType = cardRecord.CardType; card.CardNumber = cardRecord.CardNumber; card.Number = cardRecord.Number; card.CardStatus = cardRecord.CardStatus; card.CardColor = cardRecord.CardColor; card.IsDraggable = cardRecord.IsDraggable; card.IndexZ = cardRecord.IndexZ; card.isFaceDown = cardRecord.IsFaceDown; card.Deck = cardRecord.Deck; card.transform.localPosition = cardRecord.Position; card.transform.SetSiblingIndex(cardRecord.SiblingIndex); card.isFaceDown = cardRecord.IsFaceDown; //TEMP ---------------------------------------------------------------------------------------------------------- //if(card.isFaceDown == true) //{ // _cardLogicComponent.faceDownCardsCount--; //} //---------------------------------------------------------------------------------------------------------------- } //PERMANENT ------------------------------------------------------------------------------------------------------------ //_cardLogicComponent.faceDownCardsCount = deckRecord.faceDownCardsCount; } //deck.UpdateCardsPosition(false); deck.UpdateCardsPosition(true); } _cardLogicComponent.faceDownCardsCount = 0; for (int i = 0; i < _cardLogicComponent.CardsArray.Length; i++) { Card card = _cardLogicComponent.CardsArray[i]; if (card.isFaceDown == true) { _cardLogicComponent.faceDownCardsCount++; } } StatesData.States.RemoveAt(StatesData.States.Count - 1); _hintComponent.UpdateAvailableForDragCards(); ActivateUndoButton(); } } }