コード例 #1
0
    public void SaveGame()
    {
        GameSave ??= new GameSaveData();

        var savableObjects = FindObjectsOfType <MonoBehaviour>().Where(monoObject => monoObject is ISavable).ToList();

        ISavable playerSaveObject = savableObjects.First(monoObject => monoObject is PlayerController) as ISavable;

        GameSave.PlayerSaveData = (PlayerSaveData)playerSaveObject?.SaveData();

        SpawnerSaveDataList spawnerList = new SpawnerSaveDataList();
        var spawnerDataList             = savableObjects.OfType <ZombieSpawner>();

        foreach (ZombieSpawner spawner in spawnerDataList)
        {
            ISavable saveObject = spawner.GetComponent <ISavable>();
            spawnerList.SpawnerData.Add(saveObject?.SaveData() as SpawnerSaveData);
        }

        GameSave.SpawnerSaveDataList = spawnerList;

        string jsonString = JsonUtility.ToJson(GameSave);

        PlayerPrefs.SetString(GameManager.Instance.gameSaveName, jsonString);

        SaveToGameSaveList();
    }
コード例 #2
0
ファイル: SaveSystem.cs プロジェクト: Perry12th/Zombie-Horder
    public void SaveGame()
    {
        GameSave ??= new GameSaveData();

        var savableObjects = FindObjectsOfType <MonoBehaviour>().Where(monoObject => monoObject is ISavable).ToList();

        ISavable playerSaveObject = savableObjects.First(monoObject => monoObject is PlayerController) as ISavable;

        GameSave.playerSaveData = (PlayerSaveData)playerSaveObject.SaveData();

        string jsonString = JsonUtility.ToJson(GameSave);

        PlayerPrefs.SetString(GameManager.Instance.SelectedSaveName, jsonString);

        SaveToGameSaveList();
    }