Video: Using FACEBOOK INSTANT SDK with UNITY TINY | # 10
Unity tiny is great for Facebook instant But how do you add the Facebook instant SDK to your project? Well today I'm going to show you Hello and welcome back to another Unity tiny video where I'll be showing you how to use the Facebook instant SDK with your unity tiny Project then we'll import a typescript library to prevent editor errors during development while using the Facebook SDK So the first thing that we're going to want to do is add in a post processing script we can get this post processing script from the unity tiny forms by this user if We go to the forum we can scroll down a little bit and we'll find the Updated version of the post processing script and we can just copy and paste it into our project Going back into our unity tiny project in the root of our assets folder We'll create a new C sharp script called FB instant post processing We can open that file up and then we'll just copy and paste the code that we copied a minute ago You can see that this file is checking to see if our unity tiny is in release mode and If it is will copy the Facebook app JSON and add the Facebook library to the HTML After doing that let's add in a TS config override that's going to add a Facebook DTS library to our unity tiny projects so we don't get errors while accessing the SDK within our editor.
So if we go back to the unity tiny forms on Here, there'll be a github link, which you can click on to download the library that we need Once at the github we can copy and paste all of this Go into visual studio code we'll create a new file paste this Paste the code within that file now We need to save it and the place that we're going to save it If you go back into your unity tiny project click on assets, right click it and say show and explore Inside of here. We need to create a new folder called external Inside of this folder we'll create another new folder called DST and then this is where we'll save our library, so go to file save as Navigate to the folder that you just created so external DST and what we're gonna name? It is capital F be AI NS ta NT dot d dot TS Make sure your save type is all files and it's FB instant dot d TS click Save Navigate back to the folder make sure it's saved as a TS file Go back into your unity project We now need to add in 80s config override that's going to add our typescript file that we just created Into our unity tiny project to do that we'll go into the root of our unity tiny project the Platformer folder for my project and we're going to save a new JSON file into this folder So let's go into visual studios.
We'll say file new File go to web and click on JSON Open the JSON file up and we can navigate back to the unity Tiny forums to get the code that we need to paste the code is posted by revolter We can just copy and paste this into our new JSON file remove the include so after the comma and this comma so it we only need the files that adds the external file we're going to save this as And What we're going to name it and where we're going to put it is assets Platformer which is the name of my project and what we're going to name is TS config dot override Dot JSON Save your file Go back into your unity project and confirm that the file is now added in now that we have our TS config override file Added in we can confirm that it's working by getting our game to compile After a compiled let's read navigate to the explorer location of our assets folder We can open up this TS config Json file and you'll notice that it included the external DST FB instant DTS file within here Good so we know that that worked now that we have access to the Facebook instant library within our Typescript file will be able to say things like FB instant dot player dot git ID and various other things But this will throw an error until our game is actually hosted on the Facebook website There is a few more things.
We still need to do before doing that though we can navigate back to the unity tiny forums and we need to get a file called Facebook instant service if You scroll to where This same user who's posted most of our useful scripts that were using You'll find his Facebook instant service class. We can just copy and Poppy this go back into our unity editor Go into our scripts folder and we'll create a new typescript System and we'll call it FB instant service Go ahead and open that file up Paste the code that you copied from the unity tiny forms Go back into your unity project and make sure it compiles with no errors Now we can go into our game manager service and we'll initialize Facebook instant The way we're going to do it is if you go to the unity tiny forms He shows us exactly how its Facebook instant service dot get instant dot initialize dot then and then within here we can post what we want the game to do After initializing Facebook so we can just copy this Paste a here then right here. We'll close it off So after Facebook instant is initialized our game service will initialize We can say console dot log Attempting to initialize FB instant and then here we can say Initializing game Go back into your unity project and let that compile now The last thing we need to do is add an FB app – config file to the root of our assets folder So let's go back into visual studios will create a new JSON file and Inside of here if we go to the unity tiny forms and scroll down to the post that I posted We can just copy and paste this into our file ignoring the last bracket Will save this To the root of our assets folder inside of our unity tiny project Adjacent to the FB instant post-processing script that we created earlier and this file will be called FB app – Config dot JSON Go ahead and save that file go into your unity project You'll see that it gets added in now confirm that your build configuration is set to release and it is not on debug or development your on release and Then for my project this may not be the same for yours I believe it as a unity tiny bug But I need to turn on symbols and release build to get the game to show up when building but after you have those settings turned on let's click Play to build our game our Game built with no problems and was able to load up if we hit f12 You'll see that it says attempting to initialize Facebook instant and initialize game but we can't be sure if it actually initialized the SDK yet because we have no way of testing it and We're also not hosted on facebook.
com yet and with your game and not hosted on Facebook It will always return an error when trying to access the Facebook instant SDK But we can navigate to where the game was exported at and confirm that it added the Facebook SDK To our built version of the game the way we'll do that is by going into our build folder We can right click on index open with notepad and you'll see inside of our body We have script source connect Facebook net the Facebook instant je s file Excellent, so we know that we're going to be able to access the Facebook instant SDK but let's add in some code to be sure that we're accessing the Facebook Facebook instant SDK So let's just copy and paste this get key down. We'll make it an 'O' So if you push the key, 'O' it's going to print our player ID and our player name to do that will say console.log FB instant dot player dot get ID And then we'll do another console dot log instead of get ID will say get name So when we push o it should print the players ID and the name the ID is unique for each player Depending on what game they are playing and your name is the display name of the Facebook profile you're logged into Let's go back into our unity editor and build our game Alright now that our game is built we can go to the location that the game was built at by Right-clicking on assets show and explore go to tiny export platformer html5 Release and we're going to create the build folder into a dot zip folder So right click on build go to add to archive dot zip once your game is turned into a dot zip folder, let's upload this to Facebook instant so if we navigate to developer.
facebook.com/apps/ we can add a new app We'll give it a display name. I'll call mine a YouTube platformer test Create your app ID complete your security check Once your app is created you can click on skip for the select a scenario we're going to go to our dashboard We're gonna scroll down, add the instant game's module Once it's added go to web hosting Go to upload a version choose file Navigate to where your unity tiny projects release Html5 build dot zip file is select it and upload it Once it's uploaded it'll status will be scanning when it goes from scanning to standby We'll push it to production confirm that you want to push it to production and Once it's in production. We can go to details Scroll down find your shareable link. We can copy that link open a new tab and navigate to that link Your game loads you can click play now and you'll see it loads in multiple of your characters and multiple enemies which isn't right and if you hit f12 you'll see that it initialized the game four times if We look at our code you'll notice that this is an async call and this is inside of an update So this is getting called multiple times within our update the way we're gonna fix this is by saying Facebook instant service dot get instance die is available If it is not available, then we need to initialize it but if it is is available.
We don't need to initialize it anymore So Now that we have it to where it's only going to initialize if it is not available we can save this recompile the game Rebuild our game and Once it's done building we can create a new dot zip file by deleting the old dot zip file and Then right click add to archive select the zip Once it's added to the archive. We'll navigate back to here go to web hosting Upload a new version. We'll choose a file being the build data. We just created upload your new version of the game Then after it goes from scanning to standby, we'll push it to production Then we can reload our game and You'll see that we only have one character and one enemy we can walk around we can attack we can jump and if we push o It'll print our player ID and the display name of our profile Excellent everything seems to be working Exactly how we expected it to now? You know how to use the Facebook instant SDK inside of your unity. Tiny project I hope you've enjoyed this video if you did or if you learned anything, please consider liking and subscribing But until next time I hope you have a wonderful day and I'll see Excellent, we have everything working Excellent, we've managed to get the Facebook instant SDK working inside of our unity tiny project after uploading the unity tiny project to Facebook If you learned anything from this video Please consider liking the video and subscribing to my channel If you have any questions leave a comment below and in the next video we'll probably learn how to use things like the Facebook leaderboards or possibly how to save different values to Facebook based off your characters unique ID But until then have a wonderful day, and I hope I'll see you in the next video.