KLUIModelItemPanel.lua 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. ---@class KLUIModelItemPanel:UIKmlLuaPanelBase
  2. ---@field view KLUIModelItemPanelView
  3. ---@field Model
  4. local KLUIModelItemTemplateItem = class(UIKmlLuaPanelBase)
  5. local this = KLUIModelItemTemplateItem
  6. ---创建时调用一次
  7. function this:Init()
  8. end
  9. ---注册UI事件和服务器消息
  10. function this:RegistEvents()
  11. GUI:AddOnClickEvent(self.view.DeleteBtn, self, self.DeleteBtnOnClick)
  12. GUI:AddOnClickEvent(self.view.ModelBtn, self, self.ShowDelete)
  13. end
  14. ---界面显示时调用一次
  15. function this:Show()
  16. end
  17. ---创建或者刷新界面数据时调用
  18. function this:Refresh()
  19. end
  20. function this:DeleteBtnOnClick()
  21. self.baseUI:DeleteRole(self.date.rid)
  22. end
  23. function this:ShowDelete()
  24. self.baseUI:ShowChoosePlayer(self)
  25. end
  26. function this:Close()
  27. self:Recycle()
  28. end
  29. function this:LoadEffect()
  30. local index = 52
  31. --if ConfigManager.Exsit_cfg_character_create(1) and ConfigManager.Get_cfg_character_create(1).effect ~= nil then
  32. -- index = ConfigManager.Get_cfg_character_create(1).effect
  33. --end
  34. if SL:GetConfig("cfg_character_create",1) and SL:GetConfig("cfg_character_create",1).effect ~=nil then
  35. index = SL:GetConfig("cfg_character_create",1).effect
  36. end
  37. local effect = SL:GetConfig("cfg_model_effect",index) ---ConfigManager.Get_cfg_model_effect(index)
  38. local scale = Vector3.one
  39. local rotation = Quaternion.Euler(0, 0, 0)
  40. if effect ~= nil then
  41. scale = Vector3.New(effect.scale * 0.0001, effect.scale * 0.0001, effect.scale * 0.0001)
  42. end
  43. local data = {
  44. id = index,
  45. pos = Vector3.New(0, 0.15, 0),
  46. parent = self.role.model.transform,
  47. scale = scale,
  48. selfRotate = false,
  49. tableName = "cfg_model_effect",
  50. rotation = rotation,
  51. isActive = false,
  52. isSynch = true,
  53. isActive = true,
  54. callback = this.SetSize,
  55. callbackData = self,
  56. effectObjPos = Vector3.New(0, 0, 0),
  57. isUI = false
  58. }
  59. self.Effect = SL.Constructor_In:UIEffect()
  60. self.Effect:Init(data)
  61. end
  62. function this:SetSize()
  63. self.Effect.modelObject.transform:GetComponent(typeof(CS.UnityEngine.ParticleSystemRenderer)).minParticleSize = 0.16
  64. self.Effect.modelObject.transform:Find("0/Circle"):GetComponent(typeof(CS.UnityEngine.ParticleSystemRenderer)).minParticleSize = 0.13
  65. end
  66. function this:CreateRole(count)
  67. ---@type MapProtos.RoundPlayerEx
  68. local t = {}
  69. t.id = UtilityLua.UUID
  70. t.career = self.date.career
  71. t.level = self.date.level
  72. t.name = self.date.name
  73. t.hp = 1
  74. t.x = 0
  75. t.y = 0
  76. t.pkValue = 0
  77. if self.date.roleInfoExt ~= nil then
  78. t.equip = self.date.roleInfoExt.equip
  79. t.appearIdx = self.date.roleInfoExt.equipShowIdx
  80. t.roleAppear = self.date.roleInfoExt.roleAppear
  81. t.shapeRing = self.date.roleInfoExt.shapeRing
  82. t.mountId = t.shapeRing == 0 and self.date.roleInfoExt.mountId or 0
  83. end
  84. t.isCreateRolePanel = true
  85. local role = SL:CreatePlayer(t, false, true) ---RoleManager.CreatePlayer(t, false, true)
  86. role.data.isHasShadow = false
  87. role.data.isUI = true
  88. self.role = role
  89. role:AsyncInit()
  90. role:ShowHead(false)
  91. ---@type Vector3
  92. local modelSize = Vector3.New(0.5, 0.5, 0.5)
  93. ---@type Vector3
  94. local modelRota = Vector3.New(0, 180, 0)
  95. local yList = string.split('90#102#115#126', '#')
  96. modelRota.y = tonumber(yList[count])
  97. local sizeList = string.split('0.4#0.4#0.4', '#')
  98. modelSize = Vector3.New(tonumber(sizeList[1]), tonumber(sizeList[2]), tonumber(sizeList[3]))
  99. role.model:SetLocalScale(modelSize.x, modelSize.y, modelSize.z)
  100. role.model:SetLocalRotation(modelRota.x, modelRota.y, modelRota.z)
  101. role.transform.position = self.modelPos
  102. role.model.transform.localPosition = Vector3.New(0, 0, 0)
  103. role:SetAnyActionStopTime(1)
  104. role:SetActionForce()
  105. if role.guardEquipModelId ~= 0 and SL.Main.Version == EVersion.Normal then
  106. ---@field guardPet GuardPet
  107. local guardPet = SL:GetRoleById(role.guardEquipModelId)---RoleManager.GetRole(role.guardEquipModelId)
  108. if guardPet then
  109. guardPet.data.isUI = true
  110. guardPet.transform:SetParent(role.transform)
  111. if role.model.roleModelPartsCombine:IsHasMount() then
  112. guardPet.transform.position = Vector3.New(LoginManager.GuardPetPos[count][1], LoginManager.GuardPetPos[count][2], LoginManager.GuardPetPos[count][3])
  113. else
  114. guardPet.transform.position = Vector3.New(self.modelPos.x, self.modelPos.y + 0.3, self.modelPos.z + 1)
  115. end
  116. guardPet.model:SetLocalRotation(0, -210, 0)
  117. guardPet:UpdateAction()
  118. end
  119. end
  120. end
  121. function this:Recycle()
  122. ---RoleManager.RecycleRole
  123. SL:RecycleRole(self.role.data.id)
  124. self:RecycleEffect()
  125. self.activator = nil
  126. end
  127. function this:RecycleEffect()
  128. if self.Effect ~= nil then
  129. self.Effect:Recycle()
  130. end
  131. end
  132. -- 初始化或者刷新界面时调用(如果不需要刷新整个模板,另外写函数调用(推荐方式))
  133. ---@param v UserProtos.RoleInfo
  134. function this:RefreshUI(v, count)
  135. self.date = v
  136. self.createCount = count
  137. GUI:Text_setString(self.view.Name, v.name)
  138. GUI:SetActive(self.view.DeleteBtn, false)
  139. local startPos = -375
  140. GUI:SetAnchoredPosition(self.view.root, Vector2.New((startPos + (self.createCount - 1) * 250), 50))
  141. local rect = GUI:GetRectTransform(self.view.UIModelItemTemplate)
  142. self.model = rect:Find("UIModelItemTemplate/Model")
  143. local wX, wY = self.model.transform.position.x, self.model.transform.position.y
  144. local screenPoint = SL:ConvertWorldPos2Screen(wX, wY)
  145. local noUILayerMask = bit.lshift(1, ELayerMaskType.Default)
  146. local obj, x, y, z = SL:RaycastScene(screenPoint.x, screenPoint.y, noUILayerMask)
  147. self.modelPos = Vector3.New(x, y, z)
  148. if SL:HasConfig("cfg_career", v.career.baseCareer) then
  149. local careerName = SL:GetConfig("cfg_career", v.career.baseCareer).name
  150. local careerId = SL:CfgCareerPost_GetCfgCareerId(v) ---cfg_career_post.Get_cfg_career_id(v.career)
  151. if careerId then
  152. local carName =SL:CfgCareerPost_GetCfgCareerName(careerId) --cfg_career_post.Get_cfg_career_name(careerId)
  153. if carName then
  154. careerName = carName
  155. end
  156. end
  157. GUI:Text_setString(self.view.Level, careerName .. " " .. v.level .. "级")
  158. end
  159. self:CreateRole(count)
  160. end
  161. function this:PlayerAni()
  162. self.role.data.isUI = false
  163. self.role:SetStandActoin(EAction.Stand, self.role.data.Dir, true)
  164. self.role:SetIsReplaceModel()
  165. end
  166. function this:ShowDeleteBtn(isShow)
  167. GUI:SetActive(self.view.DeleteBtn, isShow)
  168. end
  169. return this