That depends entirely on what you want to save…
I actually intend to write a saveAll() and loadAll() function as part of the next update. At the moment I provide a method to keep track of everything, but I don’t save it myself, no.
So, at the moment, no. If you store all your game’s progress in the crGameKeys class then I can give you a simple method of keeping track of everything but, no way of storing it… yet.
The crGameKeys is a very simple class, to be honest. When you read the notes, you will see I even say so in there also. The very nature of the class dictated that it be just that. In fact, I already made it more complicated than it needs to be, but I thought it best to give people a few more options…
It works on the principle that everything in the world can be translated into a simple question with an answer of either yes or no. Keep in mind that in programming terms, 0 = no and everything else is true. So, do you have any money? Money = 200 = true. Have you received the third quest? Quests = 3 = true. Have you completed the third quest? QuestsDone = 2 = true. Aha! See here comes the catch! So I added a method to test the true and false against a value. (QuestsDone >= 3) = 2 = false.
By using this simple system you can keep track of what you have done and what you have not yet done and also keep track of anything you want to keep track of. If you pick up a rocket launcher, add 1 rocket launcher key and add 20 missile keys. Thus do you have any ammo left? Missiles = 7 = true. Then fire. Missiles = 0 = false. Don’t fire.
An example of it’s use is as such:
var Inventory : crGameKeys;
function Start()
{
Inventory = new crGameKeys();
}
function Pickup(weapon: String, ammo: String, qty: int)
{
if (Inventory.doesNotHave(weapon, 1))
Inventory.add(weapon,1);
Inventory.add(ammo, int);
}
function FireRocketLauncher(ammo: String)
{
if (Inventory.doesNotHave("RocketLauncher", 1))
return;
if (Inventory.doesHave(ammo, 1))
{
Inventory.subtract(ammo,1);
InstantiateRocketAndFire();
}
}
so if you want to store achievements and inventory then yes, after I write the saveAll and loadAll functions then this system can be used to save games also but once again, it all depends on WHAT you want to save. For example, something that this system can NOT store is the player’s position or rotation… These require 3 values and the crGameKeys class only stores a single int value next to every key.
I think this the very reason why a save game option doesn’t come standard with Unity. There is just no way of knowing what people want to save. Let me give you another example.
In one of my games I had 4 sets of 26 pickups and another 4 sets of 8 pickups. Now, I didn’t just need to know IF I had collected a pickup, I needed to know WHICH item I picked up. For me to keep track of every single one of those pickups one by one would be a nightmare. So to keep track of them I assigned each one an int value representing a specific binary value. For those of you who know binary you will understand the significance of calling my items 1,2,4,8,16,32 etc. I then simply AND and OR the pickups into a single int value for every set and I store the result in a GameKey. This way I only ever store 1 value and read back 1 value for each set and I am able to keep track of exactly which of the items in the set I have already collected.
So for me, this system could be used as a save game system, but if you had the same setup and stored your values differently…
It all depends on what you want to store…