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, 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) local clipFather = target._view:GetChild('comp_hudon') for i = 1, num do local obj = GetObj() obj:GetChild("loader").url = url root._view:AddChild(obj) obj.width = send._view.width obj.height = send._view.height obj.xy = sendPos -- 间隔 obj:TweenMove(obj.xy, i * 0.1):OnComplete(function() obj:TweenMove(targetPos, time):OnComplete(function() BackObj(obj) --动画击中头像后播放击中的音效和动画 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 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 function MissileSender.Clear() MissileSender = {} pool = {} curView = {} MovieClipPool = {} end return MissileSender