Creating 'Quit' & 'Continue' buttons with Easy Save

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Locked
User avatar
Joel
Moodkie Staff
Posts: 4812
Joined: Wed Nov 07, 2012 10:32 pm

Creating 'Quit' & 'Continue' buttons with Easy Save

Post by Joel »

Creating 'Quit' & 'Continue' buttons with Easy Save

This basic example shows how you can use GUIButtons to allow the user to Save and Load the state of the game. When the user presses 'Quit', it saves whichever variables we need to save. When they press 'Continue', it loads these variables.
public void OnGUI()
{
    // Quit button. When clicked, we'll save our data.
    if (GUI.Button(new Rect(10, 60, 50, 50), "Quit"))
    {
        // Save whatever needs to be kept the same.
        // Must be in the Supported Types list.
        ES2.Save(myInt, "myInt.txt");
        ES2.Save(myString, "myString.txt");
    }
	
    // Continue Button. When clicked, we'll load our data.
    if (GUI.Button(new Rect(10, 10, 50, 50), "Continue"))
    {
        // If there is data to load, load it.
        if(ES2.Exists("myInt.txt"))
        {
            // Load what we saved before, and reassign it
            // to our variables.
            myInt = ES2.Load<int>("myInt.txt");
            myString ES2.Load<string>("myString.txt");
        }
    }
}
General Jewel
Posts: 10
Joined: Tue Jun 16, 2015 4:24 pm

Re: Creating 'Quit' & 'Continue' buttons with Easy Save

Post by General Jewel »

Hi

I want to do something like this in my game where users can press the save button to save a level and load also.

I made a simple level editor in my game where users can instantiate prefab objects that can be dragged around to make simple levels.

These objects are simple and consist of rigidbodies,colliders , mesh object shapes and few scripts attached to them. How would I implement easy save to save the levels? Please be aware pretty new to this. Instructions following importing the package would be nice. Do I need to add ES.Save to each prefab? Thank you.
User avatar
Joel
Moodkie Staff
Posts: 4812
Joined: Wed Nov 07, 2012 10:32 pm

Re: Creating 'Quit' & 'Continue' buttons with Easy Save

Post by Joel »

Hi there,

After importing Easy Save there's not really anything that you need to do with regards to setup, aside from writing the code which calls the Easy Save methods.

The best idea is to check out our Saving, Loading and Instantiating Prefabs example, as this shows the general workflow of doing this, much of which I would just be repeating here :)

There's also a list of types natively supported by Easy Save here, and information on how to add support for your own types here.

In essence, you should only save the information which is going to change if you want to maximise performance. For example, if your mesh isn't being modified at runtime, it's not worth saving it (saving meshes can be very performance heavy).

Another thing worth noting is that if you're loading Components, you should try using the self-assigning Load methods. This basically loads data into an existing Component, rather than creating a brand new Component which you would then need to attach to the object.

All the best,
Joel
Locked