(music)
>> So, if you guys are joining us,
this segment will be sponsored by Microsoft Azure
and we're going to be learning
about PlayFab for the next little bit.
Today, we're going to be going over
some of the details that we can add
to make our save and load,
sign up and log in systems a little bit cleaner
and some tools that will likely be useful
if you're going to be using PlayFab in your Unity game.
First of all, let's do a little demo
of where we are with the game right now.
So our game is called Pocket People.
You have little creatures, little humanoid
which they have their own little personalities.
They can go on adventures.
You can give them items that they can interact with.
Right now, we have the very bare basics
and so far and we're slowly gonna be working
towards all of those different features.
Using PlayFab to make this game better
in a lot of ways,
and it's helping us to do some cool things.
For example, we're able to log in, sign up,
create an account and log in with that account.
And that's useful because it means
that we can play the same game
on different devices or even different computers
and some of the other features PlayFab can help us with
are saving and loading,
as we just mentioned with logging in,
but also it stores that information for us.
But there are other features like analytics that are useful.
There are features like in-app purchases that are useful.
We can do A/B testing.
We can do leaderboards.
So its a lot of cool features that we're going to use
to make this game so much more than it would be
without these features.
So we're gonna look at how to do that today.
We've already gone our sign up form here.
We can switch over to put in our information
if we have an account.
If we sign up, we enter a username,
let's say something like this,
oh, so that's our username,
our email might be something like this,
we have to use (inaudible)
and now once we log in, we see this dice,
what does the dice do?
Oh, what do you know?
It changes the color of our creature.
Not very visually pleasing yet,
but this is a very rough,
almost like a wireframe of what the game will be.
We're just getting started with some of the user experience
and making the game smooth and understandable.
Once we've done that, we have our home for our characters.
We start with this will be our characters profile picture.
The idea would be that you can add items to the scene,
it can interact with that item.
Maybe it's a type of food
and if that character likes that type of food,
it will eat it.
If it doesn't like the type of food, it will look at it,
maybe shake its head and then go do something else.
So it will have a little bit of a sense of a personality.
We can lead our Pocket People to water,
but we can't make them drink.
We can also lead our Pocket People
to go explore outside their home
and it will encounter enemies, which it will battle,
and its health will be removed when it gets attacked.
When it defeats an enemy we receive some money
and that's what we use to buy the different food,
equipment, weapons, characters have little items
that they can't use and interact with.
We can also go look at our other characters here at home,
while that one's adventuring
and it will continue to go where we left off.
It loads in from the beginning, but it does continue on.
So it's one of these types of games
where you sort of interact a little bit
leave it to do some things,
then when you return there's new gameplay that's available,
like buy new items or upgrading
or whatever things you wanna do.
First session, we looked at how to sign up and log in,
how to set that up
and then we did how to save and load information.
So the first thing we're gonna look at is
how we're doing the (inaudible)
So to give you an idea of how this works,
if we leave the game and we come back in,
and we sign in lana@lanalux
we can see our character still out adventuring
even though we left the game.
How we did that, let's take a look at our code.
We want to look at our save controls.
So let's open, PlayFab save using system,
this is a namespace we need
for use Unity to use datetime.
We set it to the current time that they go on the adventure
and we're saving the key,
which we are setting to the datetime as a string.
And then in PlayFab client API,
PlayFab client API update user data.
It will update it.
Let me show you what that looks like in PlayFab,
when we're logged into the website.
We can see that the character that I just clicked on,
does not yet have the adventuring or it was deleted.
But if we logged in,
and when we would see the datetime here.
Here it is fighting the enemies.
And so when we return we can compare to this and we do that.
We use get player data at the beginning of the scene.
Then when new get user data requests, keys is now.
So we can debug it and say, save current, now,
loading it in.
So we check if as long as the data is not known
and the data contains the body color
then we can now set the color of the character here.
Now, another thing that we're doing here,
when we load the info
but basically what is checking is if it has this key
we need to set our character to be currently
on an adventure.
So when we log in
we know is out at venturing is not home where it is usually.
And we plug this into set adventuring.
And over here in our set adventuring,
we take the character number
'cause there might be more than one.
That's the one that we're going to show
with a sword over it here.
So if we have more than one,
we can check this against all of them.
We get that number.
And then the datetime string
I think this is very likely to be useful
if you're using a game that has a login feature.
So now that we have this as a datetime,
first we get the time span difference.
We wanna know how long the character
has been adventuring for.
So that if, if our adventure is one minute,
we know that they're done
and we can put them back home again.
They've completed the adventure.
They're back home.
Now, there was something in here
that I wanted to point out as well.
When we start,
we check if the key is null or not.
If it contains the key.
If we're done adventuring we can remove that key
and then not, no need to calculate anything.
We wanna remove one of these keys.
We can log in
and we can actually delete adventure time here.
And you can say play, save player data.
So we can, in fact from PlayFab we can log in
and delete keys, but we can also do with code.
There are two more things I wanna cover.
They are both with the login.
Last time we logged, we open the game right there.
We automatically logged in,
even though we started on the login screen.
The simplest way to save our data with Unity.
And we're using that with PlayFab to do an auto log-in.
I added a method called load if available,
and to do that, we take that string.
We use PlayerPrefs.SetString
and then we can just hit PlayerPrefs.Save
So we don't have to log in every time
we can just go immediately right into gameplay,
which is one thing that we have not done yet
but we will be adding to this game as a way to log out,
in case we want to have a different account
or sign up with a new account or anything like that.
And all we would have to do is
delete our player preferences.
So we'll add a button in our main screen
and we'll put a little button here that's a log out button
and that will the delete our player preferences,
so it does not, no longer stores that information.
And the last thing that we were gonna cover,
the error codes from before were showing up like this.
If you're logging in, you see this,
it's not the best user experience.
You can get the idea that invalid input parameters,
but we can clean that up to be much more friendly.
This is what we had before, what we can do here.
We can now do a switch where we get the (inaudible) error
and then we can write
in whatever we want to let the user know what's happening.
So let's type in username like that.
Okay. So here's one of the things that we caught,
one of the error codes that we have here in our switch.
And then as our default, if we missed anything
we can now get the full error reports
and that's how we handle validation.
So that covers all of the more detailed elements
of signing up, logging in, saving and loading with PlayFab.
I hope that was helpful all for you guys.
Thank you so much for tuning in for this.
I know I'm excited for Pocket People
to be its full, reach its full vision.