Just took a glance at your code. I noticed that you can easily optimize by reusing similar code.
For instance, create health and power bar code just once and insert it for each unit.
You could do this with using a "Shared" function, that contains code used for every unit and/or by creating single functions. Somewhat like this:
Code:
local createPower = function(self) -- Power bar
.......
end
and insert it into each unit that you want to have a power bar, like:
Code:
UnitSpecific.player = function(self, ...)
Shared(self, ...) -- only if you use a shared function, obviously
createPower(self)
end
You can also do this with textures, like borders, background and so on ... Basically if you reuse code at least once on another frame, it makes sense to do it this way.
€: Just to add to the confusion, let's say you create a "createPower" function; you don't want to put the SetPoint stuff in there. Unless every unit you use is exactly the same, ofc. Only put the CreateFrame, background, PostUpdate, color and stuff like that in there.
Set your Points for each unit, after you inserted the createPower(self) function.
like
Code:
UnitSpecific.player = function(self, ...)
createPower(self)
self.Power:SetPoint("BOTTOMLEFT", self, "BOTTOMLEFT", 38, 20)
createRaidIcon(self)
self.RaidIcon:SetPoint("TOPLEFT", self, "TOPLEFT", 4, 0)
end
UnitSpecific.target = function(self, ...)
createPower(self)
self.Power:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT", -38, 20)
createRaidIcon(self)
self.RaidIcon:SetPoint("TOPRIGHT", self, "TOPRIGHT", -4, 0)
end