主题
CelestialBody
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(5 属性 / 28 函数 / 6 事件)
- [CelestialBody](7 属性)
继承成员
1 个来源 / 5 属性 / 28 函数 / 6 事件
- 来自 Unit(5 属性 / 28 函数 / 6 事件)
- 属性:
AssetId、Name、Desc、Parent、Tags - 函数:
ClearAllChildren、GetChildren、GetDescendants、IsAncestorOf、IsDescendantOf、FindFirstAncestor、FindFirstAncestorWhichIsA、FindFirstAncestorOfClass、FindFirstChild、FindFirstChildWhichIsA、FindFirstChildOfClass、HasChildren、GetChildCount、GetChildAtIndex、SetAttribute、GetAttribute、GetAllProps、Clone、IsA、Destroy、GetPropertyChangedSignal、GetAttributeChangedSignal、FindFromPath、GetFullPath、GetDebugId、HasTag、AddTag、RemoveTag - 事件:
ChildAdded、ChildRemoved、DescendantAdded、DescendantRemoving、AncestryChanged、Destroying
- 属性:
天体类型用于构建太阳、月亮这类悬挂在天空中的发光体,可同时存在多个互相独立的天体实例。它通过颜色、亮度与角大小控制光斑观感,并支持指定贴图,还能用旋转与跟随光照朝向来调整天体在天空中的位置表现;受雾影响开关则决定它是否被场景雾效遮蔽。
适用场景
常用于为地图更换昼夜氛围或打造多日同天、异色星球等天空景观:先在场景中创建一个天体实例并挂载到 LightingService 下,再调节它的颜色、亮度与角大小来匹配整体光照风格。
使用要点
通过 game:CreateUnit("CelestialBody", config) 或 World:CreateUnit("CelestialBody", config) 创建实例,随后将其挂载到 LightingService 下作为天空发光体。接着依次设置 Color、Brightness、AngularSize 与 Texture 决定外观,再用 Orientation 调整朝向;如需天体始终对齐光照方向,可开启 FollowLightOrientation,并按需要设置 AffectedByFog 控制雾效影响。
注意事项
该类型只能通过 CreateUnit 创建,不能使用 CelestialBody.New;按照公开示例将实例挂载到 LightingService 后再调整外观。多个天体可同时存在;若外观没有按预期变化,检查光照和雾效相关设置。
代码示例
创建并挂载天体
lua
-- @runtime client
local lighting = game:GetService("LightingService")
local celestialBody = game:CreateUnit("CelestialBody", {
Parent = lighting,
Brightness = 1.0,
FollowLightOrientation = true,
})
print("天体已挂载到光照节点:", celestialBody.Parent == lighting)属性 (7)
| Name | 类型 | 默认值 | 说明 |
|---|---|---|---|
Color | Color | Color.New(255, 255, 255, 255) | Color 类型属性,表示该天体的颜色。 |
Brightness | Float | 1.0 | 浮点属性,表示该天体的亮度。 |
AngularSize | Float | 5.0 | 浮点属性,表示该天体在天球上呈现的角大小。 |
Texture | String | official://image/20003 | 字符串属性,表示该天体所使用的贴图资源标识。 |
Orientation | Vector3 | [45, -45, 0] | CelestialBody 的旋转属性,类型为 Vector3,用于描述天体自身的朝向角度。该属性可读可写,其默认值为 (45, -45, 0)。 |
FollowLightOrientation | Bool | true | 布尔属性,表示该天体是否跟随光照朝向。 |
AffectedByFog | Bool | false | 布尔属性,控制该天体是否受场景雾效影响。 |
