Exemple #1
0
    private void SaveGame(string saveName)
    {
        if (!SaveUtilities.IsValidName(saveName))
        {
            Debug.Log($"Error saving {saveName}");
            return;
        }
        var savePath = Path.Combine(SaveUtilities.GetSaveFolderPath(), saveName + Path.DirectorySeparatorChar);

        Directory.CreateDirectory(savePath);
        var mapPath  = Path.Combine(savePath, SaveUtilities.MapFileName);
        var statPath = Path.Combine(savePath, SaveUtilities.StatFileName);

        SaveTextureToFile(ClassManager.MainScript.mainTexture, mapPath);
        File.WriteAllText(statPath, JsonUtility.ToJson(ClassManager.InventoryScript.GetSaveState(), true));

        Debug.Log($"Game {saveName} saved!");
    }
Exemple #2
0
    public void Populate()
    {
        SaveUtilities.EnsureSaveFolderPath();
        var potentialSaves = Directory.GetDirectories(SaveUtilities.GetSaveFolderPath());
        var saves          = potentialSaves.Where(s => SaveUtilities.IsValidSave(s)).ToList();

        Debug.Log($"Got {saves.Count} saves.");
        foreach (Transform child in ContentPanel.transform)
        {
            Destroy(child.gameObject);
        }
        for (int saveIndex = 0; saveIndex < saves.Count; saveIndex++)
        {
            string s     = saves[saveIndex];
            var    panel = Instantiate(SavePanelAsset, ContentPanel.transform);
            panel.GetComponent <SaveItemPanelScript>().Init(new DirectoryInfo(s).Name, s);
            panel.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, -70 * saveIndex);
            panel.GetComponent <Button>().onClick.AddListener(() => { SetSaveGameNameFromButton(panel.GetComponent <SaveItemPanelScript>()); });
        }
    }