87 lines
2.0 KiB
Lua
87 lines
2.0 KiB
Lua
local MissileSender = {}
|
|
local pool = {}
|
|
local curView = {}
|
|
local MovieClipPool = {}
|
|
|
|
local function GetObj()
|
|
if #pool > 0 then
|
|
local re = pool[#pool]
|
|
re.visible = true
|
|
pool[#pool] = nil
|
|
return re
|
|
end
|
|
|
|
return UIPackage.CreateObjectFromURL("ui://Main_Majiang/Missile")
|
|
end
|
|
|
|
local function BackObj(obj)
|
|
pool[#pool + 1] = obj
|
|
obj.visible = false
|
|
end
|
|
|
|
local function GetMovieClip(url)
|
|
local _pool = MovieClipPool[url]
|
|
|
|
if _pool and #_pool > 0 then
|
|
local re = _pool[#_pool]
|
|
re.visible = true
|
|
_pool[#_pool] = nil
|
|
return re
|
|
end
|
|
|
|
return UIPackage.CreateObjectFromURL(url)
|
|
end
|
|
|
|
local function BackMovieClip(obj, url)
|
|
if MovieClipPool[url] == nil then
|
|
MovieClipPool[url] = {}
|
|
end
|
|
|
|
local _pool = MovieClipPool[url]
|
|
_pool[#_pool + 1] = obj
|
|
obj.visible = false
|
|
end
|
|
|
|
function MissileSender.Send(url, send, target, view, animUrl, num, time)
|
|
if curView ~= view then
|
|
pool = {}
|
|
end
|
|
|
|
curView = view
|
|
|
|
local sendPos = send.xy--Vector2.New(send.x + send.width/2, send.y + send.height/2)
|
|
local targetPos = target.xy--Vector2.New(target.x + target.width/2, target.y + target.height/2)
|
|
|
|
for i = 1, num do
|
|
local obj = GetObj()
|
|
obj:GetChild("loader").url = url
|
|
view:AddChild(obj)
|
|
obj.xy = sendPos
|
|
|
|
-- 间隔
|
|
obj:TweenMove(obj.xy, i * 0.1):OnComplete(function()
|
|
obj:TweenMove(targetPos, time):OnComplete(function()
|
|
BackObj(obj)
|
|
if i == num then
|
|
MissileSender.Animation(target, animUrl, view)
|
|
end
|
|
end)
|
|
end)
|
|
end
|
|
end
|
|
|
|
function MissileSender.Animation(target, animUrl, view)
|
|
local e = GetMovieClip(animUrl)
|
|
e:SetPlaySettings(1, -1, 1, -1)
|
|
e.onPlayEnd:Set(function()
|
|
e.visible = false
|
|
BackMovieClip(e, animUrl)
|
|
end)
|
|
view:AddChild(e)
|
|
e.width = target.width
|
|
e.height = target.height
|
|
e.xy = target.xy
|
|
end
|
|
|
|
return MissileSender
|