主题
FindingPathUnit
寻路路径单元用于按顺序维护一组路径点,公开 Meta 支持添加、删除以及发起路点/数量查询。
概览
寻路路径单元用于按顺序维护一组路径点,公开 Meta 支持添加、删除以及发起路点/数量查询。
继承自
SpaceUnit;可通过World:CreateUnit("FindingPathUnit", ...)创建;返回单个单位
函数
GetWaypoints
签名:GetWaypoints() -> Array
获取当前路径的路点列表;每个元素是包含 Position = Vector3 的 table。
返回值 Array — 每个元素为 { Position = Vector3 } 结构的 table。
读取全部路点位置
lua
-- @runtime client
local path = game:GetService('World'):CreateUnit('FindingPathUnit', {})
if path == nil then return end
path:AddPoint(Vector3.New(0, 0, 0))
for index, waypoint in ipairs(path:GetWaypoints()) do
print('路点条目:', index, waypoint)
endAddPoint
签名:AddPoint(position: Vector3) -> Attachment
为寻路单位添加一个路点。传入目标位置的三维坐标,寻路单位会在该位置创建一个路点,并返回表示该路点的 Attachment 实例;若添加失败则返回 nil。
| 参数 | 类型 | 说明 |
|---|---|---|
position | Vector3 | 路点世界位置 |
返回值 Attachment
向路径末尾添加路点
lua
-- @runtime client
local path = game:GetService('World'):CreateUnit('FindingPathUnit', {})
if path == nil then return end
local attachment = path:AddPoint(Vector3.New(10, 0, 5))
if attachment == nil then return end
print("新路点:", attachment.Name)RemovePoint
签名:RemovePoint(index: Int)
根据索引移除一个路点。
| 参数 | 类型 | 说明 |
|---|---|---|
index | Int | 路点索引 |
按 1-based 索引删除路点
lua
-- @runtime client
local path = game:GetService('World'):CreateUnit('FindingPathUnit', {})
if path == nil then return end
path:AddPoint(Vector3.New(0, 0, 0))
path:AddPoint(Vector3.New(10, 0, 5))
path:RemovePoint(2)GetPointCount
签名:GetPointCount() -> Int
返回当前路径点数量。
返回值 Int
读取路径点数量
lua
-- @runtime client
local path = game:GetService('World'):CreateUnit('FindingPathUnit', {})
if path == nil then return end
path:AddPoint(Vector3.New(0, 0, 0))
print("路径点数量:", path:GetPointCount())属性
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
Name | String | 寻路路径 | 寻路路径的名称标识,用于在场景中区分不同的寻路路径实例。 |
