(music)
>> Today, we are looking
at Microsoft Azure's PlayFab.
Last time we looked
at authentication and now we're going to be doing saving
and loading so that you can log into your account.
You can play the game with the same account,
same settings on any computer, on any device.
And we can use that information
to keep it the same across all of them.
So the way we're going to go about
this is I'm going to show you
where we are right now with it.
And then we're going to recap quickly what we did last time.
I'm going to show you how to do the saving and loading.
Then we're going to talk about what things we could do
with the saving and loading, some next steps.
What we could do to start polishing the game more.
And eventually we will have a fully working game
that people can log into and check it out.
First let's look at how it works.
By the way, this is Pocket People.
It's like a little environment where we have either one
or more little characters who can walk around
and do things, interact with objects.
You place on the scene or go
and explore and pick up treasure
and experience along the way while fighting off monsters.
Here's where we are with it so far.
It's very early stages
but you'll see some of the PlayFab stuff in action so far.
For example, we have our sign up page here.
If you have an account, our log
in page requires email or password to login.
And if we sign up with a username, an email and a password
we can click the sign up button.
And here in our first play through
we're presented with a kind of mysterious looking screen.
But once we press the dice,
a character shows up.
You press it again,
and we see that it's randomizing the color.
We're also with this game going to try
if we can to have as little text
as possible so that anyone with any language can play it.
And hopefully we can convey the ideas
with just some iconography and visual indicators.
We'll see, it's an extra little challenge
but we're going to see how it goes.
So right now we can randomize the colors.
Let's say we decide to stick with the blue color.
Then we continue on.
What's going to happen behind the scenes is we
will be saving this information to PlayFab
and it will now set our character
to be a blue little character.
So there it is.
So not much is happening
but our character can walk around the screen.
We can tell it where to go.
And eventually we'll put in some,
it's got some nerve mesh
on it so that it can walk around the walls.
Eventually we'll put in little items that it can pick up
that it can interact with..
Maybe it'll play the drums.
Maybe it'll pick up a sword
and then we'll have some sort
of button or area where it can go on adventure
and that will be automated.
And then we can recall it.
So we've logged in,
we've picked our color
and we see the color here in the game.
Now, if we log in again,
or if we start the game again
we go to our login area
with the same credentials we just put in.
It was like this (keyboard clicking)
put in our password
and here we are, no more pop-up.
Let's see that it's a blue character
and now we can just get right back into the game.
Pretty straightforward, simple to see it.
And actually with PlayFab, simple to implement.
So let's look at it.
Well, we're gonna look at it behind the scenes in a second
or like the code, the breakdown, how it works.
But first I want to catch you up on what we have so far.
Well, in order to have play and loading happening
we need to have it authenticating first.
Otherwise, you know
it doesn't know what accounts to be saving and loading from.
The first thing you do to get PlayFab working in Unity.
We've already covered this last time
you have to install Unity.
Also bring PlayFab into Unity, which we did last time.
And we have a tab for it.
We've logged in with our PlayFab account.
You'll need a PlayFab account.
Here let's bring up the code
so we can see (keyboard clicking).
Just a quick overview of what we did within.
So here we have,
let's make it over here
and let's put a darker background
while I love the transparency.
Let's make sure we can still see it.
So we are using PlayFab
and playfab.clientmodels in our namespaces here.
And then what we do is we have the Unity UI set up
and then we use signup.
Here it is.
So in sign up, we use registered PlayFab user requests.
We put in the email, we put in the password
and we put in the encrypted,
sorry, we put an encrypted password.
And we put in the username on register requests.
If it's success, we do these things.
And if it's an error, then we show the error.
Then for login, we use login with email address request.
We put in the email and password that's encrypted.
And then we just log in
with the email address.
On the requests here,
if it's successful, we do login success.
It looks like we log in.
We do the same thing twice.
We have a bug, good thing we caught it.
It should just be success and then error.
So let's say error, login error
and this should be taking us to that.
Okay, well, there we go.
Fixed a bug
and then we have a bunch of other stuff here.
That's allowing us to switch
between the signup tab and the login tab.
So that's pretty much what we have
for our authentication is it's
with PlayFab not too hard to do.
And when you log into your PlayFab accounts,
I'll take it back a step.
So you can see what it looks like to get to PlayFab.
So I have a bunch of different games here and studio names.
I should just clean it up cause
I've been doing a lot of tests
but we have here Pocket People.
We click on it,
we see an overview of people who've been using it.
This was our last stream
when we were using it, I put it out for a day
and some testing I've been doing,
registering users to test save and load.
And then if we click on players,
if you're using this and you are like
where's my players just click I'm clear or search
and it will show you the people who've logged in,
what countries, their ID,
I guess it shows what they've been spending
and their last login.
So it shows all this information about them.
And then when you click on the last user,
it shows also some of these things here.
And so what we're going to be looking
at today is player data.
And we're going to be using this information here to save
and load information, okay?
So we will be doing this after login.
You do need to be logged in obviously
to get the information from that user.
So we're going to do it once we're in the main scene
after we've already signed up
which on signup we're automatically logged in
or when we log in on our returning signup.
So we have, you know, a scene here
and what I have is this page
with the dice to pick your character, that will show up.
If you are coming in for the first time
if you don't have that information in the user's safe
then that screen will come up
and then it will save it, next time
you will not see it.
But we are also using PlayFab load here.
So here it is where we set the colors, here
is the colors that we apply,
the materials that we apply
to the mesh and some of the screens
that we turn off and on during that little process.
So let's open PlayFab load.
And we begin by looking at,
here is get player data.
So what I'm doing is as soon
as when we start the scene,
we get the player data.
And that way we can run
playfabclientapi.getuserdata, new, get user data requests.
And the keys that we're looking
for is null, user data success and on air.
So on user data success, if we get information
then we can check if we have the key that we need
and decide what to do with that.
So for example, if we log in
and we have no save info
either we don't have results that data at all
or we don't have the key
that we're looking for, which is body color.
If the data's null, or if we don't have that key
then we'll bring up the page
which will allow us to choose one
and then set it for next time.
If we do have that information
then we can take from results.data
at this key, that works like an array .value.
And then that's an integer.
And we can use that
integer to tell which color we should be applying.
And then we have a function to do that.
Now it gives us string from the key, okay?
So the dictionary is a string and a string
but what we can do is put a number in
and the value of that string, we can turn
into an int using in.parse so that we can feed that
into our function, which applies the color.
That is pretty much it for loading.
Let me show you, let's look
at saving and I'll show you what it saves exactly.
So in a kind
of similar way we use, let's open up saving actually.
It's a separate file here.
So we use, once we click the button
then when we select the character's color
then we save that information right away.
So next time when they come in,
we've already got it.
And what we do is we call set body color data.
So we are setting the string number, which is
so if we picked color 1, 2, 3, whatever material we pick
we're converting it to a string
so that we can save it as a string.
And we do set body color
with the string by that color number of string
and we use playfabclientapi.updateuserdata,
update user data requests.
And then we set data to new dictionary string string
which is body and then body color data.
So now we're using this key word,
which we had in our load
and we're setting this here, set data success.
We can just say that it's saved properly
and on error we can display an error.
And the way that that looks in PlayFab, over here
When we click on a player data title
we can see here our dictionaries.
So we have our player data here.
This is our different keys.
We have body color and our value is
at zero for this player right now.
So that correlates
to blue in the game right now.
And we can add as many of these as we like
so we can make full customization of a character
and we can save all different values
of the game for that player in here with the player data.
So that's pretty much all you need to do.
I'm going to show you guys again now that you kind of
have an idea of what's going on while we do it.
So once again, we log in,
we'll type in our username.
(keyboard clicking) lanalux.games,
create a password, sign up.
And as you can see it's, I don't have information
for that user yet, so we can pick the color.
Let's pick yellow.
Now I have a yellow character.
It flied those settings as soon
as we clicked the arrow button.
And when we log in again
with that user information (keyboard clicking)
login, and there's our character again.
So there it is inaction.
I hope that that is something useful for you guys.
I know it's,
I don't think this game would be nearly as cool
if you could only play it with one save on one device.
I think a game like this, especially in idle game
and one that's got like really simple premise is great
for multi-platform and playing across different devices.
So I'm really excited to use PlayFab for this.
And I'm sure you could use this
for so many different ideas, so many different ways.
And that's it.
Thanks guys for joining in and learning about PlayFab today.
I hope it was interesting for you.
I know I'm really enjoying working with it
and we'll see you next time.