(music)
>> This stream is sponsored by Microsoft Azure.
We're going to be doing a series
where we make a game
using some features from PlayFab.
And these features will allow us to have users sign up,
log into the game,
play it on different devices,
make a high score in the leaderboard,
and save and load data on different platforms.
So it's a really useful tool.
I think it's really, for what you're doing,
it's so easy to use.
I'm going to be explaining how to do
sign up and log in today.
And it can be used for all different types of games.
We're going to be making
a sort of Sims/Tamagotchi style game.
So we have little people
that hatch out of an egg,
like regular humans do obviously,
and they're going to live in a little box
which is going to be either on our phone or on our computer.
You can move them around
and they can interact with things
that you can get for them
and put in their environment
and they can go up to it and react.
They're going to have different little personalities.
It's going to be super cute.
And we've decided to call it Pocket People.
It's looking pretty bare bones right now.
This is Unity, if you guys are not familiar with it.
We have the very basic UI.
We have our signup.
I Haven't even labeled them yet,
but we'll show you how to do the bare basic stuff.
And then we'll make it look nice.
And you guys will be able to try it
and log in and move around the characters.
Not very interesting yet, but it will slowly build it out
flush it out, both with the PlayFab stuff
and the actual gameplay stuff.
Let's start,
uh coding it out.
As you guys can see, let me show you my hierarchy here.
We have a canvas, and on our canvas
we have, we're going to need for this part specifically,
a start panel section which has the signup and login.
There are two different tabs.
So when this is active, it has a sign up information.
When log-in is active, it has the login information.
And then when our start panel is active, we see this.
And when it's not, we see just start game.
So again, it's very, very basic.
I just want to show you guys how to put it together
and then we'll make it look fancy.
Let's make a nice big start game button here.
We're going to say, begin.
So this is what we're starting with, okay?
Now, before we continue, actually
there's another thing I want to share with you
before we start using PlayFab,
We do need to install PlayFab in Unity.
So here's some info on PlayFab.
This is a link to help you get a quick start with it.
And if you go here from this page
you can go to Asti Case Game Engines, Unity 3d.
If you click on Unity 3D here gives you a little overview
and you have some downloads.
There's the quick download and link.
The quick download link
for the Unity editor extensions and the PlayFab STK.
If you get both of these, you'll be set.
Once you have those, you'll also need a PlayFab account.
So you can go to PlayFab.com,
or you can click the link here in chat.
You can sign up, once you're signed up
we're going to log in.
I'm already logged in it looks like,
and it shows you your studios.
I have a bunch of different test ones with different
interesting names on them.
And we made little box of creatures here.
In that you want to get your ID. Okay?
You want to get this ID here.
That's right here
on your dashboard of your developer account.
Once you've created a studio
it automatically creates a game.
And on that game is the ID number.
And you want to connect your game from PlayFab to Unity.
So you can click on PlayFab, make PlayFab shared settings
and you're going to put your ID here.
That's not the right thing.
You're going to copy the ID from your PlayFab dashboard.
And, then you're going to put in your developer secret key
which you can get by going
to, I'm going to tell you and not show you.
This is a very important secret okay?
You can't share secrets,
otherwise it's not a secret anymore.
Go to your game that you're using,
click on title settings.
So that will bring us here.
Then over here, you can see secret keys.
Okay? You can see this link here, secret keys.
Click it when no one's looking,
so it stays a secret.
And as a long key, you're going to copy it.
You're going to hide it from people.
And then you're going to paste it into this thing here
because it's a secret key
I'm not going to show you.
And now it should link up.
There we go.
So that should get you set up, connected to your-
and it should get your Unity Game connected
with your PlayFab account.
Once that's good to go,
we are going to start doing the code.
So over here in; I made just a separate game object
and empty one, and I put the PlayFab control script on it.
Let's open the PlayFab controls here.
If you see me look at another screen
I did write it out and test it before
but I'm going to go through it with you together
as we type it out again.
there's a few things that we're going to cover,
both the Unity stuff and the PlayFab stuff.
So let's go ahead and start
by serializing some game objects,
so that we can see them in the inspector.
And I'm realizing it's kind of tricky to see,
so let's make a dark background for us here.
Game object.
We're going to need our signup tab, sign up tab,
our log in tab,
our start panel
and our HUD,
which is just our start game button.
So this is going to be what we show up
when we've successfully signed up or logged in.
And I think that's all we need for now.
Then we need public text.
And since we're using text, we're going to need to make sure
that we have our namespace for Unity engine dot UI.
And we're going to need our two PlayFab namespaces.
One is using PlayFab
and one is using PlayFab dot client models.
Once these are in, we can continue using PlayFab stuff
and Unity UI stuff.
and our text we're going to need is our username.
We're going to need our user email.
Our user password, our; and then I did a separate one.
So these are our signup fields, and then we're
going to need texts for our log-in fields.
So user email
for a login,
and our user password for login.
Sign up, and error log in.
And now we need one more thing, which is a string
for the encrypted password that we're going to do.
So the third part is going to be the indie part
where we can switch between the signup or login.
And we're just going to be as simple as public.
Void signup tab, and then we're going to do like
public void login tab.
So our sign up tab, we're going to set to true.
Set active.
And for our login tab,
when we click sign up
it will close the login, so login tab set active, false.
And then we're just going to do the opposite here.
So we're going to open the login tab
sign up was false, login was true.
No more errors now.
Okay. We're good.
Now we have all of our items here in the inspector.
So let's put our sign up tab here,
our log in tab here, our start panel,
our HUD, and then we're going to want to text
that we have,
so these are all text fields.
And one thing we can also do is tell it what type
of text field it is.
So, if you click on the text fields game objects,
there is a place that asks, or says content type.
This is username, we're going to say alphanumeric.
And for the email input, we're going to say email address.
For password input, we're going to say password,
and this will make sure that its start out, basically
and we can do this as well, while we're here
for the login also.
Okay. But what we want is the text part of these.
So we put the text in, username input.
We put into username, email input, we put into email.
Password, we put into password, same deal with our login,
text for the email, text for the password.
And then we have two text fields,
one is in our signup tab, that's for any errors
that come up. So error sign up.
And one text here for,
Sorry, it's not a text field, it's just a text game object.
And that's here, login.
Now they're all linked together,
the only thing we've covered so far is switching
between tabs, so I'll show you that.
It's pretty straightforward.
So here I put in, have an account, login.
We can make this look nice, but it gets the idea across.
We have our little login information,
create an account, takes us here, signup,
have an account, takes us back to login.
So far, so good.
The next thing we're going to do is,
we are going to make a encryption function.
So it's going to output a string
and we're going to call it encrypt,
it's going to take a string, I'll call it just pass.
And we're going to use this line here.
Systems security cryptography MD five.
This is an MD five encryption tool.
You can look them up.
They're available to use,
we'll call it X equals new system security cryptography,
MD five crypto service provider.
And then we're going to say bytes BS equals system texts
and coding.
UTF eight get bytes pass is exactly one BS equals x dot
compute hash and system dot text dot string builder.
Yeah, that's what we want right there,
for each bite B in BS,
S dot append B two string X two.
And then we'll return S to string.
Now that we have that done, we can start doing our register.
So we just go public void, signup,
bar, register request,
request equals new register
PlayFab user request, we have here.
And we're going to put email equals our email up here,
user email, equals.
So here we do encrypt, then we put user password
want emails, username, email dot text.
And then we have username equals username dot text PlayFab
client API dot register, PlayFab user register request,
register success, register failure.
And we're going to need to make both of these.
So let's do that now.
Public void register success,
and public void register error.
Let's say register error.
It's that time of day when I lose my voice.
Excuse me, okay, we got it back.
Register, PlayFab, user results.
Okay.
And we're going to make sure any errors go away.
So error, sign up dot text equals no text.
Our start panel holds the log-in information.
So we're going to set it to faulse
since we are now logged in.
Log in dot text
is set to error, generate, error report.
This is for login, we need to sign this to.
Sign up, and we're going to do another one
for login error, and here we'll say error login.
Also, I'm just thinking when we switch between
login and sign up, let's set our errors to be empty
so that we don't still see the login error,
each time we switch, once we switch back
back and forth, and if we are successful
it will clear up any errors that show up.
And our last thing that we need is our login
with it's login success and failure.
So if we log in with success,
we're going to want public void, log in success.
There it is.
And we can do is start game from there.
Just like we do with our signup success, same stuff here.
We'll put in our login success
and then we'll need our PlayFab function here to tell it
to check it basically.
So this one goes like this,
login VAR request
equals new login with
email address request user email login dot text
equals the encrypted password, but it's not user password
user password login this time.
There we go.
Then we want PlayFab, client API dot login
with email address
request comma, login, and then we have the login success.
So we'll copy paste so there's no errors, comma.
Okay. This should be everything we need to get going.
Here we go.
Login button, play pad controls login,
and on our signup button over here, sign up button
play pad controls, sign up.
I think that's everything we need to link.
Let's check our controls looks good.
Let's give it a try.
Okay. To test it.
What we're going to do, here is what it looks like when
you log into PlayFab in your browser.
This is a list of our players so far, this is my users
that I made yesterday.
We're going to sign up here.
Username Lana, email Lana@lana.com
and password is a secret word.
And then we click sign up, and it was successful.
So it switched to begin, and if we click begin
our game starts pocket people
we forgot to turn off the title,
we have our name randomizer,
and it takes us to the next scene
plays the rest of the game as we tell it to.
Now, we can double check that this works by going over here.
Refreshing. If it doesn't show up, you can click search.
It may take a minute, there it is.
There's our second user, right here,
logged in from Canada.
And we have our user number, username,
info is on if you click on it
and now we can login with it.
So we go have an account login, and I type in my email
and the password I set, login.
Now we're logged in, we can begin again
and PlayFab will take care of some of the errors
but your probably going to want to take care of
a chunk of them on your own, for example,
if it's empty and you click sign up,
you know, we have this thing here like
client slash register PlayFab user
also my text box is too small but, as you can see,
it's not very user friendly.
But we can use this information
that we get from the results.
We can put in language for the different types of errors.
But we can also do things like,
if there's nothing entered, we could say,
maybe we'll make a function for
signup check, void, signup check.
And we can do things like, when we click the button
that says, you know sign up,
it should first do something like
is the first field filled out?
Is the next field filled out?
Are the other fields filled out,
we can put in our own language to say
please enter a username, please enter a email,
please enter a password.
So we can fill out the validation,
and we can handle it how we like,
we can make it really nice.
But what we have is a functioning login.
You know, if we put in a username
and this is supposed to be an email address,
and a password, it will give an error
and it will tell you like,
you know, this is not a valid email address.
So we can start checking some of these things
on our own through Unity.
We can also use some of these errors
to inform us of any issues that might come up,
like if the users already exist,
or if the password and thing doesn't match.
That is how you can setup a login and signup for PlayFab.
Again, you can make it as fancy as you like,
you can use it for any type of game,
and it can work on multiple different devices
and that's the things that I think is the coolest
because if we build this for, you know a downloadable game,
execute it well, a browser game,
or if we have it on our mobiles
whether it's an app, or wherever we access it
from different devices, different platforms.
we can still have the same account that we can play in.
And that's like, that's something that's not easy to do.
As you just saw, it took very little time to set it up
and start using, so that's really cool.
So, hope you guys enjoyed that,
I'm really having fun with this project,
I'm having fun with PlayFab,
and I hope it's useful for you guys as well.
Thank you to Microsoft Azure for sponsoring our stream
it's been a lot of fun.