[MUSIC].
>> Well, thank you guys for joining.
We are going to take a look at PlayFab,
one of Microsoft's tools.
You may have already seen some of the segments we've done before,
where we've used PlayFab to handle
the authentication of our games,
to handle the storage and saving of our games,
to handle playing on different devices,
and it can be used for many more things,
including analytics in game purchases.
We are just getting started with this.
Today we're going to be doing
a new application of some of the things we've already looked at.
We have done authentication before,
we have done leaderboards before,
we have done saving before,
and we're going to combine them
in a way they are going to come together
and the idea behind it was to use them in a Twitch game.
You may have come across streams
that have games running in the background.
We are very lucky that we recently
were part of the Twitch Dev Keno,
and we got early access to try out their new API
where we can integrate Twitch with unity projects.
One thing I thought that would be really cool
to integrate PlayFab with,
which is new Unity API,
would be to show people who are in chat
that you can see the other shadows
and imagine that you're there together
and have a digital space.
We started experimenting with that a little bit,
but one thing that we thought would be fun would be
to be able to customize your own representations.
Then we can even do things like
opting in through chat to play a game.
We could have a pool to choose who takes part in the game,
but the first step is to have these customizable avatars
that we can integrate with Twitch to play games with.
We are going to be using some things we've seen before,
like the authentication, leaderboards,
saving through PlayFab.
We're going to go through it's already built,
I'll give a demo, and then I'll walk through how it's set up.
Over here you can see, we have our login screen.
Let's start it up.
This is just a very rough log in.
I'm going to log in with a very secret password.
Close your eyes, don't look, it's very secret.
Once we log in, we now have our character that we can customize.
As you can see, we're just testing out some random hair colors.
This will be saved automatically and then if we ever come back,
our character will be the way we want it to be.
When we go into the game,
we see the other players and the colors that they have picked.
In fact, I actually have my own character here,
"eee' is the username.
It's a very simple version of what it could be.
You could even, for example,
put in the different random dialog
you want your character to show.
That's the very basic demo,
and I'm going to walk you through how we put it together.
First, let's look at our hierarchy here,
we have our controls.
This has a different scripts on it,
so those are all here with their different attributes within them
that we've linked up to the assets
that needs to be linked up to it.
We have our main camera here for our login
and our character selection.
We have our UI, which has the all screen here that you're seeing.
We've linked that up to some controls.
In fact, let's look at the log in screen right now.
Here's our scripts for the login.
Here's our authentication parts.
We have the different text elements,
so we have to be using Unity UI.
We're using PlayFab.ClientModels that on these buttons,
we've linked them up to LogInControl.
Register, which are in the script as well.
We are using RegisterPlayFabUserRequest.
We need to have a failed option here,
which you can use the codes from PlayFab
to give a humanized explanation of what went wrong
when they tried to register.
But for now, we just give ourselves a debug to show the error.
We're just going to use the sign up name
and set that to as display name
so that we can have that to work with later.
Then we go ahead and start the game.
Similarly, when we log in with an existing account,
we use log in with email address request.
You could use different ways to log in.
We've looked at even logging in through Twitch.
That's something we're probably going to do later
so we can connect the users in the game with the users in chat,
but for now we're just doing the representation
visually of the users from PlayFab.
On starting the game, we get the score if there's none.
Though we're actually going to get hair color number,
if it doesn't exist yet.
To give you an idea of what that looks like
when you set up player statistics, let's go over here.
For this, we go GetPlayerStatisticsRequest,
if we get it and that's successful,
and if the results are non-existent,
we have AddStat here.
Down here, where we add the hair color.
Using UpdatePlayerStatistics we add hair color,
we set the value and this is what we used to set the hair color.
I want to show you if we create the statistic,
how it looks in PlayFab.
If you go over, you log in and you click on "Players"
and then we're going to go over to statistics here
and you can see hair color has already been added
and the value is at zero.
This is what we're getting,
we're getting this key and this value,
and that's what we're working with here.
Though once we're logged in,
we said that if we don't have it, we create one.
If it exists,
then we bring that value into the game.
We basically turn off some of these fields
so that we can show the character selection screen.
Here's where we get the hair color by using GetPlayerStatistics.
Then we can update it and show it in the scene,
so as long as the hair isn't known,
which is a game object,
we can set it from the list using
the number of the material on that list.
The game object is not known,
we have actually some materials on this game object.
I brought one in, it's a free asset
from Unity Store that you're seeing
and here I'll show you just in case you're not familiar.
But here's a PlayFab we're using.
This hair color has three different textures on it.
We want to make sure that we are changing the one
that is the actual hair and then we save it.
Now we save it in StatsControls under SetChar
and we say UpdatePlayerStatisticsRequest
and with StatisticsUpdate of the hair color
with the current value that we've just updated to.
So whenever we change it and updates saves.
We don't need to save it again.
That's how we would set those things.
We have one example, but that can be used in all different ways.
Next, when we click "Start Game",
that opens up menus here
that we turn on when we start the game.
This is our fans that have been linked up
to set different values to these
and update the things we just looked at.
If we click "Next" here on our character customizer,
we go into the regular gameplay.
Turn off some of the things we weren't using,
we turn off this game,
we turn on this game object,
which includes our first person controller.
We turn off the camera that we had before,
turn off some of those menus we had up,
bring in the characters of the other players
and then we get them to start dancing.
I wait a minute until they're done being loaded
and then we set the trigger on an animator here
on your change profile.
MakeDance, we basically just say
for each of the children in the parent
that we spawn the game objects too,
we get the animator just based on how the PlayFab set up.
Then we also get that character to face the bonfire.
That's how we do the dancing.
But the other thing we need to look at now
is the" Load Characters",
and that's in "StatsControls".
Here and "StatsControls",
we have "GetLeaderboardRequests",
so maybe limiting the number of players would be a good idea.
We've set it to the number of top 10.
We could have done it by the most recent to have logged in,
we could do it by a number of different ways,
but I thought the leaderboard would be a fun way to do it
so that we could have some value
that people are trying to improve on.
If you are just having a leaderboard,
your characters actually shows up in the game.
From the result, we get the display name,
which we set earlier when we created the account
and the "StatValue" for hair color.
Then we use "ChangeProfile",
that instance, I add a character.
Here we instantiate the PlayFab that we set up top over here.
We also give a random position on the X and Y coordinates
where we spawn them.
Then we set the materials like we did before
for our own character,
for each of those.
That is pretty much all there is to know about this.
That pretty much covers what we're doing,
there's some basic things here
like clear the characters if we want to.
We can set the hair color number using this.
We can have a forward and backwards on
the hairstyles or colors if you want to,
but it's pretty straightforward
and there's a lot that you can do with this.
Hopefully, by watching this, you have been inspired.
Thank you again for watching.
I hope you learned something today.
We'll see you next time.
[MUSIC]