主题
WaterUnit
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(5 属性 / 28 函数 / 6 事件)
- SpaceUnit(1 属性 / 6 函数)
- BasePart(24 属性 / 9 函数)
- TriggerUnit(8 属性 / 7 函数 / 4 事件)
- [WaterUnit](20 属性 / 5 函数)
- TriggerUnit(8 属性 / 7 函数 / 4 事件)
- BasePart(24 属性 / 9 函数)
- SpaceUnit(1 属性 / 6 函数)
继承成员
4 个来源 / 23 属性 / 50 函数 / 10 事件
- 来自 TriggerUnit(8 属性 / 7 函数 / 4 事件)
- 属性:
CFrame、Scale、DisplayModelId、PhysicsActive、ModelBindParent、CollisionGroup、CanTouch - 函数:
AddCollisionWithGroup、RemoveCollisionWithGroup、GetCollisionWithGroups、AddNoCollisionPairWithUnit、RemoveNoCollisionPairWithUnit、RemoveAllNoCollisionPairWithUnit、GetNoCollisionPairUnitList - 事件:
OnTriggerEnter、OnTriggerExit、OnLocalTriggerEnter、OnLocalTriggerExit
- 属性:
- 来自 BasePart(24 属性 / 9 函数)
- 属性:
PivotOffset、Position、Rotation、Size、AssemblyRootPriority、AssemblyLinearVelocity、AssemblyAngularVelocity、AssemblyMass、AssemblyCenterOfMass、Persistent - 函数:
IsNetworkOwnerSide、GetNetworkOwner、SetNetworkOwner、GetNetworkOwnershipAuto、SetNetworkOwnershipAuto、IsWeldConstraintRoot、IsWeldConstraintChild、GetConnectedUnits、SyncRenderToPhysics
- 属性:
- 来自 SpaceUnit(1 属性 / 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
- 属性:
深水单位用于在场景中划定一片深水区域,进入其中的物体将受到浮力与阻尼等水体物理影响。它通过 WaterDensityMode、WaterDensity、WaterDensityRatio 调节密度表现,用 WaterVelocity 与 WaterVelocityInLocalSpace 描述水流方向和是否跟随局部坐标系。外观侧提供 ModelAlpha、ModelVisible、CastShadow、ModelColor1 至 ModelColor4 以及一套皮肤槽位接口,可分别控制可见度、染色与贴图细节。
适用场景
常用于在关卡里放置河流、湖泊或泳池等水域,让角色与物体进入后自然漂浮并随水流漂移;也用于需要按队伍或阶段切换水面外观与水花颜色的场景。
使用要点
先通过 game:CreateUnit("WaterUnit", config) 或 World:CreateUnit("WaterUnit", config) 创建实例,随后写入 WaterDensityMode、WaterDensity、WaterDensityRatio 与 WaterVelocity 等水体参数;外观可用 SetRenderMeshWithDefaultSkin 指定模型,再用 SetTexture 更换贴图,或用 SetSlotSkinId、SetSlotModelColor 分别调整槽位皮肤与染色,并通过 GetAllSlotSkinIds 读取当前槽位皮肤列表做校验。
注意事项
WaterUnit 是深水区域单位,可通过 game:CreateUnit 或 World:CreateUnit 创建。水体参数(WaterDensity、WaterDensityRatio、WaterVelocity 等)作用于进入区域的对象;外观相关的 SkinId、SkinSlots 与渲染函数需要与 ModelColor 系列属性配合使用。
代码示例
创建 WaterUnit 实例
lua
-- @runtime client
local World = game:GetService('World')
local waterUnit = World:CreateUnit('WaterUnit', {})
if waterUnit == nil then return end
print('WaterUnit 已创建:', waterUnit.Name)属性 (20)
| Name | 类型 | 默认值 | 说明 |
|---|---|---|---|
WaterDensityMode | Int | 0 (DensityTypeDirect) | WaterUnit 的密度类型属性,类型为 Enums.Int,用于指定水面密度的取值方式。 |
WaterDensity | Float | 6.0 | WaterUnit 的密度值属性,类型为 Float,用于描述水面的密度数值。 |
WaterDensityRatio | Float | 2 | WaterUnit 的密度比属性,类型为 Float,用于描述水面密度比例。 |
WaterVelocityInLocalSpace | Bool | false | WaterUnit 的水流速度跟随局部坐标系属性,类型为 Bool,用于决定水流速度是否按局部坐标系解释。 |
WaterVelocity | Vector3 | [0, 0, 0] | WaterUnit 的水流速度属性,类型为 Vector3,用于描述水面的水流速度向量。 |
WaterSplashColor | Color3 | Color3.New(144, 212, 255) | WaterSplashColor 是 WaterUnit 的水花颜色属性,类型为 Color3,可公开读写,用于描述水体水花的染色颜色。 |
RenderMeshId | String | official://mesh/250173 | WaterUnit 的模型资源 ID 属性,类型为 String,用于指定水面显示所使用的模型资源。 |
PhysicsMeshId | String | official://mesh/250173 | WaterUnit 的物理资源 ID 属性,类型为 String,用于指定水面使用的物理网格资源。 |
ModelAlpha | Float | 0.85 | WaterUnit 的模型透明度属性,类型为 Float,用于描述水面模型在渲染时的整体透明程度。 |
ModelVisible | Bool | true | WaterUnit 的模型可见性属性,类型为 Bool,用于控制水面模型是否显示。 |
CastShadow | Bool | false | WaterUnit 的启用阴影投射属性,类型为 Bool,用于控制水面模型是否投射阴影。 |
ModelColor1 | Color3 | Color3.New(255, 255, 255) | ModelColor1 是 WaterUnit 的第 1 号染色区域颜色,类型为 Color3,可公开读写,默认值为白色。 |
ModelColor2 | Color3 | Color3.New(255, 255, 255) | ModelColor2 是 WaterUnit 的第 2 号染色区域颜色,类型为 Color3,可公开读写,默认值为白色。 |
ModelColor3 | Color3 | Color3.New(255, 255, 255) | ModelColor3 是 WaterUnit 的第 3 号染色区域颜色,类型为 Color3,可公开读写,默认值为白色。 |
ModelColor4 | Color3 | Color3.New(255, 255, 255) | ModelColor4 是 WaterUnit 的第 4 号染色区域颜色,类型为 Color3,可公开读写,默认值为白色。 |
SkinId | String | "" | WaterUnit 的皮肤属性,类型为 String,用于指定水面模型使用的皮肤资源标识。 |
UseSkinList | Bool | false | WaterUnit 的多槽位皮肤开关属性,类型为 Bool,用于决定是否启用多槽位皮肤方案。 |
SkinSlots | Array<SkinSlot> | [] | SkinSlots 是 WaterUnit 的皮肤槽位列表属性,类型为数组,可公开读写,默认值为空列表。 |
UseCustomAppearance | Bool | false | WaterUnit 的使用自定义外观属性,类型为 Bool,用于决定是否启用自定义外观。 |
CustomAppearanceId | String | "" | WaterUnit 的自定义外观 ID 属性,类型为 String,用于指定所使用的自定义外观资源标识。 |
关联类型
函数 (5)
SetTexture
签名:SetTexture(textureAssetId: String, texIndex?: TextureChannel, slotIndex?: SkinSlotIndex) -> void
为 WaterUnit 设置贴图资源,可指定贴图通道与皮肤槽位。
| 参数 | 类型 | 说明 |
|---|---|---|
textureAssetId | String | 贴图资源ID,传空字符串清除该通道覆盖 |
texIndex? | TextureChannel | 贴图通道(TextureChannel.MAIN=主贴图 / NORMAL=法线 / MRE),缺省 TextureChannel.MAIN |
slotIndex? | SkinSlotIndex | 皮肤槽位(SkinSlotIndex.SLOT_1~4);缺省或 SkinSlotIndex.ALL 时:多槽位模式作用于全部槽位、单皮肤模式作用于当前皮肤 |
返回值 void
示例代码
调用 WaterUnit:SetTexture 的示例。
lua
-- @runtime client
local waterUnit = game:CreateUnit("WaterUnit", {})
local textureAssetId = "示例文本" -- String
local texIndex = Enums.TextureChannel.MAIN -- TextureChannel
local slotIndex = Enums.SkinSlotIndex.ALL -- SkinSlotIndex
waterUnit:SetTexture(textureAssetId, texIndex, slotIndex)
print("已调用 SetTexture", textureAssetId)SetRenderMeshWithDefaultSkin
签名:SetRenderMeshWithDefaultSkin(renderMeshId: String) -> void
切换 WaterUnit 的显示模型,并为该模型应用默认皮肤。
| 参数 | 类型 | 说明 |
|---|---|---|
renderMeshId | String | 模型资源ID |
返回值 void
示例代码
调用 WaterUnit:SetRenderMeshWithDefaultSkin 的示例。
lua
-- @runtime client
local waterUnit = game:CreateUnit("WaterUnit", {})
local renderMeshId = "default" -- String
waterUnit:SetRenderMeshWithDefaultSkin(renderMeshId)
print("已调用 SetRenderMeshWithDefaultSkin", renderMeshId)SetSlotSkinId
签名:SetSlotSkinId(slotIndex: SkinSlotIndex, skinId: String) -> void
为 WaterUnit 的指定皮肤槽位设置皮肤。
| 参数 | 类型 | 说明 |
|---|---|---|
slotIndex | SkinSlotIndex | 槽位索引(SkinSlotIndex.SLOT_1~SLOT_4,对应 0~3;ALL = 全部槽位) |
skinId | String | 皮肤资源ID |
返回值 void
示例代码
调用 WaterUnit:SetSlotSkinId 的示例。
lua
-- @runtime client
local waterUnit = game:CreateUnit("WaterUnit", {})
local slotIndex = Enums.SkinSlotIndex.ALL -- SkinSlotIndex
local skinId = "default" -- String
waterUnit:SetSlotSkinId(slotIndex, skinId)
print("已调用 SetSlotSkinId", slotIndex)GetAllSlotSkinIds
签名:GetAllSlotSkinIds() -> Array<String>
获取 WaterUnit 全部槽位的皮肤资源 ID 列表。
返回值 Array<String>
示例代码
调用 WaterUnit:GetAllSlotSkinIds 的示例。
lua
-- @runtime client
local waterUnit = game:CreateUnit("WaterUnit", {})
local result = waterUnit:GetAllSlotSkinIds() -- 返回 Array
if result ~= nil then
for index, item in ipairs(result) do
print(index, item)
end
endSetSlotModelColor
签名:SetSlotModelColor(slotIndex: SkinSlotIndex, colorIndex: ModelColorIndex, color: Color3) -> void
为 WaterUnit 的指定皮肤槽位设置某一颜色通道的模型染色。调用时按顺序传入槽位索引 slotIndex、颜色通道 colorIndex 与目标颜色 color,三个参数均为必填。
| 参数 | 类型 | 说明 |
|---|---|---|
slotIndex | SkinSlotIndex | 槽位索引(SkinSlotIndex.SLOT_1~SLOT_4,对应 0~3;ALL = 全部槽位) |
colorIndex | ModelColorIndex | 染色区索引(ModelColorIndex.MODEL_COLOR_1~MODEL_COLOR_4,对应 1~4) |
color | Color3 | 染色颜色 |
返回值 void
示例代码
为水面槽位染色
lua
-- @runtime client
local world = game:GetService("World")
local waterUnit = world:CreateUnit("WaterUnit", {})
if waterUnit == nil then return end
-- slotIndex 取 SkinSlotIndex,colorIndex 取 ModelColorIndex,color 是 0~255 分量的 Color
waterUnit:SetSlotModelColor(Enums.SkinSlotIndex.SLOT_1, Enums.ModelColorIndex.MODEL_COLOR_1, Color.New(0, 128, 255, 255))