# Unity Gaming Services CLI

> Create, deploy, and manage Cloud Code scripts using the Unity Gaming Services command-line interface.

[Unity Gaming Services CLI](https://services.docs.unity.com/guides/ugs-cli/latest/general/overview) を使用して、Cloud Code スクリプトを操作できます。CLI を使用して、コマンドラインから Cloud Code スクリプトを作成、デプロイ、管理できます。

## 前提条件##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. [Cloud Code](https://services.docs.unity.com/docs/service-account-auth/index.html#cloud-code-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

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

> **Note:**
>
> **ノート:** `ugs cloud-code scripts` コマンドは `ugs cc s` としても使用可能です。

### スクリプトのデプロイ##deploy-scripts

`new-file` コマンドを実行して、サンプルコードを含むスクリプトをローカルに作成します。

```bash
ugs cloud-code scripts new-file <file-name>
```

`Deploy` コマンドを使用して、ローカルスクリプトをリモート環境にプロモートし、それらを一度に公開できます。ローカルスクリプトをデプロイして、ゲームクライアントで使用可能にする必要があります。

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

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

### スクリプトの取得##retrieve-scripts

デプロイしたスクリプトに関する情報を取得するには、以下のコマンドを実行します。

```bash
ugs cloud-code scripts get <script-name>
```

以下のコマンドを実行して、Cloud Code に現在デプロイされているすべてのスクリプトをリストすることもできます。

```bash
ugs cloud-code scripts list
```

`Fetch` コマンドを使用して、一度に複数の Cloud Code スクリプトをリモートから取得できます。指定されたパスは、スクリプトのフェッチ先のディレクトリです。

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

> **Note:**
>
> **ノート:** サービスから宣言されたパラメーターがあり、サービススクリプトコードにパラメーターがない場合、Fetch コマンドはローカルスクリプトコードを更新し、そこにパラメーターを追加します。[パラメーター解析](https://services.docs.unity.com/guides/ugs-cli/latest/cloud-code/Cloud%20Code%20Command%20Line/parameter-parsing/) に関するページを参照してください。

### 環境の同期##environment-synchronization

1 つの環境からすべてのスクリプトを移動し、それらを別の環境にデプロイできます。

以下のコマンドを実行して、現在の環境内のすべてのスクリプトのアーカイブを生成します。

```bash
ugs cloud-code scripts export <out-dir> <file-name>
```

次に、以下のコマンドを実行することで、スクリプトをインポートし、それらを別の環境にデプロイできます。

```bash
ugs cloud-code scripts import <in-dir> <file-name> --environment-name <environment-name>
```

スクリプトは自動的に公開されます。

> **Note:**
>
> **ノート:** `Import` はデフォルトで環境を上書きしません。インポート前に既存のスクリプトを削除するには、`--reconcile` フラグを使用します。

### スクリプトの削除##delete-script

既存のスクリプトを削除するには、以下のコマンドを実行します。

```bash
ugs cloud-code scripts delete <script-name>
```

## 追加リソース##additional-resources

* [サンプルのデプロイ](https://github.com/Unity-Technologies/unity-gaming-services-cli/blob/main/Samples/Deploy/instructions.md#deploy-cloud-code-script)
* [パラメーター解析](https://services.docs.unity.com/guides/ugs-cli/latest/cloud-code/Cloud%20Code%20Command%20Line/parameter-parsing/) に関するページを参照して、コマンドがスクリプトパラメーターを扱う方法を理解してください。
