KLUIModelItemTemplateItem.lua 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. ---@class KLUIModelItemTemplateItem:UIKmlLuaPanelBase
  2. ---@field view KLUIModelItemTemplateItemView
  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. self.CreateRolePanel = self.args.createRolePanel
  17. end
  18. ---创建或者刷新界面数据时调用
  19. function this:Refresh()
  20. end
  21. function this:DeleteBtnOnClick()
  22. self.CreateRolePanel:DeleteRole(self.date.rid)
  23. end
  24. function this:ShowDelete()
  25. self.CreateRolePanel:ShowChoosePlayer(self)
  26. end
  27. function this:Close()
  28. end
  29. function this:LoadEffect()
  30. local index = 52
  31. if SL:GetConfig("cfg_character_create", 1) and SL:GetConfig("cfg_character_create", 1).effect ~= nil then
  32. index = SL:GetConfig("cfg_character_create", 1).effect
  33. end
  34. local effect = SL:GetConfig("cfg_model_effect", index)
  35. local scale = Vector3.one
  36. local rotation = Quaternion.Euler(0, 0, 0)
  37. if effect ~= nil then
  38. scale = Vector3.New(effect.scale * 0.0001, effect.scale * 0.0001, effect.scale * 0.0001)
  39. end
  40. local data = {
  41. id = index,
  42. pos = Vector3.New(0, 0.15, 0),
  43. parent = self.role.model.transform,
  44. scale = scale,
  45. selfRotate = false,
  46. tableName = "cfg_model_effect",
  47. rotation = rotation,
  48. isActive = false,
  49. isSynch = true,
  50. isActive = true,
  51. callback = this.SetSize,
  52. callbackData = self,
  53. effectObjPos = Vector3.New(0, 0, 0),
  54. isUI = false
  55. }
  56. self.Effect = SL.Constructor_In:UIEffect()
  57. self.Effect:Init(data)
  58. end
  59. function this:SetSize()
  60. self.Effect.modelObject.transform:GetComponent(typeof(CS.UnityEngine.ParticleSystemRenderer)).minParticleSize = 0.16
  61. self.Effect.modelObject.transform:Find("0/Circle"):GetComponent(typeof(CS.UnityEngine.ParticleSystemRenderer)).minParticleSize = 0.13
  62. end
  63. function this:CreateRole(count)
  64. ---@type MapProtos.RoundPlayerEx
  65. local t = {}
  66. t.id = UtilityLua.UUID
  67. t.career = self.date.career
  68. t.level = self.date.level
  69. t.name = self.date.name
  70. t.hp = 1
  71. t.x = 0
  72. t.y = 0
  73. t.pkValue = 0
  74. if self.date.roleInfoExt ~= nil then
  75. t.equip = self.date.roleInfoExt.equip
  76. t.appearIdx = self.date.roleInfoExt.equipShowIdx
  77. t.roleAppear = self.date.roleInfoExt.roleAppear
  78. t.shapeRing = self.date.roleInfoExt.shapeRing
  79. t.mountId = t.shapeRing == 0 and self.date.roleInfoExt.mountId or 0
  80. end
  81. t.isCreateRolePanel = true
  82. local role = SL:CreatePlayer(t, false, true)
  83. role.data.isHasShadow = false
  84. role.data.isUI = true
  85. self.role = role
  86. role:AsyncInit()
  87. role:ShowHead(false)
  88. ---@type Vector3
  89. local modelSize = Vector3.New(0.5, 0.5, 0.5)
  90. ---@type Vector3
  91. local modelRota = Vector3.New(0, 180, 0)
  92. local yList = string.split('90#102#115#126', '#')
  93. modelRota.y = tonumber(yList[count])
  94. local sizeList = string.split('0.4#0.4#0.4', '#')
  95. modelSize = Vector3.New(tonumber(sizeList[1]), tonumber(sizeList[2]), tonumber(sizeList[3]))
  96. role.model:SetLocalScale(modelSize.x, modelSize.y, modelSize.z)
  97. role.model:SetLocalRotation(modelRota.x, modelRota.y, modelRota.z)
  98. role.transform.position = self.modelPos
  99. role.model.transform.localPosition = Vector3.New(0, 0, 0)
  100. role:SetAnyActionStopTime(1)
  101. role:SetActionForce()
  102. if role.guardEquipModelId ~= 0 and SL:GetVersion() == EVersion.Normal then
  103. ---@field guardPet GuardPet
  104. local guardPet = SL:GetRoleById(role.guardEquipModelId)
  105. if guardPet then
  106. guardPet.data.isUI = true
  107. guardPet.transform:SetParent(role.transform)
  108. if role.model.roleModelPartsCombine:IsHasMount() then
  109. guardPet.transform.position = Vector3.New(LoginManager.GuardPetPos[count][1], LoginManager.GuardPetPos[count][2], LoginManager.GuardPetPos[count][3])
  110. else
  111. guardPet.transform.position = Vector3.New(self.modelPos.x, self.modelPos.y + 0.3, self.modelPos.z + 1)
  112. end
  113. guardPet.model:SetLocalRotation(0, -210, 0)
  114. guardPet:UpdateAction()
  115. end
  116. end
  117. end
  118. function this:Recycle()
  119. SL:RecycleRole(self.role.data.id)
  120. self:RecycleEffect()
  121. self.activator = nil
  122. end
  123. function this:RecycleEffect()
  124. if self.Effect ~= nil then
  125. self.Effect:Recycle()
  126. end
  127. end
  128. -- 初始化或者刷新界面时调用(如果不需要刷新整个模板,另外写函数调用(推荐方式))
  129. ---@param v UserProtos.RoleInfo
  130. function this:RefreshUI(v, count)
  131. self.date = v
  132. self.createCount = count
  133. GUI:Text_setString(self.view.Name, v.name)
  134. GUI:SetActive(self.view.DeleteBtn, false)
  135. local startPos = -375
  136. GUI:SetAnchoredPosition(self.view.root, Vector2.New((startPos + (self.createCount - 1) * 250), 50))
  137. local rect = GUI:GetRectTransform(self.view.UIModelItemTemplate)
  138. self.model = rect:Find("UIModelItemTemplate/Model")
  139. local screenPoint = SL:ConvertWorldPos2Screen(self.model.transform.position.x,self.model.transform.position.y)
  140. local noUILayerMask = bit.lshift(1, ELayerMaskType.Default)
  141. local obj, x, y, z = SL:RaycastScene(screenPoint.x, screenPoint.y,noUILayerMask)
  142. self.modelPos = Vector3.New(x, y, z)
  143. local str = v.level .. "级"
  144. if SL:GetConfig("cfg_career", v.career.baseCareer) then
  145. local careerName = SL:GetConfig("cfg_career", v.career.baseCareer).name
  146. local careerId = self.Get_cfg_career_id(v.career)
  147. if careerId then
  148. local carName = self.Get_cfg_career_name(careerId)
  149. if carName then
  150. careerName = carName
  151. end
  152. end
  153. GUI:Text_setString(self.view.Level, careerName .. " " .. str)
  154. end
  155. self:CreateRole(count)
  156. end
  157. ---@return number @根据根职业,职业等级,职业编号获取职业表id,职业名称
  158. ---@param careerInfo CommonProtos.Career
  159. function this.Get_cfg_career_id(careerInfo)
  160. local baseCareer = careerInfo.baseCareer
  161. local careerRank = careerInfo.careerRank
  162. ---@type cfg_career_column[]
  163. local careers = SL:GetConfigTable("cfg_career")
  164. for _, v in pairs(careers) do
  165. if v.baseCareer == baseCareer and v.careerRank == careerRank then
  166. return v.id, v.name, v.upGradeEffect, v.careerRankName, v.nextCareerNum
  167. end
  168. end
  169. end
  170. ---@return string @获取职业中文名称
  171. function this.Get_cfg_career_name(id)
  172. local careerCol = SL:GetConfigTable("cfg_career")
  173. return careerCol.name
  174. end
  175. function this:PlayerAni()
  176. self.role.data.isUI = false
  177. self.role:SetStandActoin(EAction.Stand, self.role.data.Dir, true)
  178. self.role:SetIsReplaceModel()
  179. end
  180. return this