コード例 #1
0
    public static void SetPath()
    {
        saveFileName = Script_Utils.SaveFile(saveSlotId);
        savedGameTitleDataFileName = Script_Utils.SaveTitleDataFile(saveSlotId);

        path = Application.persistentDataPath;

        saveFilePath           = $"{path}/{saveFileName}";
        savedGameTitleDataPath = $"{path}/{savedGameTitleDataFileName}";

        Debug.Log($"Persistent path is: {Application.persistentDataPath}");
        Debug.Log($"Currently using path: {path}");
    }
コード例 #2
0
    public static bool Copy(int fromSlot, int newSlotId)
    {
        SetPath();

        try
        {
            // copy saveData
            var fromFileName          = Script_Utils.SaveFile(fromSlot);
            var fromTitleDataFileName = Script_Utils.SaveTitleDataFile(fromSlot);

            var newFileName          = Script_Utils.SaveFile(newSlotId);
            var newTitleDataFileName = Script_Utils.SaveTitleDataFile(newSlotId);

            var fromFilePath          = $"{path}/{fromFileName}";
            var fromTitleDataFilePath = $"{path}/{fromTitleDataFileName}";

            var newFilePath          = $"{path}/{newFileName}";
            var newTitleDataFilePath = $"{path}/{newTitleDataFileName}";

            Debug.Log($"From File Path: {fromFilePath}");
            Debug.Log($"To File Path: {newFilePath}");

            Debug.Log($"From Title Data File Path: {fromTitleDataFilePath}");
            Debug.Log($"To Title Data File Path: {newTitleDataFilePath}");

            if (File.Exists(fromFilePath))
            {
                File.Copy(fromFilePath, newFilePath, true);
            }

            // copy titleData
            if (File.Exists(fromTitleDataFilePath))
            {
                File.Copy(fromTitleDataFilePath, newTitleDataFilePath, true);
            }

            return(true);
        }
        catch (System.Exception e)
        {
            Debug.LogError("Failed Copy with exception: " + e.ToString());
            return(false);
        }
    }
コード例 #3
0
    public Model_SavedGameTitleData Load(int saveSlotId)
    {
        string path     = Script_SaveGameControl.path;
        string fileName = Script_Utils.SaveTitleDataFile(saveSlotId);
        string filePath = $"{path}/{fileName}";

        try
        {
            if (File.Exists(filePath))
            {
                BinaryFormatter          bf   = new BinaryFormatter();
                FileStream               file = File.Open(filePath, FileMode.Open);
                Model_SavedGameTitleData data = (Model_SavedGameTitleData)bf.Deserialize(file);
                file.Close();

                if (Debug.isDebugBuild)
                {
                    Debug.Log("Successful title load at: " + filePath);
                }
                return(data);
            }
            else
            {
                if (Debug.isDebugBuild)
                {
                    Debug.Log("Did not load; file not found.");
                }
                return(null);
            }
        }
        catch (System.Exception e)
        {
            Debug.LogError("Failed Load with exception: " + e.ToString());
            return(null);
        }
    }