Extend-codegen-cli usage documentation

Hi folks,

I’ve been experimenting with accelbyte-codegen-windows_amd64.exe to generate the Unity API for my Service Extension (in Starter).

I have it successfully generating my API, which is neat and super handy. However, I don’t entirely know how to use it. It’s not particularly self-explanatory, and here is the entirety of the generated README.md. I’d appreciate a bit more information about the intended usage!


AccelByte Unity Customization

Getting Started

Preparation

  1. Download the whole repository.
  2. Add com.accelbyte.sdk.custom dependency into Packages/manifest
    {
        "dependencies": {
            "com.accelbyte.unitysdk.custom": "file:../DownloadedPackages/com.AccelByte.SDK.Custom"
        }
    }
    
  3. Fill the AccelByte SDK config file named AccelByteSDKConfig.json on Assets/Resources directory.

Using the Custom SDK

At first, you need to import the AccelByte namespace.

using AccelByte.Api;
using AccelByte.Core;
using AccelByte.Models;

Hello there again, it’s me from the Extend team.

I’ve attached an example from this release of the Extend Codegen CLI containing a “working” (relies on a reachable Guild service) example of how one would use the code-generated service package in Unity. (see the accelbyte-unity-sdk-template-example/MyAwesomeGame/Assets/Usage.cs file)

using AccelByte.Api;
using UnityEngine;

using AccelByte.Core;
using AccelByte.Models;

public class Usage : MonoBehaviour
{
    [SerializeField] private string _username;
    [SerializeField] private string _password;

    private ApiClient _apiClient;

    private void Start()
    {
        _apiClient = AccelByteSDK.GetClientRegistry().GetApi();

        User user = _apiClient.GetUser();

        user.LoginWithUsernameV3(_username, _password, LoginWithUsernameV3Callback);
    }

    private void LoginWithUsernameV3Callback(Result<TokenData, OAuthError> result)
    {
        if (result.IsError)
        {
            return;
        }

        Guild guild = _apiClient.GetApi<Guild, GuildApi>();

        guild.GuildServiceGetGuildProgress("foo", GuildServiceGetGuildProgressCallback);
    }

    private void GuildServiceGetGuildProgressCallback(Result<AccelByteGuildGuildGetGuildProgressResponse> result)
    {
        Debug.Log("Success!");
    }
}

:bulb: In the example above it uses the old way to get the ApiClient it is now encouraged to use MultiRegistry.GetApiClient().

The main takeaway here is the taking a hold of the instance of the ApiClient to get an instance of the <insert custom service name here>Api class. Similarly from how you would normally use the Unity SDK. See this tutorial on how to implement a periodic leaderboard.

For example,

ApiClient apiClient = MultiRegistry.GetApiClient();
Guild guild = apiClient.GetApi<Guild, GuildApi>();
guild.GuildServiceGetGuildProgress("foo", GuildServiceGetGuildProgressCallback);
1 Like