UIPOPGotAnimsView.lua 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. local UIPOPGotAnimsView = require("UIPOPGot/UIPOPGotAnimsView_Generate")
  2. --local UIMainCtr = require("UIMain/UIMainCtr")
  3. local UIMainCtr = ManagerContainer.LuaUIMgr:GetViewCtrById(Enum.UIPageName.UIMain)
  4. local timer
  5. local durationTime = 0.6
  6. local rotation = 60
  7. local offset = 1.3
  8. local rangeCount = {{1, 100, 2}, {101, 1000, 5}, {1001, -1, 10}}
  9. local maxCount = 10
  10. local curCount = 0
  11. local enterType
  12. --随机角度区间
  13. local rotationRange = {-60,60}
  14. --随机弧线距离
  15. local offsetRange = {0.8, 1.5}
  16. --产生间隔时间
  17. local interTime = 0.1
  18. local taskIngList = {}
  19. function UIPOPGotAnimsView:OnAwake(data)
  20. self.controller = require("UIPOPGot/UIPOPGotAnimsCtr"):new()
  21. self.controller:Init(self)
  22. self.controller:SetData(data)
  23. end
  24. function UIPOPGotAnimsView:AddEventListener()
  25. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.GOT_ITEM_ANIM, function(data)
  26. self.controller:SetData(data)
  27. self:Init()
  28. end)
  29. end
  30. function UIPOPGotAnimsView:FillContent(data, uiBase)
  31. self.uiBase = uiBase
  32. local gameObject = self.uiBase:GetRoot()
  33. if gameObject ~= nil then
  34. self.gameObject = gameObject
  35. self.transform = gameObject.transform
  36. end
  37. self:InitGenerate(self.transform, data)
  38. self:Init()
  39. end
  40. function UIPOPGotAnimsView:Init()
  41. local val = GlobalConfig.Instance:GetConfigStrValue(144)
  42. if val ~= "" and val ~= nil then
  43. rangeCount = CommonUtil.DeserializeGlobalStrToTable(val)
  44. end
  45. local data = self.controller:GetData()
  46. local list = data.list
  47. local startPoses = data.startPoses
  48. local endPoses = data.endPoses
  49. local needOffset = data.needOffset or false
  50. enterType = data.enterType
  51. curCount = 0
  52. maxCount = 0
  53. for i = 1, #startPoses do
  54. local endPos
  55. if endPoses ~= nil then
  56. endPos = endPoses[i]
  57. end
  58. self:AddGotAnim(list[i], startPoses[i], endPos, needOffset)
  59. end
  60. end
  61. function UIPOPGotAnimsView:AddGotAnim(data, startPos, endPos, needOffset)
  62. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(data.cfgId)
  63. if endPos == nil and UIMainCtr then
  64. endPos = UIMainCtr:GetGotAnimEndPosByType(itemCfgData.ResType)
  65. end
  66. if endPos == nil then
  67. LogError(data.cfgId.." item type error no endPos")
  68. return
  69. end
  70. local task = {type = itemCfgData.ResType}
  71. if (itemCfgData.ResType >= Enum.ItemType.Equip and itemCfgData.ResType <= Enum.ItemType.FashionPaper)
  72. or itemCfgData.ResType == Enum.ItemType.SkillBook
  73. or itemCfgData.ResType == Enum.ItemType.Gift
  74. or itemCfgData.ResType == Enum.ItemType.Income then
  75. ManagerContainer.GoPoolMgr:SpawnItemGo(itemCfgData.ResType, function(itemlua)
  76. CommonUtil.BatchCreateItems(self, itemlua, self.transform, data, Enum.ItemIEnterType.GotAnim)
  77. itemlua.transform.position = startPos
  78. itemlua.transform.localScale = Vector3.New(0.8,0.8,0.8)
  79. itemlua.qualityFX.gameObject:SetActive(false);
  80. local result = startPos.y > endPos.y and 1 or -1
  81. local oriVec = endPos - startPos
  82. local newVec = UnityEngine.Quaternion.AngleAxis(rotation*result, Vector3.forward) * oriVec
  83. local path = {}
  84. path[1] = startPos
  85. path[2] = startPos + (newVec.normalized * offset);
  86. path[3] = endPos;
  87. itemlua.transform:DOScale(0.3, durationTime):SetEase(DG.Tweening.Ease.InExpo):SetAutoKill()
  88. itemlua.transform:DOPath(path, durationTime, DG.Tweening.PathType.CatmullRom):SetEase(DG.Tweening.Ease.Linear):OnComplete(function ()
  89. self:RemoveCompeltedAnim(task)
  90. --ManagerContainer.GoPoolMgr:RecycleGo(itemlua)
  91. CommonUtil.RecycleFromBatchItems(self, itemlua)
  92. --CommonUtil.CloseUIClearAsyncSeqIds(self)
  93. end):SetAutoKill()
  94. end)
  95. elseif itemCfgData.ResType < Enum.ItemType.Equip
  96. or itemCfgData.ResType == Enum.ItemType.WalletNum then
  97. local count = 0
  98. if itemCfgData.Id ~= Enum.ItemIds.Box then
  99. for _,v in pairs(rangeCount) do
  100. if tonumber(v[2]) ~= -1 then
  101. if data.num >= tonumber(v[1]) then
  102. count = tonumber(v[3])
  103. end
  104. else
  105. if data.num >= tonumber(v[1]) and data.num <= tonumber(v[2]) then
  106. count = tonumber(v[3])
  107. end
  108. end
  109. end
  110. else
  111. count = data.num
  112. end
  113. maxCount = maxCount + count
  114. if count > 0 then
  115. timer = ManagerContainer.LuaTimerMgr:AddTimer(interTime, count, nil, function ()
  116. ManagerContainer.GoPoolMgr:SpawnGo(Enum.PrefabNames.GotCoinItem, function(itemlua)
  117. CommonUtil.BatchCreateItems(self, itemlua, self.transform, data, Enum.ItemIEnterType.GotAnim)
  118. local pos = startPos
  119. if needOffset then
  120. pos = self:GetCircleRandomPos(startPos, 0.5)
  121. end
  122. itemlua.transform.position = pos
  123. local rect = itemlua.gameObject:GetComponent(Enum.TypeInfo.RectTransform)
  124. rect.anchoredPosition3D = Vector3.New(rect.anchoredPosition3D.x, rect.anchoredPosition3D.y, 0)
  125. itemlua.basePar:SetActive(itemCfgData.ResType == Enum.ItemType.RoleBaseExp)
  126. itemlua.baseParCtr.uIParticle.cachedParticleSystem:Play(itemCfgData.ResType == Enum.ItemType.RoleBaseExp)
  127. itemlua.jobPar:SetActive(itemCfgData.ResType == Enum.ItemType.RoleJobExp)
  128. itemlua.jobParCtr.uIParticle.cachedParticleSystem:Play(itemCfgData.ResType == Enum.ItemType.RoleJobExp)
  129. local oriVec = endPos - pos
  130. local randomRotation = math.random(rotationRange[1], rotationRange[2])
  131. local randomOffset = math.random(offsetRange[1], offsetRange[2])
  132. local newVec = UnityEngine.Quaternion.AngleAxis(randomRotation, Vector3.forward) * oriVec
  133. itemlua.transform:DOShakePosition(0.1, Vector3.up * 100, 2):SetEase(DG.Tweening.Ease.EaseOutElastic):OnComplete(function ()
  134. --itemlua.transform:DOPunchPosition(Vector3.up*100, 0.1, 2, 2):SetEase(DG.Tweening.Ease.EaseOutElastic):OnComplete(function ()
  135. local path = {}
  136. path[1] = pos
  137. path[2] = pos + (newVec.normalized * randomOffset);
  138. path[3] = endPos;
  139. itemlua.transform:DOPath(path, durationTime, DG.Tweening.PathType.CatmullRom):SetEase(DG.Tweening.Ease.Linear):OnComplete(function ()
  140. CommonUtil.RecycleFromBatchItems(self, itemlua)
  141. --ManagerContainer.GoPoolMgr:RecycleGo(itemlua)
  142. curCount = curCount + 1
  143. if curCount == maxCount then
  144. self:RemoveCompeltedAnim(task)
  145. --CommonUtil.CloseUIClearAsyncSeqIds(self)
  146. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.GOT_ITEM_ANIM_END_NOTIFY, itemCfgData.ResType)
  147. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.GOT_ANIM_TYPE_END_NOTIFY, enterType)
  148. end
  149. end):SetAutoKill()
  150. end):SetAutoKill()
  151. end)
  152. end, nil)
  153. end
  154. end
  155. taskIngList[#taskIngList + 1] = task
  156. end
  157. function UIPOPGotAnimsView:GetCircleRandomPos(center, radius)
  158. local rad = radius * 10
  159. return center + Vector3.New(math.random(-rad, rad)*0.1, math.random(-rad, rad)*0.1, 0)
  160. end
  161. function UIPOPGotAnimsView:RemoveCompeltedAnim(task)
  162. for i = 1, #taskIngList do
  163. if task == taskIngList[i] then
  164. table.remove(taskIngList, i)
  165. return
  166. end
  167. end
  168. end
  169. function UIPOPGotAnimsView:IsInSameTypeAnim(type)
  170. for i = 1, #taskIngList do
  171. if taskIngList[i].type == type then
  172. return true
  173. end
  174. end
  175. return false
  176. end
  177. function UIPOPGotAnimsView:RemoveEventListener()
  178. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  179. end
  180. function UIPOPGotAnimsView:AddUIEventListener()
  181. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  182. end
  183. function UIPOPGotAnimsView:OnHide()
  184. end
  185. function UIPOPGotAnimsView:OnShow(data)
  186. self.controller:SetData(data)
  187. self:Init()
  188. end
  189. function UIPOPGotAnimsView:OnClose()
  190. end
  191. function UIPOPGotAnimsView:OnDispose()
  192. if timer then
  193. ManagerContainer.LuaTimerMgr:RemoveTimer(timer)
  194. timer = nil
  195. end
  196. end
  197. return UIPOPGotAnimsView