# Unity Gaming Services CLI

> Manage trigger configurations from the command line using the Unity Gaming Services command-line interface.

[Unity Gaming Services CLI](https://services.docs.unity.com/guides/ugs-cli/latest/general/overview) を使用して、トリガーを操作できます。CLI により、コマンドラインからトリガー設定を管理できます。

> **Note:**
>
> **ノート**: CLI は、フィルターを使用したトリガーをサポートしていません。フィルターを使用したトリガーを作成するには、[Triggers Admin API](./rest-api.md) または [Unity Dashboard](./unity-dashboard.md) を使用します。

## 前提条件##prerequisites

CLI の詳細情報については、[Unity Gaming Services CLI の使用の準備ガイド](https://services.docs.unity.com/guides/ugs-cli/latest/general/get-started/install-the-cli/) のステップに従います。

このガイドに従うには、最初に以下のアクションを実行する必要があります。

1. [UGS CLI をインストール](https://services.docs.unity.com/guides/ugs-cli/latest/general/get-started/install-the-cli/) します。

2. プロジェクト ID と環境を以下のように設定します。
   `ugs config set project-id <your-project-id>`
   `ugs config set environment-name <your-environment-name>`

3. [Triggers](https://services.docs.unity.com/docs/service-account-auth/index.html#triggers-configuration-editor) と [環境管理](https://services.docs.unity.com/docs/service-account-auth/index.html#unity-environments-admin) に必要なロールでサービスアカウントを設定します。[認証の取得](https://services.docs.unity.com/guides/ugs-cli/latest/general/get-started/get-authenticated/) を参照してください。

## CLI の使用##using-the-cli

すべてのコマンドとオプションの完全なリファレンスについては、[Triggers コマンドラインのドキュメント](https://services.docs.unity.com/guides/ugs-cli/latest/triggers/Triggers%20Command%20Line/overview) を参照してください。

> **Note:**
>
> **ノート**: `ugs triggers` コマンドは `ugs tr` としても使用可能です。

### トリガーのデプロイ##deploy-triggers

`new-file` コマンドを実行して、トリガー設定をローカルに作成します。

```bash
ugs triggers new-file <file-name>
```

設定ファイルのコンテンツは以下のようになります。

```json
{
  "$schema": "https://ugs-config-schemas.unity3d.com/v1/triggers.schema.json",
  "Configs": [
    {
      "Name": "example-trigger",
      "EventType": "com.unity.services.scheduler.{{EVENT_NAME}}.v{{EVENT_VERSION}}",
      "ActionUrn": "urn:ugs:cloud-code:MyScript",
      "ActionType": "cloud-code"
    }
  ]
}
```

設定ファイルを変更し、複数のトリガーを加えることもできます。

```json
{
  "$schema": "https://ugs-config-schemas.unity3d.com/v1/triggers.schema.json",
  "Configs": [
    {
      "Name": "example-trigger",
      "EventType": "com.unity.services.scheduler.{{EVENT_NAME}}.v{{EVENT_VERSION}}",
      "ActionUrn": "urn:ugs:cloud-code:MyScript",
      "ActionType": "cloud-code"
    },
    {
      "Name": "example-trigger-2",
      "EventType": "com.unity.services.scheduler.{{EVENT_NAME}}.v{{EVENT_VERSION}}",
      "ActionUrn": "urn:ugs:cloud-code:MyScript",
      "ActionType": "cloud-code"
    }
  ]
}
```

`Deploy` コマンドを使用して、ローカルトリガー設定ファイルをリモート環境にプロモートできます。

アクティブなトリガーになるように設定ファイルをデプロイする必要があります。

```bash
ugs deploy <path-to-triggers-file> <path-to-triggers-file>
```

```bash
ugs deploy <path-to-directory>
```

トリガーを既存の Cloud Code スクリプトまたはモジュールに関連付けている場合、`eventType` を指定してイベントを発行するとトリガーが発生し、関連付けられている Cloud Code スクリプトまたはモジュールが実行されます。

### トリガーの取得##retrieve-triggers

`Fetch` コマンドを使用して、一度に複数のトリガーをリモートから取得できます。

指定されたパスは、トリガーの保存先のディレクトリです。

```bash
ugs fetch <path>
```

### トリガーの削除##delete-triggers

トリガーを削除するには、`--reconcile` フラグを指定して `deploy` コマンドを実行します。

> **Warning:**
>
> \*\*注意: \*\*リコンサイルは破壊的な操作です。指定されたパスに存在しないすべてのトリガーが削除されます。`--dry-run` フラグを使用してコマンドの出力を確認してから、フラグなしでコマンドを実行できます。

```bash
ugs deploy --services triggers <path-to-triggers-file> --reconcile
```
