Sunday, July 31, 2022
HomeGame Developmentunity - How can I get a created saved recreation file's date...

unity – How can I get a created saved recreation file’s date and time format and add the date time format to slots of saved video games in one other scene?


I’ve two scenes: Recreation and Loading.

Within the Loading scene I’ve variety of slots on this case 10 saved recreation slots and I can change the slots quantity every time.

I wish to make that once I’m saving the sport within the Recreation scene it is going to replace the saved recreation slots within the Loading scene both if variety of slots exist already or to make that once I’m saving the sport it is going to create automated a saved recreation slot within the Loading scene. I wish to have this two choices with already created slots then when saving the sport every time add the date and time to fit 1 slot 2 slot 3….or when saving the sport create a slot and add the date time to the created slot so once more there will likely be slot 1 slot 2 slot 3…

This script I am utilizing the Recreation scene to save lots of the present recreation progress:

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

public class SavingGame : MonoBehaviour
{
    public int resWidth = 1920;
    public int resHeight = 1080;
    public SaveLoad saveLoad;

    public static string ScreenShotName(int width, int peak)
    {
        return string.Format("{0}/Saved Screenshots/SavedGameSlot_{1}x{2}_{3}/SavedGameSlot_{1}x{2}_{3}.png",
            Utility.persistentDataPath,
            width, peak, System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"));
    }

    void Replace()
    {
        if (Enter.GetKeyDown("okay"))
        {
            string filename = ScreenShotName(resWidth, resHeight);
            string listing = Path.GetDirectoryName(filename);
            Listing.CreateDirectory(listing);
            ScreenCapture.CaptureScreenshot(filename);
            StartCoroutine(saveLoad.SaveWithTime(listing,Path.GetFileNameWithoutExtension(filename) + ".savegame.txt"));
        }
    }
}

After urgent the okay key I’ve a screenshot of the sport view window and a saved recreation file for instance :

The picture sort is png.

Saved image screenshot and saved game file on the hard disk

Within the Loading scene I’ve this script that I take advantage of to create the saved video games slots, on this case 10 slots, and I wish to add to this script a bool variable to have the ability to resolve whether or not to create plenty of slots or if the flag bool is fake to create the slots routinely when saving the sport within the Recreation scene:

I typed manually the date and time to indicate the format I would like it to be. Contained in the circle’s picture UI I wish to add the saved png screenshot file.

The variable LevelButtonText is the place the date and time ought to be.

slots

This script within the Loading scene create the saved video games slots:

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
utilizing UnityEngine.UI;


/// <abstract>
/// LevelsScrollViewController - generate scrollview objects
/// deal with all issues these required for scrollview controller
/// </abstract>
public class LevelsScrollViewController : MonoBehaviour
{

    [SerializeField] Textual content levelNumberText;
    [SerializeField] int numberOfLevels;
    [SerializeField] GameObject levelBtnPref;
    [SerializeField] Remodel levelBtnParent;

    non-public void Begin()
    {
        LoadLevelButtons();
    }

    // load stage buttons on recreation begin
    non-public void LoadLevelButtons()
    {
        for (int i = 0; i < numberOfLevels; i++)
        {
            GameObject levelBtnObj = Instantiate(levelBtnPref, levelBtnParent) as GameObject;
            levelBtnObj.GetComponent<LevelButtonItem>().levelIndex = i;
            levelBtnObj.GetComponent<LevelButtonItem>().levelsScrollViewController = this;
        }
    }

    // consumer outlined public technique to deal with one thing when consumer press any stage button
    // at current we're simply altering stage quantity, in future you are able to do something that's required at right here
    public void OnLevelButtonClick(int levelIndex)
    {
        
    }
}

I even have this prefab LevelBtn with the OnLevelButtonClick occasion and the script LevelButtonItem:

LevelBtn prefab

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
utilizing UnityEngine.UI;


/// <abstract>
/// LevelButtonItem - hooked up to stage button
/// deal with particular button associated actions
/// </abstract>
public class LevelButtonItem : MonoBehaviour
{
    [HideInInspector] public int levelIndex;
    [HideInInspector] public LevelsScrollViewController levelsScrollViewController;

    [SerializeField] Textual content levelButtonText;

    Button btnenablestate;

    non-public void Begin()
    {
        levelButtonText.textual content = (levelIndex + 1).ToString();

        btnenablestate = remodel.GetComponent<Button>();

        if (levelButtonText.textual content == "")
        {
            btnenablestate.enabled = false;
        }
    }

    non-public void Replace()
    {
        if (levelButtonText.textual content == "")
        {
            btnenablestate.enabled = false;
        }
    }

    // click on occasion of stage button
    public void OnLevelButtonClick()
    {
       // To load saved recreation right here
    }
}

The issue is how you can use the LevelBtn prefab or different methods to cross the formatted date and time and the png picture to the Loading scene to the best saved slot every time the following saved slot if already created or if that’s the case to create a brand new one every time urgent the okay key when saving the sport?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments