调用方式
addon.Platform:GetUnitPresenceObservation(unit)
可直接通过 addon 使用,无需依赖项。
作用
在已识别的客户端系列上观测单位的存在性。将所选单位原样传给一次受保护的 UnitExists 调用。保留可读的 true 和 false;所需观测缺失、失败、受限、为 nil 或格式错误时返回 nil 及原因。不会添加身份、可见性、距离或战斗状态的查询。
参数
| 名称 | 类型 | 作用 |
|---|---|---|
self | RMPlatform | Rotation Master 平台适配器(使用冒号调用时隐含传入)。 |
unit | string | 可读的非空单位标识,作为单个原生参数原样传递。 |
返回值
| 1 | boolean | nil | 已知的单位存在或不存在;所需观测不可用时为 nil。 |
|---|---|---|
| 2 | string | nil | 结果为 nil 时的客户端系列、查询验证或所需观测的可用性原因。 |
版本
内置辅助函数在每个版本上都会注册。不同的是它们读取的游戏 API;某个 API 缺失时,辅助函数会改用后备方案,或返回 nil 并附上原因。
- 该版本不可用(原因见提示)
- 仅在暴雪的弃用兼容层开启时
| 游戏 API | |||||
|---|---|---|---|---|---|
UnitExists |
秘密值(正式服和永久服)
在正式服和永久服上,游戏交给插件的是秘密值。此辅助函数会检查它读取的内容(addon.Platform:CanReadValue),遇到无法比较的秘密值时返回 nil 并附上原因(例如 restricted-value),而不是返回该秘密值。请将 nil 视为不可用,而不是假。
示例
local present = addon.Platform:GetUnitPresenceObservation("focus")
if present == nil then return nil end
return not present源码
Platform/unit_presence.lua,第 65 行。在游戏中为只读;“复制”会生成一份可编辑的副本。
Platform.unit_presence.GetUnitPresenceObservation(self, unit)
if not self:CanReadValue(unit) then return nil,'restricted-value' end
if type(unit)~='string' or unit=='' then return nil,'invalid-unit' end
if self:GetClientFamily()=='unknown' then return nil,'unsupported-client' end
if type(UnitExists)~='function' then return nil,'missing-api' end
local ok,exists=pcall(UnitExists,unit)
if not ok then return nil,'api-error' end
if not self:CanReadValue(exists) then return nil,'restricted-value' end
if exists==nil then return nil,'unit-data-unavailable' end
if type(exists)~='boolean' then return nil,'invalid-api-result' end
return exists




