Appearance
区域模块管理接口 Area
具体函数名及描述如下:
| 序号 | 函数名 | 函数描述 |
|---|---|---|
| 1 | CreateAreaPrefab(...) | 创建区域对象 |
| 2 | GetAreaUuidByObjId(...) | 通过区域对象ID获取区域uuid |
| 3 | CreateAreaRectByRange(...) | 创建矩形区域 |
| 4 | DestroyArea(...) | 销毁区域 |
| 5 | GetAreaCenter(...) | 获取区域中间点 |
| 6 | GetAreaRectLength(...) | 获取区域各边长 |
| 7 | GetAreaRectRange(...) | 获取区域范围 |
| 8 | GetRandomPos(...) | 随机区域内位置 |
| 9 | ObjInArea(...) | 检测对象是否在区域内 |
| 10 | BlockInArea(...) | 检测区域内是否有某个方块 |
| 11 | PosInArea(...) | 位置是否在区域内 |
| 12 | GetAreaPlayers(...) | 获取区域中的所有玩家 |
| 13 | GetAreaCreatures(...) | 获取区域中的所有生物 |
| 14 | ClearAllBlock(...) | 清空区域内全部方块 |
| 15 | CloneAreaBlock(...) | 复制区域内方块到另一个区域 |
| 16 | ReplaceAreaBlock(...) | 替换方块类型为新的方块类型 |
| 17 | GetAllObjsInAreaRange(...) | 获取区域范围内全部对象 |
| 18 | GetAllPlayersInAreaRange(...) | 获取区域范围内全部玩家 |
| 19 | GetAllCreaturesInAreaRange(...) | 获取区域范围内全部生物 |
| 20 | FillBlockAreaRange(...) | 用方块填充区域范围 |
| 21 | ClearAllBlockAreaRange(...) | 清空区域范围内方块 |
| 22 | DestroyAllBlock(...) | 破坏区域内的方块 |
| 23 | CloneAreaRange(...) | 复制区域范围内方块到另一个区域 |
| 24 | ReplaceAreaRangeBlock(...) | 替换区域范围方块 |
| 25 | GetRandomAirPos(...) | 获取一个区域内随机空气方块 |
| 26 | GetAreaBlockTypes(...) | 获取区域内的方块类型 |
| 27 | GetBlockNum(...) | 获取区域内的方块数量 |
| 28 | CheckRangeCanPlace(...) | 检查指定范围内是否可以放置方块 |
| 29 | GetRelativeActors(...) | 获取区域中指定玩家关系的角色 |
CreateAreaPrefab
- 参数及类型:
- 返回值及类型:
- 该方法的其他说明: 创建区域预制体对象,设置区域大小和位置,返回区域对象和对象ID
- 具体使用案例如下:
lua
-- 在玩家位置下方上创建一个20*20*20 尺寸的区域对象, 玩家在整个区域包围盒底面正中心
local area = Area:CreateAreaPrefab({x = x, y = y, z = z}, {x = 21, y = 21, z = 21}, WorldId)
--区域对象也是对象,可以挂载组件等
if area then
local areaId = area:GetId() -- 获取区域对象的id
-- area:AddComponent("组件id")
end
local startPos, endPos = Area:GetAreaRectRange(area:GetId())GetAreaUuidByObjId
lua
local id = Area:GetAreaUuidByObjId(objId)CreateAreaRectByRange
- 参数及类型:
- 返回值及类型:
- id:
number区域ID
- id:
- 该方法的其他说明: 根据起始和结束坐标创建矩形区域,通过范围定义区域边界
- 具体使用案例如下:
lua
-- 以玩家为底面中心位置 创建一个矩形区域,指定起始点和终点
local startPos = {x = x - 10, y = y , z = z - 10}
local endPos = {x = x + 10, y = y + 20, z = z + 10}
local areaId = Area:CreateAreaRectByRange(startPos, endPos, false, WorldId)DestroyArea
lua
-- 销毁区域
local result = Area:DestroyArea(areaId)GetAreaCenter
lua
-- 获取区域中心点
local centerPos = Area:GetAreaCenter(areaId)GetAreaRectLength
- 参数及类型:
- areaid:
number区域ID
- areaid:
- 返回值及类型:
- 该方法的其他说明: 获取指定区域在三个轴向上的长度尺寸
- 具体使用案例如下:
lua
-- 获取矩形区域的长度
local lengthX, lengthY, lengthZ = Area:GetAreaRectLength(areaId)GetAreaRectRange
- 参数及类型:
- areaid:
number区域ID
- areaid:
- 返回值及类型:
- 该方法的其他说明: 获取指定区域的边界范围,返回起始坐标、结束坐标和所在星球ID
- 具体使用案例如下:
lua
-- 获取矩形区域的范围
local startPos, endPos = Area:GetAreaRectRange(areaId)GetRandomPos
lua
-- 获取区域内随机位置
local pos = Area:GetRandomPos(areaId)ObjInArea
- 参数及类型:
- 返回值及类型:
- bool:
boolean是否在区域内
- bool:
- 该方法的其他说明: 检测指定对象是否位于指定区域内
- 具体使用案例如下:
lua
-- 检查对象是否在区域内
local result = Area:ObjInArea(areaId, Player:GetHostUin())BlockInArea
- 参数及类型:
- areaid:
number区域ID - blockid:number,string方块类型ID
- areaid:
- 返回值及类型:
- bool:
boolean是否在区域内
- bool:
- 该方法的其他说明: 检测指定区域内是否存在指定类型的方块
- 具体使用案例如下:
lua
-- 检查指定位置的方块是否在区域内
local isInArea = Area:BlockInArea(areaId, 200)PosInArea
- 参数及类型:
- 返回值及类型:
- bool:
boolean是否在区域内
- bool:
- 该方法的其他说明: 检测指定位置坐标是否位于指定区域内
- 具体使用案例如下:
lua
-- 检查位置是否在区域内
local result = Area:PosInArea(areaId, {x = x, y = y, z = z}, WorldId)GetAreaPlayers
lua
-- 获取区域内所有玩家
local players = Area:GetAreaPlayers(areaId)GetAreaCreatures
- 参数及类型:
- areaid:
number区域唯一ID
- areaid:
- 返回值及类型:
- objids:
table生物ID组
- objids:
- 该方法的其他说明: 获取指定区域内的所有生物对象ID列表,注意当帧创建的生物无法获取
- 具体使用案例如下:
lua
-- 获取区域内的所有生物
local creatures = Area:GetAreaCreatures(areaId)ClearAllBlock
- 参数及类型:
- 返回值及类型:
- bool:
boolean是否成功
- bool:
- 该方法的其他说明: 清空指定区域内的所有方块,可指定方块类型和最大清除数量,支持触发事件
- 具体使用案例如下:
lua
-- 清除区域内的所有201方块
local result = Area:ClearAllBlock(areaId, 201)CloneAreaBlock
- 参数及类型:
- 返回值及类型:
- bool:
boolean是否成功
- bool:
- 该方法的其他说明: 将指定区域内的方块复制到目标位置的另一个区域
- 具体使用案例如下:
lua
-- 克隆区域内的方块
local isSuccess = Area:CloneAreaBlock(areaId, {x = x + 10, y = y, z = z - 10})ReplaceAreaBlock
- 参数及类型:
- 返回值及类型:
- bool:
boolean是否成功
- bool:
- 该方法的其他说明: 将区域内指定类型的方块替换为新的方块类型,支持设置朝向和颜色
- 具体使用案例如下:
lua
-- 替换区域内的方块, 200 替换为 203
local result = Area:ReplaceAreaBlock(areaId, 200, 203) -- 将方块ID为1的替换为2GetAllObjsInAreaRange
- 参数及类型:
- 返回值及类型:
- objids:
table对象ID组
- objids:
- 该方法的其他说明: 获取指定位置范围内指定类型的所有对象ID列表
- 具体使用案例如下:
lua
-- 获取区域中的全部玩家
local posBeg, posEnd = Area:GetAreaRectRange(areaId)
local objects = Area:GetAllObjsInAreaRange(posBeg, posEnd, ObjType.Player, WorldId)GetAllPlayersInAreaRange
- 参数及类型:
- 返回值及类型:
- objids:
table对象ID组
- objids:
- 该方法的其他说明: 获取指定位置范围内的所有玩家对象ID列表
- 具体使用案例如下:
lua
local posBeg, posEnd = Area:GetAreaRectRange(areaId)
local players = Area:GetAllPlayersInAreaRange(posBeg, posEnd, WorldId)GetAllCreaturesInAreaRange
- 参数及类型:
- 返回值及类型:
- objids:
table对象ID组
- objids:
- 该方法的其他说明: 获取指定位置范围内的所有生物对象ID列表
- 具体使用案例如下:
lua
local posBeg, posEnd = Area:GetAreaRectRange(areaId)
local creatures = Area:GetAllCreaturesInAreaRange(posBeg, posEnd, WorldId)FillBlockAreaRange
- 参数及类型:
- 返回值及类型:
- bool:
boolean是否成功
- bool:
- 该方法的其他说明: 用指定方块填充位置范围,支持设置朝向、颜色和填充类型,分帧处理当前帧无法操作填充的方块
- 具体使用案例如下:
lua
local startPos = {x = x + 5, y = y, z = z}
local endPos = {x = x + 6, y = y + 2, z = z + 1}
-- 填充区域内的方块
local result = Area:FillBlockAreaRange(startPos, endPos, 105, nil, nil, nil,nil, WorldId)ClearAllBlockAreaRange
- 参数及类型:
- 返回值及类型:
- bool:
boolean是否成功
- bool:
- 该方法的其他说明: 清空指定位置范围内的方块,可指定方块类型和是否触发事件
- 具体使用案例如下:
lua
local posBeg, posEnd = Area:GetAreaRectRange(areaId)
local result = Area:ClearAllBlockAreaRange(posBeg, posEnd, 205, nil, WorldId)DestroyAllBlock
- 参数及类型:
- 返回值及类型:
- bool:
boolean操作是否成功
- bool:
- 该方法的其他说明: 破坏指定区域内的方块,可指定方块类型、销毁数量、是否掉落物品和是否触发事件
- 具体使用案例如下:
lua
-- 销毁区域内的所有105方块
local result = Area:DestroyAllBlock(areaId, 105)CloneAreaRange
- 参数及类型:
- 返回值及类型:
- bool:
boolean操作是否成功
- bool:
- 该方法的其他说明: 将指定位置范围内的方块复制到目标位置的另一个区域,支持指定操作类型
- 具体使用案例如下:
lua
local stPos = {x = x - 10, y = y, z = z - 10}
local ePos = {x = x + 10, y = y + 10, z = z + 10}
-- 克隆区域范围
local isSuccess = Area:CloneAreaRange(stPos, ePos, {x = x + 10, y = y, z = z - 10}, nil, WorldId)ReplaceAreaRangeBlock
- 参数及类型:
- 返回值及类型:
- bool:
boolean操作是否成功
- bool:
- 该方法的其他说明: 将指定位置范围内的源方块类型替换为目标方块类型,支持设置朝向和是否包括空气方块
- 具体使用案例如下:
lua
-- 替换区域范围内的方块
local posBeg, posEnd = Area:GetAreaRectRange(areaId)
local result = Area:ReplaceAreaRangeBlock(posBeg, posEnd, 202, 205, nil, nil, WorldId)GetRandomAirPos
- 参数及类型:
- 返回值及类型:
- pos:
table随机空气位置(x,y,z)
- pos:
- 该方法的其他说明: 在指定位置范围内随机获取一个空气方块的坐标位置
- 具体使用案例如下:
lua
-- 获取区域内随机空气位置
local posBeg, posEnd = Area:GetAreaRectRange(areaId)
local pos = Area:GetRandomAirPos(posBeg, posEnd, WorldId)GetAreaBlockTypes
lua
-- 获取区域内所有方块类型
local blockTypes = Area:GetAreaBlockTypes(areaId)GetBlockNum
- 参数及类型:
- areaid:
number区域ID - blockid:string,number方块ID
- areaid:
- 返回值及类型:
- num:
number方块数量
- num:
- 该方法的其他说明: 统计指定区域内指定类型方块的数量
- 具体使用案例如下:
lua
-- 获取区域内方块数量
local blockNum = Area:GetBlockNum(areaId, 202)CheckRangeCanPlace
- 参数及类型:
- 返回值及类型:
- bool:
boolean是否可以放置方块
- bool:
- 该方法的其他说明: 检查指定位置范围内是否可以放置指定类型的方块
- 具体使用案例如下:
lua
local startPos = {x = x + 5, y = y, z = z}
local endPos = {x = x + 6, y = y + 2, z = z + 1}
-- 检查范围是否可以放置
local result = Area:CheckRangeCanPlace(startPos, endPos, 105, WorldId)GetRelativeActors
- 参数及类型:
- 返回值及类型:
- 该方法的其他说明: 获取指定位置范围内与指定玩家具有特定关系的角色对象,返回数量和ID列表
- 具体使用案例如下:
lua
local posBeg, posEnd = Area:GetAreaRectRange(areaId)
local num, objs = Area:GetRelativeActors(posBeg, posEnd, Player:GetHostUin(), RelativeCampType.Friendly, ObjType.Mob, WorldId)