[MUSIC].
>> So everybody, welcome.
Today, we're looking at Microsoft PlayFab's sign-in.
Last time we did the registration in Unity,
today we are going to be doing the sign-in, also in Unity.
We'll be starting where we left off
last time and the one before that was setting up.
So if you guys are wanting to give this a go.
The first steps would be to install the PlayFab SDK,
an extension for Unity.
Here's the website for it,
if you guys want to give it a try.
It is free, which is pretty sweet.
There's higher tiers that you can pay for,
but I think for a lot of your needs,
especially getting started and trying it out,
there's a lot available at the free tier.
So to give you guys a refresh of where we left off,
we have the sign up and log in
form/we only have the sign up right now as you can see.
You type in your username,
snowflakemaster,
because the snowflakes I made earlier were really amazing.
The e-mail is snowflake@master.com and our password,
well, that's a secret.
Sign up, in our Console it says, "User added".
But more importantly, over here are my list of users.
When I refresh, there'll be a new one.
I did a couple of tests earlier today and voila,
3:14 we had new registration.
What we're going to be doing today is when we click on "Log In",
this will change instead of
saying "Sign Up", it will say "Log In".
We'll login with our, I think I want the e-mail,
that'll be the first step is to get a confirmation,
and then the second thing I'd like to do is
actually build it out so it feels real.
So when you sign up, it has a screen that's like,
"You've signed up successfully."
When you log in, it gets rid of this and change it.
So let's get started.
First, let's create a second,
maybe I can copy and paste this login, this part.
This is the whole thing,
this "Sign Up" button.
I should say, "Sign Up" tab and a "Log In" tab.
I decided not to put e-mail verification
and after much pushback from chat,
I prefer you got to spell your e-mail
correctly or you got to sign up again, it's that simple.
What's the best sign up experience you guys have had?
I signed up for something recently and
all they asked me was my e-mail.
It's pretty impressive. Type in your e-mail and done, signed up.
Under my e-mail, I could go in through that.
That sign up was e-mail verification.
Why do you guys want to type your e-mail so many times?
It's annoying to type an e-mail,
it's a lot of parts to it.
Oh, connect through an account?
That's actually something we could do in the future,
is log in through other things.
I have to double-check about what other ones are available.
Never had a good sign in experience.
Twitch does it pretty good. Log index me code.
Here's our Sign Up Fields,
as I need both, it'd be our Log In Fields,
and I'm going to take these three things
and put them into, wait I need user,
four things, Sign Up Fields and then I'm going to
take all of them except for duplicate,
and put them into the Log In Field.
Sign Up is off,
Log In is only these two,
and let's change this text to Log In.
I'm going to actually put this Log In [inaudible].
I'm going to fake it actually,
so this is going to be Log In.
Instead of changing them, I'm going to just make new ones.
So log in will be the white,
text will be charcoal,
and this one will now be gray.
That will be white text and that's too gray, very nice.
I can remove the button on
this because we're already on this page.
In the sign up,
well do it so that our sign up doesn't have a button.
Now, in our code. Here's what we had before.
We are using PlayFab,
PlayFab Client models, Unity UI.
We have our username, our e-mail,
our password, we have our encrypted password string,
which we go through this crypted function here,
puts out that string,
which we use here in
our register requests, which is RegisterPlayFabUserRequest.
On success, we do RegisterPlayFabUserResults
and on failure we do PlayFabError.
I don't like only using on, let's just stick to regular, that.
First, we need to get to the correct place.
So let's put our buttons here.
Public void Sign Up Tab
and let's do one for our Sign Up and Log In tab.
So we put our buttons here and we can
link them up even right now actually.
From sign up, we want the log in to have a button at this,
and in our controls we can put, I should name this better.
I did. Log In tab, not showing up.
What's happened? I was editing the wrong file it seems? No, no.
It's right here. Sign Up tab,
Log In Tab, they're public.
Maybe it wasn't updating. Let's try again.
Controls, Log In Tab. There it is.
I just took a second to update and then in
our Log In Fields we want to know our Sign Up Tab.
Sign Up Tab, there we go.
Register. Well, now we need to switch these.
So let's get our GameObjects
that we wanted to be turning off and on,
and we'll want our Sign Up Tab and our Log In Tab.
Then what we can just do is as simple as activate
this one and LogInTab.SetActive,
false, and the opposite for the other one.
Now, let's put these in the right place.
Here's our Sign Up fields and our Log In fields,
and let's add the right things to
the buttons. We did that part already.
So now it should actually
show up when we want it to, let's try that.
Good. Now, our next step is to make
this part work and we went public on this,
so we won't be able to access it from the button.
Void Login, and here we want to have
var request equals new login with e-mail address request,
then we set our e-mail equal to the same thing we have before,
which is here we got it from
our text up there, it needs to be a string.
So we just put dot text after.
Our password needs to be encrypted,
so we're going to use this,
which puts our entered password through an encryption.
We don't need a username which we have on the sign
up because we're logging in with just our e-mail this time.
Then we put
PlayFabClientAPI.LoginwithEmailAddressRequest,
login success and login failure.
I spelled success wrong,
let's get that right away.
Now we need to make those,
so public LogInSuccess takes LogInResults.
Is there's some problem?
Let's keep going. I forgot the void after.
Public void this time,
LogInFailure and this one we'll put in PlayFabError,
and say debug.LogError, error.GeneratesErrorReport.
Okay, looks good. Now, let's add
the log in to our button here that says Log In.
I'm also realizing we're
going to be getting the text from over here.
So we're going to need to put it in from the other tab.
So let's go username, we don't need username actually,
we need userEmailLogin and userPasswordLogin.
So now we get our e-mail,
we'll do it from the Login Input fields and we're going
to get our password from the Login Input field. Okay, cool.
Then we'll just need to add those over here.
I think if we assign it to the button. Did we do that yet?
Let's see. Login button,
but we need to switch this over to login.
So let's try that.
First, let's make it user.
Actually, we made that user. Well, let's make a new one.
Let's say, and then we'll put in a password, user added.
Again, in our PlayFab login over here,
we have a new user-created and now let's restart just so
that we can see it from empty here. Go over here.
We'll say test user. Test user and something went wrong.
I did it wrong. E-mail address is not valid.
I did the wrong e-mail address.
Test user, signed in.
Okay, cool. So it works,
but it doesn't look very exciting.
So I would like to put in an actual gameplay,
once we're logged in.
Let's make a new scene, make it simple.
Let's bring in our Character Controller too,
so we can feel we're walking around the grit in the game.
Unity assets, standard assets,
that's the one, "Import".
While that is importing,
over here in leaderboards,
I'm very curious to get this working in the future.
Leaderboards are essentially rankings of
entities such as players, groups, or items.
A leaderboard ranks a list of
entities based on their respective values,
such as high scores, view quickstart.
Tournaments and leaderboards quickstart,
this quickstart describes how to
have a statistic that keeps track.
There it is. Where were we?
This can be utilized for a global
leaderboard or in conjunction with
resettable statistics to reset for a specific event or tournament.
So there, we logged in.
It's a good thing we're learning how to put that in.
Create a statistic and associated leaderboard.
Go to leaderboards menu on the left,
select leaderboard, Add a leaderboard.
So we have a bunch of stuff to fill out here.
It looks they even give us some code that we can use.
Cool. I like to try this one out next.
Let's set it up in PlayFab, like what
happens if we go New Leaderboard.
Statistics name, high scores.
Reset, interesting.
Manually. We don't want to reset it.
Let's have the highest value at the top.
Now we have it ready to use in the future.
I wonder if we can find out more about that player.
Test user, PlayFab login e-mail,
"Unlock", send password reset e-mail.
That'll be cool if we figure it out as well.
Language, we can set a language?
We can set an avatar image URL.
Display name, cool.
I want to be able to settle this on the game.
There's some error with that.
Let's restart Unity just to make sure it's fresh.
I'm not seeing any errors, that's good.
Let's make a new scene. Let's call it Main.
Let's open it, remove the camera,
let's add a plane.
This is what I do whenever I set up a new scene.
I want to just test walking around or whatever.
Make a plane in the middle,
I "Import" the Standard Asset Pack.
I put in First Person PlayFab rigid.
No, I take the FPS Controller,
make sure they're in the middle, but not going through the floor.
Looks good, they might fall a bit.
Let's bring them down. There we go.
So first, let's just double check we can walk around here.
Let's put in a cube here and another one here. There we go.
So what we want to do is,
once we're signed in, we want to go straight to gameplay.
So let's go back to our sign-in scene.
Before we do that, save it and add it to the "Build Settings".
Sample scene, which one was I building it in?
Let's say UI and as it came out,
we'll say SignUpLogInForm. There we go.
So now let's take signed in and instead let's add
using Unity.SceneManagement and we
can say when this happens, SceneManager.Load.
I've been using Async, I can't remember.
It's just load scene I think.
Load scene, main. It should work,
why is there this?
Using Unity Engine, my bad.
Unity Engine scene management, then we can do it.
So let's try that out.
So let's login with our and a password and now we play the game.
There it is folks.
Now we have sign-in, we have registration,
and so we can now sign-in,
register, and play the game.
That's pretty cool. I'm excited
about this. That was not bad at all.
Just a little bit of code, not much though.
You guys have any questions on this, please let me know.
Why do you need to sign-in?
The sign-in can be used for a number of different reasons.
To me, the best thing is to prevent piracy.
So you can have logins rather than just
giving your copies of the game. So that's really cool.
Also if you want to have multiplayer
or leaderboard or anything like that,
you can now do so using a login.
Also if you want to have multiple devices,
you want to play a multiple different accounts or
devices, you can do that.
So maybe I'll play here,
I login, and play the game.
But then maybe I'm at
a friend's house and I want to use their computer,
I can just login instead of having to have
the game save file from my own computer.
Any other questions guys?
Let's go back to our regular stuff.
Some of them are little bit over-complicated,
the tutorials like that.