function FadeUnitVertexColor_Update takes nothing returns nothing
local timer t = GetExpiredTimer()
local real r = GetHandleReal(t, "r") + GetHandleReal(t, "dr")
local real g = GetHandleReal(t, "g") + GetHandleReal(t, "dg")
local real b = GetHandleReal(t, "b") + GetHandleReal(t, "db")
local real a = GetHandleReal(t, "a") + GetHandleReal(t, "da")
local integer step = GetHandleInt(t, "step") - 1
local unit u = GetHandleUnit(t, "u")
call SetUnitVertexColor(u, R2I(r*255), R2I(g*255), R2I(b*255), R2I(a*255))
if ( u == null or step <= 0 ) then
call FlushHandleLocals(t)
call PauseTimer(t)
call DestroyTimer(t)
call SetHandleHandle( u, "FadeUnitVertexColor_Timer", null )
set t = null
set u = null
return
endif
call SetHandleReal(t, "r", r)
call SetHandleReal(t, "g", g)
call SetHandleReal(t, "b", b)
call SetHandleReal(t, "a", a)
call SetHandleInt(t, "step", step)
set t = null
set u = null
endfunction
function FadeUnitVertexColor takes unit u, real r1, real g1, real b1, real a1, real r2, real g2, real b2, real a2, real time returns nothing
local timer t = GetHandleTimer( u, "FadeUnitVertexColor_Timer" )
local real update = 0.05
if ( time <= 0 ) then
call SetUnitVertexColor(u, R2I(r2*255), R2I(g2*255), R2I(b2*255), R2I(a2*255))
if ( t != null ) then
call PauseTimer( t )
call DestroyTimer( t )
call SetHandleHandle( u, "FadeUnitVertexColor_Timer", null )
set t = null
endif
return
endif
call SetUnitVertexColor(u, R2I(r1*255), R2I(g1*255), R2I(b1*255), R2I(a1*255))
if ( t == null ) then
set t = CreateTimer()
call SetHandleHandle( u, "FadeUnitVertexColor_Timer", t )
else
call PauseTimer( t )
endif
call SetHandleReal(t, "r", r1)
call SetHandleReal(t, "g", g1)
call SetHandleReal(t, "b", b1)
call SetHandleReal(t, "a", a1)
call SetHandleReal(t, "dr", update*(r2-r1)/time)
call SetHandleReal(t, "dg", update*(g2-g1)/time)
call SetHandleReal(t, "db", update*(b2-b1)/time)
call SetHandleReal(t, "da", update*(a2-a1)/time)
call SetHandleHandle(t, "u", u)
call SetHandleInt(t, "step", R2I(time/update + 0.99))
call TimerStart(t, update, true, function FadeUnitVertexColor_Update)
set t = null
endfunction