After working in backend and game services, I knew there was a need for easy upkeep for game developers. So, I created an open-source lightweight API for Unity to access backend services with minimal setup. Specifically made for Azure Functions, the API can be used for other services, like AWS with a few header changes. I created a sample Unity project to help others understand how it works.
Implementing EAFU in a Unity project involves a few steps:
Game API Example
The GameApi class, built using the Easy Azure Functions for Unity (EAFU) library, simplifies interactions with backend services. It provides methods like CreatePlayer to send player data and GetLeaderboard to fetch leaderboard data from Azure Functions.
[Serializable]
public class GameApi : EAFUApi
{
public Player player { get; set; }
public void CreatePlayer(string name, int score, int gameDuration, Action
public void GetLeaderboard(Action<List> GetLeaderboardsAction) => Get(GetLeaderboardsAction);
}
You can use an instance of GameApi to create a player and update the leaderboard in two action callbacks:
// Post Player subscribte GetLeaderboards after creating Player
gameApi.CreatePlayer(playerName, score, gameDuration, postPlayerAction => {
// Get Leaderboards and Set Game UI
gameApi.GetLeaderboard(SetLeaderboard));
}