How to use Llama Chat in an existing project
Prerequisites
Ensure TextMeshPro is in your project already. If it is not, you can add it from the package manager.
If you do not already have a database, you can use the provided sqlite database in Assets/Llama Software/Llama Chat/Demo/Database/login.db
until you move your users to a more production-ready database.
If you already have a database you will need to make some sql command changes to hook up Llama Chat to your database. If you do not use sqlite please ensure you have the appropriate C# libraries to connect to your database.
Recommend you add subscribed_channels
table as defined in Assets/Llama Software/Llama Chat/Demo/Database/create_login_sample.sql
. If you want to support friends list & block list, recommend also having a similar setup for friends
table and blocked_players
table if you do not already have them.
Updating SQL to match your database
I cannot cover all cases in this section, but I will provide the files that interact with a database and the concepts should be similar regardless of platform. This is the primary effort in integrating with an existing project with an existing database.
Review the sql in Assets/Llama Software/Llama Chat/Demo/Database/create_login_sample.sql
so you understand the structure that was implemented for the demo and what kind of query changes need to happen to match your schemas.
- Open
LlamaSoftware.Chat.SQLitePlayerDatabase
class -SQLitePlayerDatabase.cs
a. This is the class that primarily interacts with the database i. if you are not using sqlite you will need to connect to your database in a similar fashion to what is done here. ii. If you are using sqlite, findPathToDatabase
and update it to whatever URI you have your database on. b. InFindPlayersWhoHaveFriend
update the command to match your schema. Currently it uses a unique player identifier and finds all players who have thatid
in thefriend_id
column, and joins that with the main account (login
) table to be able to generate a Player object. c. InFindFriendsFor
update the command to match your schema. Currently it uses a unique player identifier as a key and finds allid
s in thefriend_id
column and joins that with the main account (login
) table to be able to generate a Player object d. InFindPlayersWhoAreBlockedBy
&FindBlockedPlayersFor
the same logic happens, just on theblocked_players
table to find which players a given player should not talk to and not be able to be talked to by. e. InFindSubscribedChannelsFor
I would recommend just creating thissubscribed_channels
table and keeping this code the same. f. InDoSavePlayerData
it updates a given player's friends, blocked players, and channels. - View
LlamaSoftware.Chat.Demo.LoginController
-LoginController.cs
a. InCreatePlayerFromRow
we do Player Construction – you will likely want to do a similar process on successful login. i. If using Mirror, you can abstract the login piece out with an Authenticator.
Update your Player Prefab
Add LlamaSoftware.Chat.Player_Chat
– Player_Chat.cs
to your Player prefab and configure default chat channels.