> For the complete documentation index, see [llms.txt](https://docs.decentraland.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/jiao-hu-xing/skybox-control.md).

# 天空盒控制

更改天空盒时间

你可以在玩家站在你的场景中时改变他们看到天空盒的方式，这也会影响全局照明的色调和方向。

Decentraland 的天空遵循一个默认的昼夜循环，完成一次需要 2 小时，因此每个真实世界的一天会有 12 个完整循环。如果场景没有强制固定的时段，那么玩家也可以通过在 UI 中调整滑块切换到特定的时段。

每当玩家进入一个具有不同时间的场景，或者场景动态更改时间时，天空盒都会在几秒内平滑过渡到这个新值。

## 固定时段

你可以为场景设置固定的时间。所有玩家看到的场景都会是这个时间，天空盒不会遵循昼夜循环。

在 Creator Hub 中，打开场景设置并点击 **设置** 选项卡以找到 **天空盒** 部分。取消勾选 **自动** 选项，然后设置你想要的时间。

![](https://2460066822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoPnXBby9S6MrsW83Y9qZ%2Fuploads%2Fgit-blob-85bd070c455c7e5852eba1e78902edb88dbfd17b%2Ffixed-time-of-day.png?alt=media)

你也可以在场景代码中设置天空盒时间。为此，请将以下部分添加到你的 `scene.json` 根级别：

```json
 "skyboxConfig": {
    "fixedTime": 36000
  }
```

该数字表示自一天开始以来经过的秒数，范围从 0（表示 *00:00*）到 86400（表示 *24:00*）。任何高于 86400 的数字也会被解释为午夜。

以下是一些更多有效值示例：

* 0 秒 => *00:00*
* 21600 秒 => *06:00*
* 43200 秒 => *12:00*
* 64800 秒 => *18:00*
* 86400 秒 => *24:00*

## 读取一天中的时间

你可以在场景代码中使用以下内容读取一天中的时间： `getWorldTime()` 函数。

```ts
import { getWorldTime } from '~system/Runtime'

executeTask(async () => {
  let time = await getWorldTime({})
  console.log(time.seconds)
})
```

该函数返回 0 到 86400 之间的一个数字，其中 0 表示午夜，86400 表示 24:00。如果场景动态更改时间，或玩家在 UI 中更改时间，此值会更新。否则，它返回相对于默认昼夜循环的值。

## 动态更改时间

你可以使用以下内容动态更改时间： `SkyboxTime` 组件。此组件只能添加到场景的根实体 `engine.RootEntity`.

```ts
import { SkyboxTime } from '@dcl/sdk/ecs'

function main() {
  SkyboxTime.create(engine.RootEntity, { fixedTime: 36000 })
}
```

该 `fixed_time` 属性是 0 到 86400 之间的数字，其中 0 表示午夜，86400 表示 24:00。任何高于 86400 的数字也会被解释为午夜。

每当添加、移除此组件，或 `fixed_time` 该属性发生更改时，天空盒中的一天时间都会在几秒内平滑过渡到这个新值。玩家离开或进入场景时也会发生同样的情况。当天空盒时间被固定时，天空盒将不再随其昼夜循环推进，玩家也无法通过 UI 更改时间。

默认情况下，过渡总是向前进行，但你可以通过设置 `transitionMode` 属性设为 `TransitionMode.TM_FORWARD` 或 `TransitionMode.TM_BACKWARD`.

```ts
import { SkyboxTime, TransitionMode } from '@dcl/sdk/ecs'

function main() {
  SkyboxTime.create(engine.RootEntity, { fixedTime: 36000, transitionMode: TransitionMode.TM_BACKWARD })
}
```

{% hint style="info" %}
**💡 提示**：有关天空盒控制的可用示例，请参见 [`2,1-skybox-sdk-scene-a`](https://github.com/decentraland/sdk7-test-scenes/tree/main/scenes/2,1-skybox-sdk-scene-a) 和 [`3,1-skybox-sdk-scene-b`](https://github.com/decentraland/sdk7-test-scenes/tree/main/scenes/3,1-skybox-sdk-scene-b) 测试场景，其中驱动 `SkyboxTime` 和 `TransitionMode` 从 UI 面板实时控制，以及 [`2,0-skybox-scene-json`](https://github.com/decentraland/sdk7-test-scenes/tree/main/scenes/2,0-skybox-scene-json)，其读取 `fixedTime` 设置在 `scene.json` 在运行时通过 `getSceneInformation()`.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/jiao-hu-xing/skybox-control.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
