Save/Load

Save/Load works with the GameSaveManager.

GameSaveViewList

All you have to do implement abstract class GameSaveViewList according to your game's custom save data.

Example

using UnityEngine.UIElements;
using CupkekGames.Core;

public class GameSaveViewListExample : GameSaveViewList<GameSaveDataExample>
{
  protected override GameSaveManager<GameSaveDataExample> GetSaveManager()
  {
    return (GameSaveManagerExample)GameSaveManagerExample.Instance;
  }

  protected override bool IsInGame()
  {
    // If MainMenu Scene is not loaded, we are not in game 
    // so return false to disable saving
    return !SceneLoader.Instance.IsLoaded("MainMenu");
  }

  protected override VisualElement SlotOne(int index, GameSaveDataExample data)
  {
    // Create custom visual element to show data about your save
    return new Label("Save-" + (index + 1));
  }

  protected override VisualElement SlotTwo(int index, GameSaveDataExample data)
  {
    // Second slot to show data
    return new Label("Gold: " + data.Gold);
  }

  protected override void OnLoadButtonClicked(int saveSlot, GameSaveDataExample slot)
  {
    // Load Save and Start Game
    GameSaveManager.CurrentSave.Data = slot;

    SceneLoader.Instance.LoadScene("Base", SceneTransitionManager.Instance.Transitions.Dictionary["Fade"]);

    GameSaveView.ReturnClicked(); // unloads prefab
  }
}

Last updated