Install/Setup
Requirements
Unity 2020.3.4f1
Docker
PlayFab SDK - (PlayFab is a complete backend platform for live games with managed game services. It is free, the only way that you will be required to pay is if your game scales a lot. For example, PlayFab can have 100 000 users for free and after that you will be required to upgrade. You can check the different plans, but you won't need to pay anything unless your game is getting a lot of traction.)
Dakrift 2 Free version - We use Darkrift for the multiplayer
Gley plugin for ADS - (You can use whatever plugin you want and change the parts that use ads accordingly)
LeanTween FREE
RestClient FREE
URP
Text Mesh Pro
Installation/Setup (Short)
Import Newtonsoft.Json-for-Unity
Import PlayFab SDK
Import Dakrift 2 Free version , LeanTween , RestClient , Facebook SDK
Setup PlayFab (you can do it now or later it's not required to be in that order)
Import TriviaFakeit project
Export YourProject\Assets\TriviaFakeit\Lib.zip into your main project folder "YourProject" so that the folders look similar to "Library, Packages etc.. and Lib should be in there as well after you have extracted Lib.zip
Build Lib \ dt \ multiplayer_server_script \ TriviaTilesMultiplayerServer \ TriviaTIlesMultiplayerServer.sln - (it creates the necessary dll files). Lib folder should be in the main directory if you change it the dll wont be created in the right place.
Go to Lib \ TriviaTiles directory open terminal/PowerShell and enter: docker-compose up -d (this starts all our projects)
Open http://localhost:8073/ and enter username: trivia password: p123456. ( It opens phpmyadmin which is just a tool we use to inspect and work with our database. )
Import -> Choose File -> tdb.sql (tdb.sql is located in the main asset directory it should be something like (Your Game/Assets/TriviaFakeit/tdb.sql)
Open the server project and in TriviaModels->Networking->Constents.cs change DEV_SECRET_KEY and PLAYFAB_ID
This should be it, you can start the game, login and play.
The Trivia Includes
4 Projects
All the game scripts
TriviaTiles.sln
Location: Lib\TriviaTiles
TriviaTIlesMultiplayerServer.sln -
Location: Lib\dt\multiplayer_server_script\TriviaTilesMultiplayerServer
Wordpress (Admin panel)
Location: Lib\.wp\
It includes premade categories/sub categories 130 questions as example
You need to get the Lib projects from Assets\TriviaFakeit\Lib.zip extract it in the main directory of your game. Where there are folders like "Packages" "UserSettings" "Library" so when you extrat it you should have Lib folder with the main projects in it.
1 - All the game scripts
All the scripts for the game in Unity
TriviaTiles
This is the main project which you start the API+Database+Multiplayer Server+Wordpress. Everything is connected with docker-composer file.
You can check the api calls also from : http://localhost:8074/swagger/index.html
TriviaTilesMultiplayerServer
Darkrift 2 Multiplayer server - All the TCP/UDP requests go here
Wordpress
We use Wordpress as a base for our Admin Panel, it includes custom plugin which is controlling all the questions/categories/subcategories/tags in game. You can create/edit/delete all of that from the admin panel.
You can check it at http://localhost:8000. Login with username : admin pasword : admin. On the left side in the menu you can see our plugin Trivia Tiles.
Check the Wordpress section for more info about the admin panel.
Installation/Setup (Long)
Export YourProject\Assets\TriviaFakeit\Lib.zip into your main project folder "YourProject" so that the folders look similar to "Library, Packages etc.. and Lib should be in there as well after you have extracted Lib.zip
One of the first things you need to do is Build the Project TriviaTilesMultiplayerServer. If it is in the correct directory which is pointed above, it should build successfuly and include the dlls inside Assets/Plugins folder.
If Assets\Plugins folder doesn't exist create one and after that build/rebuild the projects again.
These dependencies are required in order the project to run without errors:
Darkrift 2 Free version
Leantween Free
Rest Client free
PlayFab SDK, Facebook SDK and Newtonsoft are external libraries so you need to download them from the links and locate the .unitypackage file that they provide. Then you import it from here:
Import and Setup PlayFab and import Newtonsoft before importing the asset. If you have already imported the Trivia asset before importing PlayFab and Newtonsoft move the whole folder TriviaFakeit outside of the project and Import the assets after that.
PlayFab SDK SETUP - after initial setup
From the PlayFab link above, you should have went trough the steps and have created a Studio and Title ID
There are couple of settings we must configure in order our game to run with PlayFab correctly.
You can set your own settings with different values and etc.. these settings that are shown in this setup are just for example. You are free to change/add/remove whatever you want.
Go to Multiplayer -> Matchmaking -> New queue
Go to Economy -> Currency -> New Currency
We need 2 types of currency. For the MMR and Coins (Example in the below images)
MMR and Coins are not used for any features in game. At some point there might be features that will be using them but currently none are available. MMR will be used for more accurate queues and Coins for Shop items.
Go to Leaderboards -> New Leaderboard
Exact naming of the leaderboards is important. (You can create completely different leaderboards but the current in game uses those ones)
Go to Content -> Title Data and add these key/value pairs.
This is just an example how we can use this as an extra admin panel, if our server has some issues we rely on PlayFab to deliver a message to the users.
Newtonsoft requires that there are no errors inside the project (this is stated inside the documentation of the newtonsoft package) so we need to install it before we put our TriviaFakeit folder inside the Assets. If you already downloaded the package which might be the case before installing Newtonsoft it's not a problem. Just move the TriviaFakeit folder which is located inside the Assets to somewhere outside of the project and install Newtonsoft. After Newtonsoft is installed and you can see the package added to your main game Solution you can move back the TriviaFakeit folder inside the Assets.
The Newtonsoft reference should be added automatically to the solution
If your Unity game doesnt have a solution, you can easily create one by going to (inside Unity) Edit->Preferences->External Tools->Regenerate project files (External script editor should be pointing to Visual studio). Check the image below.
If Tags & Layers are missing. Go to Tags & Layers and select the TriviaFakeitLayersTags from the Presets.
Check in the Build Settings if you have all the Scenes included. If you do not add them.
Go to TriviaTiles directory open terminal/PowerShell and enter: docker-compose up -d
This starts all our projects
Open http://localhost:8073/ and enter username: trivia password: p123456. It opens phpmyadmin which is just a tool we use to inspect and work with our database.
Click on Import -> Choose File -> tdb.sql
tdb.sql is located in the main asset directory it should be something like (Your Game/Assets/TriviaFakeit/tdb.sql, after importing you can delete it it includes all the tables + the main data we need for the game.
Facebook login requires additional setup. You can check the Facebook SDK documentation for how to setup login with Facebook.
Open the server project and in TriviaModels->Networking->Constents.cs change DEV_SECRET_KEY and PLAYFAB_ID
This should be it, you can start the game, login and play.
Gley plugin - ADS
If you want to enable the ADS the most easy way it will be if you get the Gley plugin. If you use something else you just have to put the required code for the plugin you are using at the specific places.
You can search the Game Solution project with CTRL+SHIFT+F for ADSHERE keyword and it will show you where the ads code should be in the project. Uncomment the code and the ads should start working.
Important
If you change the location of any of the projects you might have issues with dependencies. Currently when the projects are built they automatically copy the generated dll in the right directory. You can change that by going to the specific project Build Events and change the locations acoordingly your change.
If you are going to change localhost to something else you need to change couple of places:
TriviaMultiplayerScene -> HomeCanvas
/Scripts/Helper/Api.cs
It's important to know that if you have some different settings in PlayFab for example your matchmaking queue is called differently you need to change the following variable value:
Helper -> Multiplayer -> Models -> MultiplayerGlobals.cs
If you are building for mobile sometimes the Unity engine can strip some code that is needed and might throw exception like Unable to find constructor... if that's the case you need to create a file named link.xml inside Plugins folder with the following code and build again:
You can check more about what is causing the issue here: https://stackoverflow.com/questions/59757635/how-to-solve-newtonsoft-json-jsonserializationexception-unable-to-find-construc
Last updated