Now ignores NPCs and enemy players/pets, and won't error on partially-loaded units (eg. players in the process of joining your group). Let me know if you're actually seeing "UNKNOWN" on frames and, if so, under what circumstances.
Code:
local CUSTOM_PLAYER_TEXT = "谷歌"
local CUSTOM_PET_TEXT = "PET"
local function SetCustomName(unit, fontString)
if UnitIsUnit(unit, "player") then
fontString:SetText(CUSTOM_PLAYER_TEXT)
elseif UnitIsPlayer(unit) then
fontString:SetText(strupper(UnitClass(unit) or UNKNOWN))
else
fontString:SetText(CUSTOM_PET_TEXT)
end
end
hooksecurefunc("UnitFrame_Update", function(frame, isParty)
if frame.name then
local unit = frame.overrideName or frame.unit
if UnitPlayerControlled(unit) and UnitIsFriend(unit, "player") then
SetCustomName(unit, frame.name)
end
end
end)
hooksecurefunc("CompactUnitFrame_UpdateName", function(frame)
SetCustomName(frame.unit, frame.name)
end)
Added/changed parts highlighted in
green.