> 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 个完整循环。如果场景没有强制固定时间，那么玩家也可以通过在其界面中调整滑块来切换到某个特定的时段。

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

## 固定时间

你可以为你的场景设置一个固定的时间。所有玩家都会以该时间看到场景，天空盒不会跟随昼夜循环变化。

在 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\&token=56081304-f57b-475b-94e4-07c292805637)

你也可以在场景代码中设置天空盒时间。为此，请将以下部分添加到你的 `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。如果场景动态更改时间，或者玩家在界面中更改时间，该值会更新。否则，它返回相对于默认昼夜循环的值。

## 动态更改时间

你可以使用以下方式动态更改时间： `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` 属性发生更改时，天空盒时间会在几秒内平滑过渡到这个新值。玩家进入或离开场景时也会发生同样的情况。当天空盒时间被固定时，天空盒将不再跟随其昼夜循环进度，玩家也无法通过界面更改时间。

默认情况下，过渡始终朝前进行，但你可以通过设置以下内容来更改： `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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
