ViewSystem.lua 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. local ViewSystem = class("ViewSystem")
  2. local Object = UnityEngine.Object
  3. local GameObject = UnityEngine.GameObject
  4. local UnityEngineUtils = UnityEngine.UnityEngineUtils
  5. local CfgMgr = ManagerContainer.CfgMgr
  6. local function CalcQiyuePoses(count, radius)
  7. if count == 1 then
  8. return {{radius, 0, 0}}
  9. elseif count == 2 then
  10. return {{radius, 0, 0}, {-radius, 0, 0}}
  11. elseif count == 3 then
  12. return {{radius, 0, 0}, {-radius/1.414, 0, radius/1.414}, {-radius/1.414, 0, -radius/1.414}}
  13. elseif count == 4 then
  14. return {{radius, 0, 0}, {0, 0, radius}, {-radius, 0, 0}, {0, 0, -radius}}
  15. end
  16. end
  17. function ViewSystem:ctor()
  18. self.extGoesMap = {}
  19. end
  20. function ViewSystem:Dispose()
  21. self:Clear()
  22. self.extGoesMap = nil
  23. self.qiyueOffset = nil
  24. end
  25. function ViewSystem:Clear()
  26. for heroExtGoesShow,data in pairs(self.extGoesMap) do
  27. if heroExtGoesShow == Enum.HeroExtGoesShowType.God_Art then
  28. local go = data.prefabGo
  29. if go then
  30. go:DestroyComponent(typeof(AroundSphereMove))
  31. end
  32. ManagerContainer.ResMgr:RecycleGO(Constants.ModelPath, data.prefabPath, data.prefabGo)
  33. elseif heroExtGoesShow == Enum.HeroExtGoesShowType.Pet_Qiyue then
  34. local datas = self.extGoesMap[heroExtGoesShow]
  35. for i = 1, #datas do
  36. local go = datas[i].prefabGo
  37. if go then
  38. local qiyuePoint = go.transform:Find("Qiyue_Point/Qiyue_Point1")
  39. if not tolua.isnull(qiyuePoint) then
  40. qiyuePoint.gameObject:DestroyComponent(typeof(AroundSphereMove))
  41. end
  42. end
  43. ManagerContainer.ResMgr:RecycleGO(Constants.EffectPath, datas[i].prefabPath, datas[i].prefabGo)
  44. end
  45. else
  46. ManagerContainer.ResMgr:RecycleGO(Constants.ModelPath, data.prefabPath, data.prefabGo)
  47. end
  48. end
  49. end
  50. function ViewSystem:UpdateGodArt(heroExtGoesShow, parent, oldShowData, cfgId)
  51. local oldCfgId = oldShowData[heroExtGoesShow]
  52. if oldCfgId ~= cfgId then
  53. if self.extGoesMap[heroExtGoesShow] then
  54. local data = self.extGoesMap[heroExtGoesShow]
  55. local go = data.prefabGo
  56. if go then
  57. go:DestroyComponent(typeof(AroundSphereMove))
  58. end
  59. ManagerContainer.ResMgr:RecycleGO(Constants.ModelPath, data.prefabPath, data.prefabGo)
  60. self.extGoesMap[heroExtGoesShow] = nil
  61. end
  62. else
  63. return
  64. end
  65. local cfgData = CfgMgr:GetArtifactCfgDataByCfgId(cfgId)
  66. if cfgData then
  67. local avatarPrefab = cfgData.AvatarPrefab
  68. if avatarPrefab and avatarPrefab ~= '' then
  69. local godArtGo = ManagerContainer.ResMgr:GetGoFromPool(Constants.ModelPath, avatarPrefab)
  70. if not tolua.isnull(parent) and not tolua.isnull(godArtGo) then
  71. local point = UnityEngineUtils.RecurisiveFindTransformChild(parent, "Bip001 Spine")
  72. if not tolua.isnull(point) then
  73. local around = godArtGo:GetComponent(typeof(AroundSphereMove))
  74. if not around then
  75. around = godArtGo:AddComponent(typeof(AroundSphereMove))
  76. end
  77. around.moveRadius = tonumber(cfgData.MoveRadius) or 0.5
  78. around.moveAngleSpeed = tonumber(cfgData.MoveAngleSpeed) or 3
  79. around.shakeDir = cfgData.ShakeDir and Vector3(cfgData.ShakeDir[1], cfgData.ShakeDir[2], cfgData.ShakeDir[3]) or Vector3(0,0,1)
  80. around.shakeSpeed = tonumber(cfgData.ShakeSpeed) or 1
  81. around.selfRotateSpeed = tonumber(cfgData.SelfRotateSpeed) or 2
  82. around.OffsetAngle = CommonUtil.TableToQuaternion(cfgData.OffsetAngle)
  83. around.Scale = tonumber(cfgData.Scale) or 1
  84. around.OffsetHeight = tonumber(cfgData.OffsetHeight) or 0
  85. godArtGo.transform:SetParent(point)
  86. godArtGo.transform.localPosition = Vector3.zero
  87. godArtGo.transform.localScale = Vector3.one
  88. self.extGoesMap[heroExtGoesShow] = {prefabGo = godArtGo, prefabPath = avatarPrefab}
  89. end
  90. end
  91. end
  92. end
  93. oldShowData[heroExtGoesShow] = cfgId
  94. end
  95. function ViewSystem:UpdateStrengthHalo(heroExtGoesShow, parent, oldShowData, val)
  96. local oldVal = oldShowData[heroExtGoesShow]
  97. if oldVal ~= val then
  98. if self.extGoesMap[heroExtGoesShow] then
  99. local data = self.extGoesMap[heroExtGoesShow]
  100. ManagerContainer.ResMgr:RecycleGO(Constants.EffectPath, data.prefabPath, data.prefabGo)
  101. self.extGoesMap[heroExtGoesShow] = nil
  102. end
  103. else
  104. return
  105. end
  106. local lv = val
  107. if val >= #Constant.PartnerStrengthEffectPath then
  108. lv = #Constant.PartnerStrengthEffectPath
  109. end
  110. local effectName = Constant.PartnerStrengthEffectPath[lv]
  111. local effect = ManagerContainer.ResMgr:GetGoFromPool(Constants.EffectPath, effectName)
  112. if not tolua.isnull(parent) and not tolua.isnull(effect) then
  113. local point = parent:Find("Foot_Point")
  114. if not tolua.isnull(point) then
  115. effect.transform:SetParent(point)
  116. effect.transform.localPosition = Vector3.zero
  117. effect.transform.localScale = Vector3.one
  118. self.extGoesMap[heroExtGoesShow] = {prefabGo = effect, prefabPath = effectName}
  119. end
  120. end
  121. oldShowData[heroExtGoesShow] = val
  122. end
  123. function ViewSystem:UpdatePetQiyueShow(heroExtGoesShow, parent, oldShowData, val)
  124. local oldVal = oldShowData[heroExtGoesShow]
  125. if oldVal then
  126. if oldVal.sumNum ~= val.sumNum then
  127. if self.extGoesMap[heroExtGoesShow] then
  128. local datas = self.extGoesMap[heroExtGoesShow]
  129. for i = 1, #datas do
  130. ManagerContainer.ResMgr:RecycleGO(Constants.EffectPath, datas[i].prefabPath, datas[i].prefabGo)
  131. end
  132. self.extGoesMap[heroExtGoesShow] = nil
  133. end
  134. else
  135. return
  136. end
  137. end
  138. local cfgData = CfgMgr:GetPetDataById(val.battlePetId)
  139. if cfgData and val.cfgIds and #val.cfgIds > 0 then
  140. local radius = 1
  141. self.qiyueOffset = CalcQiyuePoses(val.count, radius)
  142. self.extGoesMap[heroExtGoesShow] = {}
  143. local offsetPos = cfgData.OffsetPos and Vector3(cfgData.OffsetPos[1], cfgData.OffsetPos[2], cfgData.OffsetPos[2]) or Vector3.zero
  144. local qiyuePoint1
  145. if val.count > 0 then
  146. if not tolua.isnull(parent) then
  147. local qiyuePoint = parent:Find("Qiyue_Point")
  148. if tolua.isnull(qiyuePoint) then
  149. qiyuePoint = GameObject("Qiyue_Point")
  150. qiyuePoint.transform:SetParent(parent)
  151. qiyuePoint.transform.localScale = Vector3.one
  152. qiyuePoint = qiyuePoint.transform
  153. end
  154. qiyuePoint.localPosition = cfgData.OffsetPos and Vector3(cfgData.OffsetPos[1], cfgData.OffsetPos[2], cfgData.OffsetPos[3]) or Vector3.zero
  155. qiyuePoint1 = qiyuePoint:Find("Qiyue_Point1")
  156. if tolua.isnull(qiyuePoint1) then
  157. qiyuePoint1 = GameObject("Qiyue_Point1")
  158. qiyuePoint1.transform:SetParent(qiyuePoint)
  159. qiyuePoint1.transform.localScale = Vector3.one
  160. qiyuePoint1.transform.localPosition = Vector3.zero
  161. qiyuePoint1 = qiyuePoint1.transform
  162. end
  163. local around = qiyuePoint1.gameObject:GetComponent(typeof(AroundSphereMove))
  164. if not around then
  165. around = qiyuePoint1.gameObject:AddComponent(typeof(AroundSphereMove))
  166. end
  167. around.moveRadius = 0
  168. around.moveAngleSpeed = 0
  169. around.shakeDir = Vector3.zero
  170. around.shakeSpeed = 0
  171. around.selfRotateSpeed = tonumber(cfgData.SelfRotateSpeed) or 2
  172. around.Scale = tonumber(cfgData.Scale) or 1
  173. around.OffsetHeight = 0
  174. end
  175. end
  176. for i = 1, #val.cfgIds do
  177. local cfgId = val.cfgIds[i]
  178. local petCfgData = CfgMgr:GetPetDataById(cfgId)
  179. if petCfgData then
  180. local natureData = CfgMgr:GetNatureDataById(petCfgData.NatureType)
  181. if natureData then
  182. local avatarPrefab = natureData.PetContract
  183. if avatarPrefab and avatarPrefab ~= '' then
  184. local qiyueGo = ManagerContainer.ResMgr:GetGoFromPool(Constants.EffectPath, avatarPrefab)
  185. if not tolua.isnull(qiyuePoint1) and not tolua.isnull(qiyueGo) then
  186. qiyueGo.transform:SetParent(qiyuePoint1)
  187. if self.qiyueOffset and self.qiyueOffset[i] then
  188. qiyueGo.transform.localPosition = Vector3(self.qiyueOffset[i][1], self.qiyueOffset[i][2], self.qiyueOffset[i][3])
  189. else
  190. qiyueGo.transform.localPosition = Vector3.zero
  191. end
  192. qiyueGo.transform.localScale = Vector3.one
  193. self.extGoesMap[heroExtGoesShow][#self.extGoesMap[heroExtGoesShow] + 1] = {prefabGo = qiyueGo, prefabPath = avatarPrefab}
  194. end
  195. end
  196. end
  197. end
  198. end
  199. end
  200. oldShowData[heroExtGoesShow] = val
  201. end
  202. function ViewSystem:UpdateView(parent, oldShowData, updateView)
  203. if updateView then
  204. for heroExtGoesShow,val in pairs(updateView) do
  205. if val then
  206. if heroExtGoesShow == Enum.HeroExtGoesShowType.God_Art then
  207. self:UpdateGodArt(heroExtGoesShow, parent, oldShowData, val)
  208. elseif heroExtGoesShow == Enum.HeroExtGoesShowType.Strength_Halo then
  209. if val < 100 then
  210. self:UpdateStrengthHalo(heroExtGoesShow, parent, oldShowData, val)
  211. end
  212. elseif heroExtGoesShow == Enum.HeroExtGoesShowType.Pet_Qiyue then
  213. self:UpdatePetQiyueShow(heroExtGoesShow, parent, oldShowData, val)
  214. end
  215. end
  216. end
  217. end
  218. end
  219. return ViewSystem