# Unity Gaming Services（Unity 游戏服务）CLI

> Create and manage schedule configurations from the command line using the Unity Gaming Services command-line interface.

您可以使用 [Unity Gaming Services（Unity 游戏服务）CLI](https://services.docs.unity.com/guides/ugs-cli/latest/general/overview) 来处理计划。通过 CLI 可以从命令行管理计划配置。

## 先决条件##prerequisites

如需了解 CLI 更全面的信息，请按照 [Unity Gaming Services（Unity 游戏服务）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. 使用以下命令配置您的 Project ID 和环境：
   `ugs config set project-id <your-project-id>`
   `ugs config set environment-name <your-environment-name>`

3. 为服务帐户配置 [Scheduler](https://services.docs.unity.com/docs/service-account-auth/index.html#scheduler-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

如需了解所有命令和选项的完整参考，请参阅 [Scheduler 命令行文档](https://services.docs.unity.com/guides/ugs-cli/latest/scheduler/Scheduler%20Command%20Line/overview)。

> **Note:**
>
> **注意：**`ugs scheduler` 命令也可按照 `ugs sched` 的形式使用。

### 部署计划##deploy-schedules

运行 `new-file` 命令在本地创建计划配置：

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

配置文件内容可能如下所示：

```json
{
  "$schema": "https://ugs-config-schemas.unity3d.com/v1/schedules.schema.json",
  "Configs": {
    "Schedule1": {
      "EventName": "EventType1",
      "Type": "recurring",
      "Schedule": "0 * * * *",
      "PayloadVersion": 1,
      "Payload": "{}"
    },
    "Schedule2": {
      "EventName": "EventType2",
      "Type": "one-time",
      "Schedule": "2024-03-08T13:06:32.311+00:00",
      "PayloadVersion": 1,
      "Payload": "{ \"message\": \"Hello, world!\"}"
    }
  }
}
```

如果需要，还可以将计划配置分到多个文件中。

```json
{
  "$schema": "https://ugs-config-schemas.unity3d.com/v1/schedules.schema.json",
  "Configs": {
    "Schedule1": {
      "EventName": "EventType1",
      "Type": "recurring",
      "Schedule": "0 * * * *",
      "PayloadVersion": 1,
      "Payload": "{}"
    }
  }
}
```

```json
{
  "$schema": "https://ugs-config-schemas.unity3d.com/v1/schedules.schema.json",
  "Configs": {
    "Schedule2": {
      "EventName": "EventType2",
      "Type": "one-time",
      "Schedule": "2024-03-08T13:06:32.311+00:00",
      "PayloadVersion": 1,
      "Payload": "{ \"message\": \"Hello, world!\"}"
    }
  }
}
```

您可以使用 `Deploy` 命令将本地计划配置文件推送到远程环境。

您需要部署配置文件后才能激活计划。

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

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

### 获取计划##retrieve-schedules

要列出所有当前激活的计划，请运行以下命令：

```bash
ugs scheduler list
```

您可以使用 `Fetch` 命令一次性从远程获取多个计划。

提供的路径是保存计划的目录：

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

### 删除计划##delete-schedules

您可以运行带有 `--reconcile` 标志的 `deploy` 命令来删除计划。

> **Warning:**
>
> **警告：** 协调 (reconcile) 是一项破坏性操作。它会删除所提供路径中不存在的所有计划。您可以先检查带 `--dry-run` 标志的命令的输出，然后再运行不带该标志的命令。

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