2025-07-18 17:59:24 +08:00
|
|
|
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
|
|
|
|
|
|
2025-09-08 14:39:21 +08:00
|
|
|
function MissileSender.Send(url, send, target, root, animUrl, Missile, num, time)
|
|
|
|
|
local sendPos = send._view.xy --Vector2.New(send.x + send.width/2, send.y + send.height/2)
|
|
|
|
|
local targetPos = target._view.xy --Vector2.New(target.x + target.width/2, target.y + target.height/2)
|
2025-07-18 17:59:24 +08:00
|
|
|
|
2025-09-08 14:39:21 +08:00
|
|
|
local clipFather = target._view:GetChild('comp_hudon')
|
2025-07-18 17:59:24 +08:00
|
|
|
for i = 1, num do
|
|
|
|
|
local obj = GetObj()
|
|
|
|
|
obj:GetChild("loader").url = url
|
2025-09-08 14:39:21 +08:00
|
|
|
root._view:AddChild(obj)
|
|
|
|
|
obj.width = send._view.width
|
|
|
|
|
obj.height = send._view.height
|
2025-07-18 17:59:24 +08:00
|
|
|
obj.xy = sendPos
|
|
|
|
|
|
|
|
|
|
-- 间隔
|
|
|
|
|
obj:TweenMove(obj.xy, i * 0.1):OnComplete(function()
|
|
|
|
|
obj:TweenMove(targetPos, time):OnComplete(function()
|
|
|
|
|
BackObj(obj)
|
2025-09-08 14:39:21 +08:00
|
|
|
--动画击中头像后播放击中的音效和动画
|
|
|
|
|
root:PlayMJSound(string.format("%s.mp3", Missile))
|
|
|
|
|
local clip = UIPackage.CreateObjectFromURL(string.format("ui://Main_Majiang/%s", Missile))
|
|
|
|
|
clip:SetSize(clipFather.width, clipFather.height)
|
|
|
|
|
clipFather:AddChild(clip)
|
|
|
|
|
clip:SetPlaySettings(0, -1, 1, -1)
|
|
|
|
|
clip.onPlayEnd:Add(function()
|
|
|
|
|
if clip.parent then
|
|
|
|
|
clip.parent:RemoveChild(clip)
|
|
|
|
|
end
|
|
|
|
|
clip:Dispose()
|
|
|
|
|
end)
|
|
|
|
|
clip.playing = true
|
2025-07-18 17:59:24 +08:00
|
|
|
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
|