主题
CelestialBody
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(4 属性 / 25 函数 / 6 事件)
- [CelestialBody](7 属性)
继承成员
1 个来源 / 4 属性 / 25 函数 / 6 事件
- 来自 Unit(4 属性 / 25 函数 / 6 事件)
- 属性:
AssetId、Name、Desc、Parent - 函数:
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 - 事件:
ChildAdded、ChildRemoved、DescendantAdded、DescendantRemoving、AncestryChanged、Destroying
- 属性:
天体类型用于在场景中布置太阳、月亮等天空发光体,支持同时存在多个实例。它通过颜色、亮度与角大小控制光球的视觉表现,并可指定贴图与朝向;开启跟随光照朝向后其方向会与场景光照保持一致,还可选择是否受雾效影响。
适用场景
常用于为地图塑造天空氛围,例如创建一个发光天体作为太阳或月亮,再配合颜色与角大小表现不同的时段与天气观感。
使用要点
使用 game:CreateUnit("CelestialBody", config) 或 World:CreateUnit("CelestialBody", config) 创建实例,创建时可在配置中传入 Color、Brightness、AngularSize 与 Texture。创建后直接读写实例上的 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] | Vector3 类型属性,表示该天体的旋转。 |
FollowLightOrientation | Bool | true | 布尔属性,表示该天体是否跟随光照朝向。 |
AffectedByFog | Bool | false | 布尔属性,控制该天体是否受场景雾效影响。 |
