Home Game Development unity – The place to set off load from PlayerPrefs for knowledge in a static class?

unity – The place to set off load from PlayerPrefs for knowledge in a static class?

0
unity – The place to set off load from PlayerPrefs for knowledge in a static class?

[ad_1]

I’ve this save system that saves screenshots in consecutively-numbered recordsdata. I retailer the variety of the final quantity utilized in PlayerPrefs, in order that the following save continues from there.

However I am unsure the place to name the LoadNumber methodology to load the final used quantity, since it is a static class with no Begin() operate.

utilizing System;
utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing System.IO;
utilizing UnityEngine;

public static class SaveSystem
{
    personal static int countName;

    public static string Load(string FileName)
    {
        string content material = File.ReadAllText(FileName);

        return content material;
    }

    personal static string ScreenShotName(int width, int top)
    {
        return string.Format("{0}/Saved Video games/SaveSlot{1} SavedGameSlot_{2}x{3}_{4}/SavedGameSlot_{1}x{2}_{3}.png",
            Utility.persistentDataPath,
            countName,
            width, top, System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"));
    }

    public static void Save(string saveString, int resWidth, int resHeight)
    {
        string filename = ScreenShotName(resWidth, resHeight);
        string listing = Path.GetDirectoryName(filename);
        Listing.CreateDirectory(listing);
        ScreenCapture.CaptureScreenshot(filename);
        string fileName = Path.Mix(listing, "savegame.txt");
        File.WriteAllText(fileName, saveString);

        countName++;

        SaveNumber();
    }

    public static void SaveNumber()
    {
        PlayerPrefs.SetInt("countName", countName);
    }

    public static void LoadNumber()
    {
        countName = PlayerPrefs.GetInt("countName");
    }
}

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here