Skip to main content

Use Extend Codegen CLI to generate Unity SDK Plugin for Extend Service Extension

Last updated on November 14, 2023

Overview

The Extend Codegen CLI is a tool for generating code from an OpenAPI 2.0 JSON file according to the template pack used with it. The OpenAPI 2.0 JSON file may come from a custom service, such as Extend Service Extension. The template pack consists of Jinja templates and a Makefile to invoke Extend Codegen CLI and the Jinja templates for generating code.

This particular template pack is used to generate a custom service plugin for the AccelByte Unity SDK. It will allow developers to interact with their custom service APIs more effectively by using AccelByte Unity SDK which offers enhanced functionality, such as login capabilities, token refresh, token validation, and HTTP request retries. All of these features are included to enable developers to concentrate on their specific objectives.

Prerequisites

  1. Based on your operating system, you will need the following tools:

    a. Linux Ubuntu 20.04 (or Windows 10 WSL2)

     i. bash

    ii. make

    iii. Docker v23.x

    b. Windows 10

     i. [Cygwin](https://github.com/AccelByte/extend-codegen-cli/blob/master/windows/INSTALLING_CYGWIN.md)

    ii. Docker v23.x
    info

    Support for macOS may be available soon.

  2. The latest version of the Extend Codegen CLI binary for your operating system. For Linux, you may have to use chmod +x accelbyte-codegen-linux_amd64 to allow the file to be executed.

    info

    Some examples demonstrate the use of the accelbyte-codegen executable file, with the filename potentially varying in your specific scenario such as accelbyte-codegen-linux_amd64 or accelbyte-codegen-windows_amd64, depending on your operating system.

  3. The latest version of the template pack zip.

  4. The AccelByte Unity SDK.

  5. A valid Open API 2.0 JSON file from your custom service.

Generate Unity SDK Plugin for Extend Service Extension

  1. Copy a valid Open API 2.0 JSON/YAML file(s) from your custom service into a folder in your Unity project, for example /path/to/my/unity/project/spec

    danger

    The template pack uses the OpenAPI 2.0 JSON file name as an identifier for your service. You can rename the file according to your preferences, but please use all lowercase alphabets (a-z) to avoid issues when generating code. :::

    a. Duplicate the JSON/YAML file(s) from your custom service(s) into 3 more directories (Client, GameServer, Models) under the folder you've chosen.

    /path/to/my/unity/project/
    ├── Assets/
    ├── Library/
    ├── Packages/
    ├── ProjectSettings/
    └── spec/
    ├── Client/
    │ └── guild.json <
    ├── GameServer/
    │ └── guild.json <
    ├── Models/
    │ └── guild.json <
    └── guild.json
  2. Unzip the contents of the template pack zip file you downloaded. Next, navigate inside the folder where a Makefile file is located and execute the following command.

    make all \
    CODEGEN_PATH=/path/to/my/accelbyte-codegen \
    PROJECT_PATH=/path/to/my/unity/project \
    SPEC_PATH=/path/to/my/unity/project/spec

    Output:

    * copied ./res/com.AccelByte.SDK.Custom into com.AccelByte.SDK.Custom
    * copied spec/Client into com.AccelByte.SDK.Custom/spec/Client
    * copied spec/GameServer into com.AccelByte.SDK.Custom/spec/GameServer
    * copied spec/Models into com.AccelByte.SDK.Custom/spec/Models
    * generated package.json: '{package_name: com.AccelByte.SDK.Custom, package_version: 0.1.0, unity_version: 2020.2}'
    * generated package-lock.json
    * generated version.json
    * generated guild Client API
    * generated guild Client Wrapper
    * generated guild GameServer API
    * generated guild GameServer Wrapper
    * generated guild Models
    { "services": [ { "file_stem": "guild", "path": "guild" } ] }
    { "services": [ { "file_stem": "guild", "path": "guild" } ] }
    * generated Client Config
    * generated GameServer Config
  3. Add com.accelbyte.sdk.custom as a dependency in your Packages/manifest.json

    {
    "dependencies": {
    "com.accelbyte.unitysdk": "file:../com.AccelByte.SDK",
    ...
    "com.accelbyte.unitysdk.custom": "file:../com.AccelByte.SDK.Custom"
    }
    }