UpdateUnitMesh = function(self)
if self:CanChangeMesh() and not self:BeenDestroyed() then
if not self:GetUnitParam('FirstTimeMeshChangeDone') then
self:SetUnitParam('FirstTimeMeshChangeDone', true)
self:AddUnitThread('UpdateFirstUnitMeshChange',{})
else
local bpDisplay = self:GetBlueprintParam('Display')
local CurrentMesh = self:GetCurrentMesh()
local IntelMeshes = self:GetIntelMeshes()
local Intels = self:GetEnabledIntels()
local UnitMeshes = self:GetUnitMeshes()
local ChangeMesh = true
if table.getn(UnitMeshes) > 0 then
for id, Params in UnitMeshes do
local MeshIntelType = Params.inteltype
if Intels[MeshIntelType] then
local Mesh = Params.mesh
if Intels[MeshIntelType] then
local Mesh = Params.mesh
local KeepActor = Params.keepactor or true
local ClearStructureIntel = Params.clearstructureintel
if Mesh then
if bpDisplay[Mesh] then
if CurrentMesh != MeshIntelType then
self:SetMesh(bpDisplay[Mesh], KeepActor)
self:SetUnitParam('CurrentMesh', MeshIntelType)
if ClearStructureIntel then
self:ClearStructureUnitIntel()
self:SetUnitParam('ClearStructureIntel', true)
end
ChangeMesh = false
break
else
if CurrentMesh == MeshIntelType then
ChangeMesh = false
break
end
end
end
end
end
end
end
end
if table.getn(IntelMeshes) > 0 then
if ChangeMesh then
for id, Params in IntelMeshes do
local MeshIntelType = Params.inteltype
if Intels[MeshIntelType] then
local Mesh = Params.mesh
local KeepActor = Params.keepactor or true
local ClearStructureIntel = Params.clearstructureintel
if Mesh then
if bpDisplay[Mesh] then
if CurrentMesh != MeshIntelType then
self:SetMesh(bpDisplay[Mesh], KeepActor)
self:SetUnitParam('CurrentMesh', MeshIntelType)
if ClearStructureIntel then
self:ClearStructureUnitIntel()
self:SetUnitParam('ClearStructureIntel', true)
end
ChangeMesh = false
break
else
if CurrentMesh == MeshIntelType then
ChangeMesh = false
break
end
end
end
end
end
end
end
end
if ChangeMesh and CurrentMesh != 'MeshBlueprint' then
self:SetUnitParam('ClearStructureIntel', nil)
self:SetMesh(bpDisplay.MeshBlueprint, true)
self:SetUnitParam('CurrentMesh', 'MeshBlueprint')
end
end
end
end,