> For the complete documentation index, see [llms.txt](/llms.txt)

# 実装

GS2 を利用したゲーム開発について




GS2-SDK はゲームエンジンに特化した SDK が提供されています。
Unity、Unreal Engine 5、Godot を利用した開発者はこの SDK による様々な機能を利用できます。

## Unity

Unity で利用できる SDK として 「GS2-SDK for Unity」 を提供しています。
Unity Package Manager(UPM) と完全に統合されており、SDK の更新も UPM 上で行えます。

依存しているライブラリは [LitJSON](https://litjson.net/)(Public Domain) / [websocket-sharp](https://github.com/sta/websocket-sharp)(MIT) / [Protocol Buffers](https://developers.google.com/protocol-buffers)(BSD) のみです。
GS2-SDK for Unity は Apache License 2.0 で提供されており、以下の GitHub リポジトリで全てのソースコードが公開されています。

- https://github.com/gs2io/gs2-csharp-sdk
- https://github.com/gs2io/gs2-sdk-for-unity
- https://github.com/gs2io/gs2-uikit-for-unity

GS2-SDK for Unity はサーバーから取得したデータの状態管理機能を有しています。
APIを通して取得したデータは SDK のレイヤーでキャッシュされ、サーバーの値が更新された場合はキャッシュも自動的に更新されます。

そのため、開発者はデータの読み込みに関しては、何も考えずに Update関数 から GS2-SDK の API を呼び出して最新の値にアクセスできます。

### 実装例

```csharp
    var result = await gs2.Account.Namespace(
        namespaceName: "namespace-0001"
    ).CreateAsync();

    var item = await result.ModelAsync();
    var userId = item.UserId;
    var password = item.Password;
```

### GS2-UIKit for Unity

![uikit.png](uikit.png)

より Unity に特化した SDK です。

Unity Editor で GameObject に対してコンポーネントを付与するだけで、テキストにアイテムの所持数量を反映したり
回数制限の上限に達しているか・達していないかで GameObject を有効化・無効化するような設定ができます。

サーバーからデータを取得して UI に反映するような単純な実装であれば、UI Kit を使用することでノーコードで実現できます。

## Unreal Engine 5

Unreal Engine 5 で利用できる SDK として 「GS2-SDK for Unreal Engine」 を提供しています。
Unreal Engine のプラグインとして提供されており、コードを配置するだけでプロジェクトに組み込むことができます。

依存している外部のライブラリはなく、全て Unreal Engine 5 の標準機能で実装されています。
GS2-SDK for Unreal Engine は Apache License 2.0 で提供されており、以下の GitHub リポジトリで全てのソースコードが公開されています。

- https://github.com/gs2io/gs2-sdk-for-ue5

### 実装例

```cpp
    const auto Domain = Gs2->Account->Namespace(
        "namespace-0001" // namespaceName
    );
    const auto Future = Domain->Create(
    );
    Future->StartSynchronousTask();
    if (Future->GetTask().IsError()) return false;

    // obtain changed values / result values
    const auto Future2 = Future->GetTask().Result()->Model();
    Future2->StartSynchronousTask();
    if (Future2->GetTask().IsError()) return false;
    const auto Result = Future2->GetTask().Result();
```

### Blueprint SDK

![blueprint.png](blueprint.png)

より Unreal Engine 5 に特化した SDK です。

Unreal Editor で開発できるノードベースのプログラミング環境である Blueprint に対応したSDKです。
Blueprint SDK を使用することで、C++ を使用しなくても GS2 の機能にアクセス可能です。

## Godot

Godot 4（GDScript）で利用できる SDK として「GS2 SDK for Godot」を提供しています。
SDK は `addons/gs2` フォルダとして提供されており、Godot プロジェクトへコピーして利用できます。

GS2 SDK for Godot は、ゲーム内から利用しやすい Ez レイヤーと低レベル API クライアントを同梱しています。`Gs2EzDomain` を作成すると、Unity の `gs2.Account` などと同様に `ez.account`、`ez.inventory` といったサービスプロパティから各機能へアクセスできます。
Apache License 2.0 で提供されており、以下の GitHub リポジトリで全てのソースコードが公開されています。

- https://github.com/gs2io/gs2-sdk-for-godot

### 実装例

```gdscript
var credential = Gs2BasicCredential.new("client-id", "client-secret")
var connection = Gs2Connection.new(credential, Gs2Region.AP_NORTHEAST_1)
var ez = Gs2EzDomain.new(connection)

var create_result = await ez.account.namespace_(
    "namespace-0001"
).create()
if create_result.error != null:
    push_error(str(create_result.error))
    return

var model_result = await create_result.result.model()
if model_result.error != null:
    push_error(str(model_result.error))
    return

var account = model_result.result
print("UserId: ", account.user_id)
print("Password: ", account.password)
```




- [GS2の機能拡張](/ja/overview/workflow/coding/extend/)
  
