The simplest solution is probably going to be to hook the function that sets the text:
Code:
hooksecurefunc("UnitFrame_Update", function(self)
if not self.name then return end
if UnitIsPlayer(self.unit) then
-- Color by class:
local _, class = UnitClass(self.unit)
local color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
self.name:SetTextColor(color.r, color.g, color.b)
else
-- Not a player. Return to default color:
self.name:SetTextColor(1, 0.82, 0)
end
end)
Feel free to color non-players by reaction instead of using the default color.
If you wanted to color pets by their owner's class, the simplest solution would probably be to look at the pet's creature type and just make an assumption -- eg. beast = hunter, demon = warlock, etc.