源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2012 rivejä
76 KiB

1 kuukausi sitten
  1. --ui挂接模型处理
  2. UIModelCommon = UIModelCommon or BaseClass(UIPartical)
  3. UIModelCommon.ModelType =
  4. {
  5. RT = 1,
  6. BackModel = 2,
  7. Model = 3,
  8. }
  9. local UIModelCommon = UIModelCommon
  10. local ModelPartName = ModelPartName
  11. function UIModelCommon:__init(go,parent,model_data)
  12. self.particle_mgr = ParticleManager:getInstance()
  13. self.model_type = UIModelCommon.ModelType.RT
  14. self.gameObject = go
  15. self.parent = parent
  16. self.model_data = model_data
  17. self.particle_list = {}
  18. self.load_res_target = {}
  19. self.show_shadow = model_data.show_shadow
  20. self.raycastParent = model_data.raycastParent
  21. self.layer_name = model_data.layer_name or "UI"
  22. self.delay_play_action_timer_list = {}
  23. self.pearl_list = {}
  24. self.pearl_parent = {}
  25. end
  26. function UIModelCommon:__delete()
  27. self.cache_bones = {}
  28. self:ClearActionTimerList()
  29. self:RemoveAllParticle()
  30. if self.cache_effect_list then
  31. for obj_type, list in pairs(self.cache_effect_list) do
  32. for k,v in pairs(list) do
  33. destroy(v.go)
  34. end
  35. end
  36. end
  37. if self.light_go then
  38. destroy(self.light_go)
  39. end
  40. if self.clothe then
  41. self.clothe:DeleteMe()
  42. self.clothe = nil
  43. end
  44. if self.head_wear then
  45. self.head_wear:DeleteMe()
  46. self.head_wear = nil
  47. end
  48. if self.weapon_clothe_obj then
  49. self.weapon_clothe_obj:DeleteMe()
  50. self.weapon_clothe_obj = nil
  51. self.weapon_clothe_id = nil
  52. end
  53. if self.role then
  54. destroy(self.role)
  55. self.role = nil
  56. end
  57. if self.horse_gameObject then
  58. destroy(self.horse_gameObject)
  59. self.horse_gameObject = nil
  60. end
  61. if self.gameObject then
  62. destroy(self.gameObject)
  63. end
  64. if self.weapon_hand_list then
  65. for k,v in pairs(self.weapon_hand_list) do
  66. destroy(v)
  67. self.weapon_hand_list[k] = nil
  68. end
  69. end
  70. if self.head_wear_animator then
  71. self.head_wear_animator = nil
  72. end
  73. if self.deay_show_warSoul then
  74. GlobalTimerQuest:CancelQuest(self.deay_show_warSoul)
  75. self.deay_show_warSoul = nil
  76. end
  77. if self.deay_show_light then
  78. GlobalTimerQuest:CancelQuest(self.deay_show_light)
  79. self.deay_show_light = nil
  80. end
  81. if self.weapon_event_id then
  82. GlobalEventSystem:UnBind(self.weapon_event_id)
  83. self.weapon_event_id = nil
  84. end
  85. if self.fahion_event_id then
  86. GlobalEventSystem:UnBind(self.fahion_event_id)
  87. self.fahion_event_id = nil
  88. end
  89. if self.cloth_event_id then
  90. GlobalEventSystem:UnBind(self.cloth_event_id)
  91. self.cloth_event_id = nil
  92. end
  93. if self.args_fun_event_id then
  94. GlobalEventSystem:UnBind(self.args_fun_event_id)
  95. self.args_fun_event_id = nil
  96. end
  97. if self.viseble_change_id then
  98. GlobalEventSystem:UnBind(self.viseble_change_id)
  99. self.viseble_change_id = nil
  100. end
  101. for k,v in pairs(self.pearl_list) do
  102. v:DeleteMe()
  103. end
  104. self.pearl_list = {}
  105. for k,v in pairs(self.pearl_parent) do
  106. if self.pearl_parent[k] then
  107. destroy(self.pearl_parent[k])
  108. self.pearl_parent[k] = nil
  109. end
  110. end
  111. self.pearl_parent = {}
  112. if self.raycastGo then
  113. destroy(self.raycastGo)
  114. end
  115. lua_resM:clearReference(self.load_res_target)
  116. self:StopSkillPreViewTimer()
  117. end
  118. function UIModelCommon:AddEvents()
  119. if self.can_rotate then
  120. local function touch_begin(target,pos_x, pos_y)
  121. self.pos_x = pos_x
  122. end
  123. local function draging(target,pos_x, pos_y)
  124. self:OnDragging(pos_x, pos_y)
  125. end
  126. local function touch_end(target,pos_x, pos_y)
  127. end
  128. local rtGo = self.parent.gameObject
  129. if self.model_data.raycast_size then
  130. self.parent:GetComponent("RawImage").raycastTarget = false
  131. self.raycastGo = GameObject.New("raycast_"..self.parent.gameObject.name)
  132. self.raycastGo.transform:SetParent(self.parent.transform)
  133. local eImage = self.raycastGo:AddComponent(typeof(LuaFramework.EmptyRaycast))
  134. self.raycastGo.transform.localPosition = Vector3.zero
  135. self.raycastGo.transform.sizeDelta = Vector2(self.model_data.raycast_size.x, self.model_data.raycast_size.y)
  136. self.raycastGo.transform.localScale = Vector3.one
  137. eImage.raycastTarget = true
  138. -- if type(self.raycastParent) ~= "userdata" and self.raycastParent.use_background then
  139. self.raycastGo.transform:SetSiblingIndex(1)
  140. -- else
  141. -- self.raycastGo.transform:SetSiblingIndex(0)
  142. -- end
  143. rtGo = self.raycastGo
  144. else
  145. self.parent:GetComponent("RawImage").raycastTarget = true
  146. end
  147. AddDragBeginEvent(rtGo, touch_begin)
  148. AddDragEvent(rtGo, draging)
  149. AddDragEndEvent(rtGo, touch_end)
  150. -- AddUpEvent(self.parent.gameObject, touch_end)
  151. elseif self.skill_preview and self.skill_id then
  152. local function on_click()
  153. self:PlaySkillEffect(self.role, self.skill_id)
  154. end
  155. local rtGo = self.parent.gameObject
  156. if self.model_data.raycast_size then
  157. self.parent:GetComponent("RawImage").raycastTarget = false
  158. self.raycastGo = GameObject.New("raycast_"..self.parent.gameObject.name)
  159. self.raycastGo.transform:SetParent(self.parent.transform)
  160. local eImage = self.raycastGo:AddComponent(typeof(LuaFramework.EmptyRaycast))
  161. self.raycastGo.transform.localPosition = Vector3.zero
  162. self.raycastGo.transform.sizeDelta = Vector2(self.model_data.raycast_size.x, self.model_data.raycast_size.y)
  163. self.raycastGo.transform.localScale = Vector3.one
  164. eImage.raycastTarget = true
  165. self.raycastGo.transform:SetSiblingIndex(1)
  166. rtGo = self.raycastGo
  167. else
  168. self.parent:GetComponent("RawImage").raycastTarget = true
  169. end
  170. AddClickEvent(rtGo,on_click)
  171. else
  172. self.parent:GetComponent("RawImage").raycastTarget = false
  173. end
  174. if self.type and self.type == SceneBaseType.MainRole then
  175. --武器变化
  176. local weapon_fun = function (_type, weapon_id, career, weapon_clothe)
  177. if self.do_not_main_role_cloth_res_change then return end
  178. if not IsNull(self.role) then
  179. self:CreateWeapon(_type, weapon_id, career, weapon_clothe)
  180. end
  181. end
  182. self.weapon_event_id = GlobalEventSystem:Bind(SceneEventType.MAIN_ROLE_WEAPON_RES_CHANGE, weapon_fun)
  183. --时装变化(暂不包括武器时装)
  184. local fashion_fun = function (_type, fashion_model_id, texture_id)
  185. if self.do_not_main_role_cloth_res_change then return end
  186. if not IsNull(self.role) then
  187. if self.clothe_res_id then
  188. if self.clothe_res_id == fashion_model_id then
  189. self:CreateClothTexture(fashion_model_id, texture_id)
  190. else
  191. self:SetData(self.parent, self.model_data)
  192. end
  193. end
  194. end
  195. end
  196. self.fahion_event_id = GlobalEventSystem:Bind(SceneEventType.MAIN_ROLE_FASHION_RES_CHANGE, fashion_fun)
  197. --衣服改变
  198. local cloth_fun = function (_type, clothe_res_id)
  199. if self.do_not_main_role_cloth_res_change then return end
  200. if not IsNull(self.role) then
  201. self:SetData(self.parent, self.model_data)
  202. end
  203. end
  204. self.cloth_event_id = GlobalEventSystem:Bind(SceneEventType.MAIN_ROLE_CLOTH_RES_CHANGE, cloth_fun)
  205. --默认摄像机参数改变
  206. local on_args_fun = function ()
  207. self:SetCameraArgs(true)
  208. end
  209. self.args_fun_event_id = GlobalEventSystem:Bind(EventName.UPDATE_UIMODEL_CAMERA_DEFAULT_ARGS, on_args_fun)
  210. end
  211. --visible改变时重新播动作
  212. local action_fun = function()
  213. if not IsNull(self.role) and self.replay_action_name then
  214. local is_show = self.role and self.role.activeInHierarchy
  215. if not is_show then
  216. self._has_set_hide = true
  217. end
  218. --从隐藏到显示
  219. if is_show == true and self._has_set_hide then
  220. self._has_set_hide = false
  221. local last_action = self.replay_action_name or "show"
  222. local action_list = {last_action}
  223. self:DelayPlayNextAction(nil, action_list, 0)
  224. end
  225. end
  226. end
  227. self.viseble_change_id = GlobalEventSystem:Bind(BaseView.ChangeVisible, action_fun)
  228. end
  229. function UIModelCommon:OnDragging(pos_x, pos_y)
  230. if pos_x and self.pos_x then
  231. local delta_x = pos_x - self.pos_x
  232. local speed = 6
  233. if self.role then
  234. if delta_x > 0 then
  235. self.rotate = self.rotate - speed
  236. -- self.role.transform:Rotate(Vector3(0, -speed, 0))
  237. if self.horse_transform and (self.type == SceneBaseType.Include_Horse
  238. or self.type == SceneBaseType.Baby_Include_Horse) then
  239. --如果人物身上有马,要旋转马,因为self.role被丢进马里去当子物体了
  240. self.horse_transform:Rotate(Vector3.up, -speed, UnityEngine.Space.World)
  241. else
  242. self.role.transform:Rotate(Vector3.up, -speed, UnityEngine.Space.World)
  243. end
  244. else
  245. self.rotate = self.rotate + speed
  246. -- self.role.transform:Rotate(Vector3(0, speed, 0))
  247. if self.horse_transform and (self.type == SceneBaseType.Include_Horse
  248. or self.type == SceneBaseType.Baby_Include_Horse) then
  249. --如果人物身上有马,要旋转马,因为self.role被丢进马里去当子物体了
  250. self.horse_transform:Rotate(Vector3.up, speed, UnityEngine.Space.World)
  251. else
  252. self.role.transform:Rotate(Vector3.up, speed, UnityEngine.Space.World)
  253. end
  254. end
  255. self.pos_x = pos_x
  256. end
  257. else
  258. print("---UIModelClassByRT--OnDragging-pos_x-:", pos_x)
  259. print("---UIModelClassByRT--OnDragging-pos_y-:", pos_y)
  260. end
  261. end
  262. function UIModelCommon:ClearActionTimerList()
  263. if self.delay_play_action_timer_list then
  264. for i, id in ipairs(self.delay_play_action_timer_list) do
  265. GlobalTimerQuest:CancelQuest(id)
  266. end
  267. self.delay_play_action_timer_list = {}
  268. end
  269. end
  270. function UIModelCommon:PlayActions(action_name_list,action_delta,animator)
  271. if IsNull(self.role) then return end
  272. animator = animator or self.role:GetComponent("Animator")
  273. if not IsTableEmpty(action_name_list) then
  274. local action_name = action_delta and action_name_list[1] or table.remove(action_name_list, 1)
  275. if action_name then
  276. local animator = self.role:GetComponent("Animator")
  277. animator:CrossFade( action_name,0, 0.0 )
  278. if not IsTableEmpty(action_name_list) then
  279. self.delay_play_action_timer_list = self.delay_play_action_timer_list or {}
  280. if action_delta then
  281. self:DelayPlayNextActionLoop(animator, action_name_list, action_delta)
  282. else
  283. self:DelayPlayNextAction(animator, action_name_list)
  284. end
  285. end
  286. end
  287. end
  288. end
  289. --随机循环动作列表 暂时不添加音效
  290. --action_name_list.idle_name 默认待机动作
  291. function UIModelCommon:DelayPlayNextActionLoop(animator, action_name_list, action_delta)
  292. if animator == nil then return end
  293. if IsTableEmpty(action_name_list) then return end
  294. animator:Update(0)
  295. local cur_state = animator:GetCurrentAnimatorStateInfo(0)
  296. local action_time = 0
  297. if not cur_state then return end
  298. action_time = cur_state.length
  299. local idle_action = action_name_list.idle_name or "idle"
  300. local delay_play = function ()
  301. local action_name = action_name_list[ math.random(1,#action_name_list)]
  302. animator:CrossFade(action_name, 0.0, 0.0)
  303. self:DelayPlayNextActionLoop(animator, action_name_list, action_delta)
  304. end
  305. local play_idle = function ()
  306. animator:CrossFade(idle_action, 0.3, 0.0 )
  307. end
  308. --清理计时器列表
  309. if #self.delay_play_action_timer_list >= 20 then
  310. self:ClearActionTimerList()
  311. end
  312. action_delta = action_delta < action_time and action_time + 1 or action_delta
  313. table.insert(self.delay_play_action_timer_list, GlobalTimerQuest:AddDelayQuest(play_idle,action_time))
  314. table.insert(self.delay_play_action_timer_list, GlobalTimerQuest:AddDelayQuest(delay_play,action_delta))
  315. end
  316. --延迟播放下一个动作
  317. function UIModelCommon:DelayPlayNextAction(animator, action_name_list, force_delay_action_time)
  318. if not IsTableEmpty(action_name_list) then
  319. animator = animator or self.role:GetComponent("Animator")
  320. local cur_state = 0
  321. local action_time = 0
  322. if force_delay_action_time and force_delay_action_time > 0 then
  323. action_time = force_delay_action_time
  324. else
  325. animator:Update(0)
  326. cur_state = animator:GetCurrentAnimatorStateInfo(0)
  327. action_time = cur_state.length
  328. end
  329. if animator and action_time and action_time > 0 then
  330. local delay_play = function ()
  331. if IsNull(animator) or self._use_delete_method then
  332. return
  333. end
  334. local action_name = table.remove(action_name_list, 1)
  335. if animator and action_name then
  336. animator:CrossFade(action_name, 0.1, 0.0 )
  337. if not IsNull(self.head_wear_animator) then
  338. self.head_wear_animator:CrossFade(action_name, 0.2, 0.0 )
  339. end
  340. self:CreateEffect(self.type, self.clothe_res_id, self.role, action_name)
  341. if not IsTableEmpty(action_name_list) then
  342. self:DelayPlayNextAction(animator, action_name_list)
  343. else
  344. --播完动作再重置一下相机灯光参数
  345. if self.use_light_data then
  346. self:ApplyCameraLightData()
  347. end
  348. end
  349. else
  350. return
  351. end
  352. end
  353. table.insert(self.delay_play_action_timer_list, GlobalTimerQuest:AddDelayQuest(delay_play,action_time))
  354. else
  355. return
  356. end
  357. end
  358. return
  359. end
  360. --创建武器
  361. function UIModelCommon:CreateWeapon(_type, weapon_res_id, career, weapon_clothe)
  362. if _type and _type == SceneBaseType.Monster then
  363. return
  364. end
  365. self.weapon_res_id = weapon_res_id
  366. if _type and weapon_res_id then
  367. local abName,weapon_attach_list,weapon_res_list = GameResPath.GetWeaponRes(_type,weapon_res_id,career)
  368. local function localWeaponCallback(objs, is_gameObject)
  369. if not self._use_delete_method then
  370. if weapon_attach_list and objs then
  371. if self.weapon_container then
  372. for k,v in pairs(self.weapon_container) do
  373. destroy(v.go)
  374. end
  375. end
  376. if self.weapon_clothe_obj then
  377. self.weapon_clothe_obj:DeleteMe()
  378. self.weapon_clothe_obj = nil
  379. end
  380. local bone_go = nil
  381. self.weapon_container = {}
  382. for k,boneName in ipairs(weapon_attach_list) do
  383. bone_go = FindBone(self.role.transform,boneName)
  384. if bone_go then
  385. local go = is_gameObject and objs[k] or newObject(objs[k-1])
  386. if go then
  387. go.transform.parent = bone_go.transform
  388. go.transform.localPosition = Vector3.zero
  389. go.transform.localRotation = Quaternion.Euler(Vector3.zero)
  390. go.transform.localScale = Vector3.one
  391. if ClientConfig.is_use_model_render or self.model_type == UIModelCommon.ModelType.BackModel then
  392. self:SetUIbackRoleLayer(self.parent.transform)
  393. elseif self.model_type == UIModelCommon.ModelType.Model then
  394. self:SetUILayer(self.parent.transform)
  395. end
  396. self:CheckShadow(go, weapon_attach_list[i])
  397. self.weapon_container[boneName] = {go = go, abName = abName, resName = weapon_res_list[k], index = k}
  398. go:SetActive(true)
  399. -- if weapon_clothe and weapon_clothe ~= "" and tonumber(weapon_clothe) ~= 0 then
  400. -- local mesh = go:GetComponentInChildren(typeof(UnityEngine.MeshRenderer))
  401. -- if mesh and mesh.material then
  402. -- local res = weapon_res_id .. "_" .. weapon_clothe
  403. -- self.weapon_clothe_obj = Weapon.New( mesh.material, res)
  404. -- end
  405. -- end
  406. end
  407. end
  408. end
  409. --部件特效,参数为部件类型与id
  410. self:CreateEffect(SceneBaseType.FWeapon, self.weapon_res_id)
  411. end
  412. end
  413. end
  414. if self.role and self.role.transform and abName and weapon_res_list then
  415. LuaResManager:getInstance():loadPrefabs(self,abName,weapon_res_list, localWeaponCallback)
  416. end
  417. end
  418. end
  419. --时装衣服贴图
  420. function UIModelCommon:CreateClothTexture(fashion_model_id, texture_id)
  421. self.fashion_model_id = fashion_model_id
  422. self.texture_id = texture_id
  423. -- if fashion_model_id and texture_id and tonumber(texture_id) ~= 0 and self.gameObject then --使用贴图
  424. -- if self.clothe then
  425. -- self.clothe:DeleteMe()
  426. -- self.clothe = nil
  427. -- end
  428. -- local texture_res = fashion_model_id .. "_" .. texture_id
  429. -- self.skin_mesh_renderer = self.gameObject:GetComponentInChildren(typeof(UnityEngine.SkinnedMeshRenderer))
  430. -- if self.skin_mesh_renderer and self.skin_mesh_renderer.material and texture_res then
  431. -- self.clothe = Clothe.New(self.skin_mesh_renderer.material,texture_res)
  432. -- end
  433. -- end
  434. end
  435. --创建翅膀
  436. function UIModelCommon:CreateWing(_type, wing_id)
  437. if _type and wing_id then
  438. if self.role_type == SceneBaseType.Pet then--巫女+翅膀
  439. _type = SceneBaseType.FCloud
  440. end
  441. local abName, resName = GameResPath.GetModelClotheRes(_type, wing_id)
  442. local function localWingCallback(objs, is_gameObject)
  443. if self._use_delete_method then
  444. return
  445. end
  446. if not objs or not objs[0] then
  447. logWarn("cannot find wing res = "..self.wing_id)
  448. return
  449. end
  450. local go = is_gameObject and objs[0] or newObject(objs[0])
  451. go:SetActive(true)
  452. local bone = FindBone(self.role.transform, AttachNode.Wing)
  453. if bone == nil then
  454. return
  455. end
  456. go.transform:SetParent(bone)
  457. go.transform.localPosition = Vector3.zero
  458. go.transform.localRotation = Quaternion.identity
  459. go.transform.localScale = Vector3.one
  460. if ClientConfig.is_use_model_render or self.model_type == UIModelCommon.ModelType.BackModel then
  461. self:SetUIbackRoleLayer(self.parent.transform)
  462. elseif self.model_type == UIModelCommon.ModelType.Model then
  463. -- 修改翅膀节点下的面片渲染的sortingOrder与带Canvas组件的父节点同级,保证不会被UI背景盖住
  464. local shinned_meshRender_com_list = go:GetComponentsInChildren(typeof(UnityEngine.SkinnedMeshRenderer),true)
  465. if shinned_meshRender_com_list.Length > 0 then
  466. for i=1,shinned_meshRender_com_list.Length do
  467. shinned_meshRender_com_list[i-1].sortingOrder = self:GetCurrLayerDepth(self.layer_name)
  468. end
  469. end
  470. -- 修改翅膀节点下的渲染队列
  471. self:SetUILayer(self.parent.transform)
  472. end
  473. local animator = go:GetComponent("Animator")
  474. if not IsNull(animator) then
  475. animator.cullingMode = UnityEngine.AnimatorCullingMode.AlwaysAnimate
  476. animator:CrossFade( "idle",0, 0.0 )
  477. end
  478. --部件特效,参数为部件类型与id
  479. self:CreateEffect(SceneBaseType.FWing, self.wing_id, go)
  480. end
  481. if self.role.transform and abName and resName then
  482. LuaResManager:getInstance():loadPrefab(self,abName,resName, localWingCallback)
  483. end
  484. end
  485. end
  486. --创建活跃度形象
  487. function UIModelCommon:CreateLivenessImage(_type, image_id)
  488. if _type and image_id and image_id ~= 0 then
  489. local prefixStr = image_id < 10 and "00" or "0"
  490. local effect_name = "effect_huoyuedu_" .. prefixStr .. image_id
  491. self.particle_mgr:AddUIModelEffect(effect_name,self,true,nil,7,nil,nil,nil,nil,nil,false)
  492. end
  493. end
  494. --创建头发
  495. function UIModelCommon:CreateHeadWear(_type, head_wear_id, head_clothe_id)
  496. --self.head_wear_id = head_wear_id
  497. --self.head_clothe_id = head_clothe_id
  498. if _type and head_wear_id then
  499. local abName, resName = GameResPath.GetHeadRes(_type, head_wear_id)
  500. local function localHeadWearCallback(objs, is_gameObject)
  501. if self._use_delete_method then
  502. return
  503. end
  504. if not objs or not objs[0] then
  505. logWarn("cannot find headwear res = "..head_wear_id)
  506. return
  507. end
  508. if self.default_headWear_go and self.default_headWear_abName then
  509. lua_resM:AddObjToPool(self, self.default_headWear_abName, self.default_headWear_abName, self.default_headWear_go)
  510. self.default_headWear_go = nil
  511. self.default_headWear_abName = nil
  512. end
  513. local go = is_gameObject and objs[0] or newObject(objs[0])
  514. go:SetActive(true)
  515. local bone = FindBone(self.role.transform, AttachNode.Head)
  516. if bone == nil then
  517. return
  518. end
  519. go.transform:SetParent(bone)
  520. go.transform.localPosition = Vector3.zero
  521. go.transform.localRotation = Quaternion.identity
  522. go.transform.localScale = Vector3.one
  523. --头发动作
  524. local animator = go:GetComponent("Animator")
  525. if IsNull(animator) then
  526. return
  527. end
  528. -- if self.curr_body_action_name then
  529. -- animator:CrossFade(self.curr_body_action_name, 0, 0.0)
  530. -- end
  531. self.head_wear_animator = animator
  532. if ClientConfig.is_use_model_render or self.model_type == UIModelCommon.ModelType.BackModel then
  533. self:SetUIbackRoleLayer(self.parent.transform)
  534. elseif self.model_type == UIModelCommon.ModelType.Model then
  535. self:SetUILayer(self.parent.transform)
  536. end
  537. self:CheckShadow(go, resName)
  538. -- local mesh = go:GetComponentInChildren(typeof(UnityEngine.MeshRenderer))
  539. -- if mesh and mesh.material then
  540. -- if head_clothe_id and tonumber(head_clothe_id) ~= 0 then
  541. -- if self.head_clothe then
  542. -- self.head_clothe:DeleteMe()
  543. -- self.head_clothe = nil
  544. -- end
  545. -- local texture_res = head_wear_id .. "_" .. head_clothe_id
  546. -- self.head_clothe = Clothe.New(mesh.material, texture_res)
  547. -- end
  548. -- end
  549. end
  550. if self.role.transform and abName and resName then
  551. if not resMgr:GetAssetBundle(abName) and self.career then--没有当前头发 需要异步加载 就先创建默认头饰
  552. if self.default_headWear_go and self.default_headWear_abName then
  553. --self:SetUILayer(self.default_headWear_go.transform, UIPartical.RenderingOther_List.DEFAULT)
  554. lua_resM:AddObjToPool(self, self.default_headWear_abName, self.default_headWear_abName, self.default_headWear_go)
  555. self.default_headWear_go = nil
  556. self.default_headWear_abName = nil
  557. end
  558. local local_default_headWear_abName = ModelPartName[6] .. string.format("10%d000", self.career)
  559. local local_default_headWear_go = lua_resM:GetObjFormPool(self, local_default_headWear_abName, local_default_headWear_abName)
  560. if local_default_headWear_go then
  561. local bone = FindBone(self.role.transform, AttachNode.Head)
  562. if bone == nil then
  563. return
  564. end
  565. local_default_headWear_go.transform:SetParent(bone)
  566. local_default_headWear_go.transform.localPosition = Vector3.zero
  567. local_default_headWear_go.transform.localRotation = Quaternion.identity
  568. local_default_headWear_go.transform.localScale = Vector3.one
  569. self.default_headWear_go = local_default_headWear_go
  570. self.default_headWear_abName = local_default_headWear_abName
  571. if ClientConfig.is_use_model_render or self.model_type == UIModelCommon.ModelType.BackModel then
  572. self:SetUIbackRoleLayer(self.parent.transform)
  573. elseif self.model_type == UIModelCommon.ModelType.Model then
  574. self:SetUILayer(self.parent.transform)
  575. end
  576. end
  577. self:CheckShadow(self.default_headWear_go, resName)
  578. end
  579. LuaResManager:getInstance():loadPrefab(self,abName,resName, localHeadWearCallback)
  580. end
  581. end
  582. end
  583. --创建真·头饰,上面的那个应该叫头发
  584. function UIModelCommon:CreateHatWear(hat_wear_id)
  585. if hat_wear_id then
  586. local abName, resName = GameResPath.GetHatRes(hat_wear_id)
  587. local function localHeadWearCallback(objs, is_gameObject)
  588. if self._use_delete_method then
  589. return
  590. end
  591. if not objs or not objs[0] then
  592. logWarn("cannot find headwear res = "..hat_wear_id)
  593. return
  594. end
  595. if self.default_hat_go and self.default_hat_abName then
  596. lua_resM:AddObjToPool(self, self.default_hat_abName, self.default_hat_abName, self.default_hat_go)
  597. self.default_hat_go = nil
  598. self.default_hat_abName = nil
  599. end
  600. local go = is_gameObject and objs[0] or newObject(objs[0])
  601. go:SetActive(true)
  602. local bone = FindBone(self.role.transform, AttachNode.Head)
  603. if bone == nil then
  604. return
  605. end
  606. go.transform:SetParent(bone)
  607. go.transform.localPosition = Vector3.zero
  608. go.transform.localRotation = Quaternion.identity
  609. go.transform.localScale = Vector3.one
  610. if ClientConfig.is_use_model_render or self.model_type == UIModelCommon.ModelType.BackModel then
  611. self:SetUIbackRoleLayer(self.parent.transform)
  612. elseif self.model_type == UIModelCommon.ModelType.Model then
  613. self:SetUILayer(self.parent.transform)
  614. end
  615. self:CheckShadow(go, resName)
  616. -- local mesh = go:GetComponentInChildren(typeof(UnityEngine.MeshRenderer))
  617. -- if mesh and mesh.material then
  618. -- if head_clothe_id and tonumber(head_clothe_id) ~= 0 then
  619. -- if self.head_clothe then
  620. -- self.head_clothe:DeleteMe()
  621. -- self.head_clothe = nil
  622. -- end
  623. -- local texture_res = hat_wear_id .. "_" .. head_clothe_id
  624. -- self.head_clothe = Clothe.New(mesh.material, texture_res)
  625. -- end
  626. -- end
  627. end
  628. if self.role.transform and abName and resName then
  629. if not resMgr:GetAssetBundle(abName) and self.career then--没有当前头发 需要异步加载 就先创建默认头饰
  630. if self.default_hat_go and self.default_hat_abName then
  631. --self:SetUILayer(self.default_hat_go.transform, UIPartical.RenderingOther_List.DEFAULT)
  632. lua_resM:AddObjToPool(self, self.default_hat_abName, self.default_hat_abName, self.default_hat_go)
  633. self.default_hat_go = nil
  634. self.default_hat_abName = nil
  635. end
  636. local local_default_hat_abName = ModelPartName[6] .. string.format("10%d000", self.career)
  637. local local_default_hat_go = lua_resM:GetObjFormPool(self, local_default_hat_abName, local_default_hat_abName)
  638. if local_default_hat_go then
  639. local bone = FindBone(self.role.transform, AttachNode.Head)
  640. if bone == nil then
  641. return
  642. end
  643. local_default_hat_go.transform:SetParent(bone)
  644. local_default_hat_go.transform.localPosition = Vector3.zero
  645. local_default_hat_go.transform.localRotation = Quaternion.identity
  646. local_default_hat_go.transform.localScale = Vector3.one
  647. self.default_hat_go = local_default_hat_go
  648. self.default_hat_abName = local_default_hat_abName
  649. if ClientConfig.is_use_model_render or self.model_type == UIModelCommon.ModelType.BackModel then
  650. self:SetUIbackRoleLayer(self.parent.transform)
  651. elseif self.model_type == UIModelCommon.ModelType.Model then
  652. self:SetUILayer(self.parent.transform)
  653. end
  654. end
  655. self:CheckShadow(self.default_hat_go, resName)
  656. end
  657. LuaResManager:getInstance():loadPrefab(self,abName,resName, localHeadWearCallback)
  658. end
  659. end
  660. end
  661. function UIModelCommon:CreateLightEffect( light_id, parent_go )
  662. -- if self.deay_show_light then
  663. -- GlobalTimerQuest:CancelQuest(self.deay_show_light)
  664. -- self.deay_show_light = nil
  665. -- end
  666. -- local function delay( )
  667. -- local show_type = (self.model_type == UIModelCommon.ModelType.BackModel) and "UIBackRole" or "UI"
  668. -- self.light_effect_id = self.particle_mgr:AddTargetEffect(LightModel:GetInstance():GetLightResById(light_id), self.role, true, nil, nil, 7,nil,nil,nil,nil,show_type)
  669. -- if self.light_effect_id then
  670. -- self.particle_list[self.light_effect_id] = self.light_effect_id
  671. -- end
  672. -- end
  673. -- self.deay_show_light = setTimeout(delay,0)
  674. local effect_obj_type = nil
  675. local effect_vo = {name = LightModel:GetInstance():GetLightResById(light_id)}
  676. local bone = FindBone(parent_go and parent_go.transform or self.transform, "root")
  677. if bone then
  678. local function load_finish_func(objs, is_gameObject)
  679. if not objs or not objs[0] then
  680. return
  681. end
  682. if IsNull(bone) then
  683. if is_gameObject then destroy(objs[0]) end
  684. return
  685. end
  686. local go = is_gameObject and objs[0] or newObject(objs[0])
  687. if not self.light_go then--没有就直接赋值
  688. self.light_go = go
  689. else--有就直接销毁原来的继续赋值新的
  690. if self.light_go then
  691. destroy(self.light_go)
  692. end
  693. self.light_go = go
  694. end
  695. go:SetActive(true)
  696. if effect_vo.is_world_particle then
  697. AttachGameRoot(go.transform)
  698. else
  699. go.transform:SetParent(bone)
  700. end
  701. SetLocalPosition(go.transform)
  702. SetLocalRotation(go.transform)
  703. SetLocalScale(go.transform, 1)
  704. if effect_obj_type or (self.model_data and self.model_data.attach_game_root) then
  705. self:SetUILayer(go.transform, UIPartical.RenderingOther_List.DEFAULT)
  706. elseif ClientConfig.is_use_model_render or self.model_type == UIModelCommon.ModelType.BackModel then
  707. self:SetUIbackRoleLayer(go.transform)
  708. elseif self.model_type == UIModelCommon.ModelType.Model then
  709. self:SetUILayer(go.transform)
  710. end
  711. if not effect_obj_type then
  712. local effect_sortingOrder = self:GetCurrLayerDepth(self.layer_name)
  713. UIDepth.SetUIDepth(go,false,effect_sortingOrder)
  714. end
  715. end
  716. lua_resM:loadPrefab(self, effect_vo.name, effect_vo.name, load_finish_func, false)
  717. end
  718. end
  719. function UIModelCommon:CreateWarSoulEffect( warSoul_effect_res,warSoul_effect_pos,warSoul_effect_scale )
  720. if self.deay_show_warSoul then
  721. GlobalTimerQuest:CancelQuest(self.deay_show_warSoul)
  722. self.deay_show_warSoul = nil
  723. end
  724. local function delay( )
  725. local function load_callback( ... )
  726. if warSoul_effect_scale then
  727. self.particle_mgr:SetEffectScale(self.warSoul_effect_id, warSoul_effect_scale)
  728. end
  729. if warSoul_effect_pos then
  730. self.particle_mgr:SetEffectLocalPos(self.warSoul_effect_id, warSoul_effect_pos.x,warSoul_effect_pos.y,warSoul_effect_pos.z)
  731. end
  732. local effect = self.particle_mgr:GetEffect(self.warSoul_effect_id)
  733. local root_dummy_node = FindBone(self.role.transform, "Dummy001")
  734. -- self.transform.localRotation = Quaternion.Euler(0, 0, 0)
  735. if root_dummy_node and effect then
  736. effect.transform:SetParent(root_dummy_node)
  737. -- effect.localPosition = warSoul_effect_pos or Vector3.zero
  738. effect.transform.localRotation = Quaternion.Euler(0, 180, 0)
  739. -- effect.localScale = Vector3.one
  740. end
  741. end
  742. self.warSoul_effect_id = self.particle_mgr:AddTargetEffect(warSoul_effect_res, self.role, true, nil, nil, 7, nil,nil,nil,nil,"UI" or self.layer_name,load_callback,nil,nil,nil,nil,warSoul_effect_pos)
  743. if self.particle_list and self.warSoul_effect_id then
  744. self.particle_list[self.warSoul_effect_id] = self.warSoul_effect_id
  745. end
  746. end
  747. self.deay_show_warSoul = setTimeout(delay,0.01)
  748. end
  749. --创建足迹
  750. function UIModelCommon:CreateFootmark(footmark_id)
  751. end
  752. function UIModelCommon:PlaySkillEffect(attacker, skill_id, next_anim, custom_end_callback)
  753. if attacker and skill_id and SkillManager and SkillManager.Instance then
  754. --正在播放技能中
  755. if self.duration_timer then return end
  756. local movie_cfg = SkillManager.Instance:GetFightSkillMovie(skill_id)
  757. if movie_cfg then
  758. if movie_cfg.anim then
  759. if self.skill_preview_callback then
  760. self.skill_preview_callback(1)
  761. end
  762. local action_name = {[1] = movie_cfg.anim,}
  763. self:PlayActions(action_name)
  764. local duration_time = movie_cfg.back_swing and movie_cfg.back_swing or 2
  765. self:StopSkillPreViewTimer()
  766. local function PlaySkillEffectEnd()
  767. if self.skill_preview_callback then
  768. self:PlayActions({[1] = "idle",})
  769. self.skill_preview_callback(2)
  770. elseif next_anim then
  771. self:PlayActions({[1] = next_anim,})
  772. end
  773. if custom_end_callback then
  774. custom_end_callback()
  775. end
  776. self:StopSkillPreViewTimer()
  777. end
  778. self.duration_timer = GlobalTimerQuest:AddDelayQuest(PlaySkillEffectEnd,duration_time)
  779. end
  780. if movie_cfg.particles then
  781. for i = 1, #movie_cfg.particles do
  782. local cfg = movie_cfg.particles[i]
  783. local res = cfg.res
  784. local x, y = attacker.transform.position.x, attacker.transform.position.y
  785. local dir = GameMath.AngleToDirection(270 - self.rotate)
  786. local scale = cfg.scale
  787. local attach_type = cfg.attach_type
  788. local play_time = cfg.play_time
  789. if cfg.custom_angle then
  790. dir = GameMath.AngleToDirection(cfg.custom_angle)
  791. end
  792. local pos_type = cfg.pos_type
  793. --所有特效都是特定播放轨迹,所以这里简单的都从人物跟节点发出
  794. pos_type = 0
  795. self.particle_mgr:AddUIModelEffect( res, self, false, play_time, attach_type,dir, nil,nil,nil,nil,nil,false)
  796. -- --播放特效方法1
  797. -- self.particle_mgr:AddUIModelEffect(res,self,true,nil,attach_type,nil,nil,nil,nil,nil,false)
  798. --播放后特效方法2
  799. -- local particle_id = nil
  800. -- if pos_type == 2 or pos_type == 6 then --在攻击者坐标上
  801. -- if cfg.offset_dist and cfg.offset_dist ~= 0 and dir then
  802. -- co.NormaliseXYTable(dir)
  803. -- local dist = GameMath.ChangeEllipseValue(dir, cfg.offset_dist)
  804. -- x = x + dir.x * dist
  805. -- y = y + dir.y * dist
  806. -- end
  807. -- particle_id = self.particle_mgr:AddPosEffect( res, co.TableXY(x, y), (play_time ~= 0), play_time, dir ,nil, nil, nil, nil, nil, max_depth)
  808. -- elseif pos_type == 7 then --特效沿攻击方向移动
  809. -- local move_speed = cfg.move_speed or 100
  810. -- local move_dist = cfg.move_dist or 300
  811. -- particle_id = self.particle_mgr:AddPosEffect( res, co.TableXY(x, y), true, 0 , dir, nil, nil, move_speed, move_dist, nil, max_depth)
  812. -- else
  813. -- particle_id = self.particle_mgr:AddTargetEffect(res, attacker, (play_time ~= 0), play_time, dir, attach_type, nil, nil, nil, max_depth)
  814. -- end
  815. -- if particle_id then
  816. -- if cfg.scale then
  817. -- self.particle_mgr:SetEffectScale(particle_id, cfg.scale)
  818. -- end
  819. -- self.particle_list[particle_id] = true
  820. -- end
  821. end
  822. end
  823. end
  824. end
  825. end
  826. function UIModelCommon:CreateEffect(obj_type, id, parent_go, action_name, effect_obj_type)
  827. if effect_obj_type then
  828. obj_type = effect_obj_type
  829. end
  830. if obj_type == SceneBaseType.Role or obj_type == SceneBaseType.MapModel then
  831. return
  832. end
  833. -- RT加载怪物模型时不加载一切特效
  834. if obj_type == SceneBaseType.Monster and self.model_type == UIModelCommon.ModelType.RT then
  835. return
  836. end
  837. self.cache_effect_list = self.cache_effect_list or {}
  838. local cache_effect_type = action_name and obj_type .. "_action" or obj_type
  839. if self.cache_effect_list[cache_effect_type] then
  840. for k,v in pairs(self.cache_effect_list[cache_effect_type]) do
  841. destroy(v.go)
  842. end
  843. end
  844. self.cache_effect_list[cache_effect_type] = {}
  845. local parent_go = parent_go or self.transform
  846. --武器要区分职业
  847. -- if obj_type and obj_type == SceneBaseType.FWeapon then
  848. -- print('=======Msh:UIModelCommon.lua[851] =======', id, action_name)
  849. -- PrintCallStack()
  850. -- end
  851. if obj_type and obj_type == SceneBaseType.FWeapon and id and tonumber(id) < 1000 then
  852. local career = self.career
  853. if not career and RoleManager.Instance and RoleManager.Instance.mainRoleInfo then
  854. career = RoleManager.Instance.mainRoleInfo.career
  855. end
  856. career = career or 1
  857. id = tonumber(id) + career*1000
  858. end
  859. local temp_cfg = Config.SceneObjectParticle[obj_type] and Config.SceneObjectParticle[obj_type][id]
  860. if action_name and action_name ~= "" then
  861. --动作特效
  862. temp_cfg = temp_cfg and temp_cfg.action_effect_list
  863. temp_cfg = temp_cfg and temp_cfg[action_name]
  864. -- self.last_action_effect_list = self.last_action_effect_list or {}
  865. else
  866. --模型特效
  867. temp_cfg = temp_cfg and temp_cfg.body_effect_list
  868. local temp_id = obj_type.."_"..id
  869. if self.last_effect_id and self.last_effect_id == temp_id then
  870. return
  871. end
  872. self.last_effect_id = temp_id
  873. end
  874. if not temp_cfg then
  875. return
  876. end
  877. local function on_load_res( bone_name, effect_vo )
  878. if not parent_go then
  879. return
  880. end
  881. local bone = FindBone(parent_go and parent_go.transform or self.transform, bone_name)
  882. if bone or effect_vo.is_world_particle then
  883. local function load_finish_func(objs, is_gameObject)
  884. if not objs or not objs[0] then
  885. return
  886. end
  887. if IsNull(bone) then
  888. if is_gameObject then destroy(objs[0]) end
  889. return
  890. end
  891. local go = is_gameObject and objs[0] or newObject(objs[0])
  892. table.insert(self.cache_effect_list[cache_effect_type], {go = go})
  893. if effect_vo.is_world_particle then
  894. AttachGameRoot(go.transform)
  895. else
  896. go.transform:SetParent(bone)
  897. end
  898. SetLocalPosition(go.transform)
  899. SetLocalRotation(go.transform)
  900. SetLocalScale(go.transform, 1)
  901. if effect_obj_type or (self.model_data and self.model_data.attach_game_root) then
  902. self:SetUILayer(go.transform, UIPartical.RenderingOther_List.DEFAULT)
  903. elseif ClientConfig.is_use_model_render or self.model_type == UIModelCommon.ModelType.BackModel then
  904. self:SetUIbackRoleLayer(go.transform)
  905. elseif self.model_type == UIModelCommon.ModelType.Model then
  906. self:SetUILayer(go.transform)
  907. end
  908. if not effect_obj_type then
  909. local effect_sortingOrder = self:GetCurrLayerDepth(self.layer_name)
  910. UIDepth.SetUIDepth(go,false,effect_sortingOrder)
  911. end
  912. end
  913. lua_resM:loadPrefab(self, effect_vo.name, effect_vo.name, load_finish_func, false)
  914. end
  915. end
  916. for key, effect_vo in pairs(temp_cfg) do
  917. local bone_name = effect_vo.bone
  918. if obj_type and obj_type == SceneBaseType.FWeapon then
  919. for k,v in pairs(self.weapon_container) do
  920. parent_go = v.go
  921. on_load_res(bone_name, effect_vo)
  922. end
  923. else
  924. on_load_res(bone_name, effect_vo)
  925. end
  926. end
  927. end
  928. --主动添加挂在自己身上的例子特效
  929. function UIModelCommon:AddParticle(id,particle_tranform,attach_type,is_weapon,effect_pos)
  930. if self._use_delete_method then
  931. return
  932. end
  933. if is_weapon then
  934. if self.weapon then
  935. local effect_root = self.weapon.transform:Find("Bone_wq")
  936. if effect_root then
  937. particle_tranform.parent = effect_root
  938. particle_tranform.localPosition = effect_pos or Vector3.zero
  939. particle_tranform.localRotation = Quaternion.Euler(0, 0, 0)
  940. particle_tranform.localScale = Vector3.one
  941. self.particle_list[id] = particle_tranform
  942. local effect = self.particle_mgr:GetEffect(id)
  943. if effect then
  944. effect:SetSpeed(self.particle_speed)
  945. end
  946. end
  947. end
  948. else
  949. local bone_name = ParticleAttachNode[attach_type]
  950. local transform = self.role
  951. if bone_name and transform then
  952. local bone = nil
  953. if bone_name == AttachNode.SceneObj then
  954. bone = transform
  955. else
  956. bone = FindBone(self.role.transform,bone_name)
  957. end
  958. if bone == nil then
  959. logWarn("AddParticle ".. transform.name .." cannot find bone " .. bone_name)
  960. return
  961. end
  962. particle_tranform.parent = bone.transform
  963. particle_tranform.localPosition = effect_pos or Vector3.zero
  964. if bone_name == AttachNode.SceneObj then
  965. particle_tranform.localRotation = Quaternion.Euler(self.rotateX, 0, 0)
  966. else
  967. particle_tranform.localRotation = Quaternion.Euler(0, 0, 0)
  968. end
  969. particle_tranform.localScale = Vector3.one
  970. self.particle_list[id] = particle_tranform
  971. local effect = self.particle_mgr:GetEffect(id)
  972. if effect then
  973. effect:SetSpeed(self.particle_speed)
  974. end
  975. end
  976. end
  977. end
  978. --删除挂在伙伴身上的特效
  979. --is_acive = false 被动删除挂在自己身上的粒子特效 由特效播放完来调用
  980. --is_acive = true 主动删除挂在自己身上的特效 会通知particlemanager去删除 默认false
  981. function UIModelCommon:RemoveParticle(id,is_acive)
  982. self.particle_list[id] = nil
  983. if is_acive then
  984. self.particle_mgr:DelEffect(id)
  985. end
  986. end
  987. function UIModelCommon:CheckShadow(go, name)
  988. --先不处理
  989. if true then
  990. return
  991. end
  992. if not go or not self.show_shadow then
  993. return
  994. end
  995. local scene_info =
  996. {
  997. shadow_angle = 60,
  998. shadow_alpha = 0.7,
  999. shadow_len = 7,
  1000. }
  1001. local scale = scene_info.shadow_len / 7
  1002. local light_x = math.cos(scene_info.shadow_angle * math.pi / 180) * scale
  1003. local light_z = (math.sin(scene_info.shadow_angle * math.pi / 180)) * scale
  1004. local shadow2_mat_light_vector4 = self.model_data.shadow2_light_pos or Vector4(light_x, -1, light_z, 0)
  1005. --local shadow2_mat_plane_vector4 = Vector4(0, 1, 0, 0.5)
  1006. local shadow2_mat_plane_vector4 = self.model_data.shadow2_plane_pos or Vector4(0, 1, 0, 0.5)
  1007. local render = go:GetComponentInChildren(typeof(UnityEngine.SkinnedMeshRenderer)) or go:GetComponentInChildren(typeof(UnityEngine.MeshRenderer))
  1008. if render then
  1009. local mats = render.sharedMaterials
  1010. local lua_mats = {}
  1011. local shadow_index = nil
  1012. local mats_len = mats.Length
  1013. local need_create_shadow = true
  1014. local change = false
  1015. for i = 0, mats_len - 1 do
  1016. lua_mats[i + 1] = mats[i]
  1017. if IsNull(mats[i]) then
  1018. shadow_index = i + 1
  1019. elseif string.find(mats[i].name, "shadow2", 1, true) then
  1020. mats[i]:SetVector("_LightDir", shadow2_mat_light_vector4)
  1021. mats[i]:SetFloat("_ShadowAlpha", scene_info.shadow_alpha)
  1022. mats[i]:SetVector("_Plane", shadow2_mat_plane_vector4)
  1023. -- self.shadow_timer_list[name] = {shadow2_mat_plane_vector4 = shadow2_mat_plane_vector4,material = mats[i]}
  1024. need_create_shadow = false
  1025. elseif mats[i].shader.name == "Unlit/Texture" or string.find(mats[i].shader.name, "XRay", 1, true) then
  1026. mats[i].shader = ShaderTools.GetShader("Unlit-Texture-NoFog")
  1027. change = true
  1028. end
  1029. end
  1030. if not shadow_index then
  1031. shadow_index = mats_len + 1
  1032. end
  1033. if not lua_mats[shadow_index] and need_create_shadow then
  1034. local shadow2_mat = Material.New(ShaderTools.shadow2)
  1035. shadow2_mat:SetVector("_LightDir", shadow2_mat_light_vector4)
  1036. shadow2_mat:SetFloat("_ShadowAlpha", scene_info.shadow_alpha)
  1037. shadow2_mat:SetVector("_Plane", shadow2_mat_plane_vector4)
  1038. -- self.shadow_timer_list[name] = {shadow2_mat_plane_vector4 = shadow2_mat_plane_vector4,material = shadow2_mat}
  1039. lua_mats[shadow_index] = shadow2_mat
  1040. change = true
  1041. end
  1042. if change then
  1043. render.materials = lua_mats
  1044. end
  1045. end
  1046. end
  1047. --主动删除挂在伙伴身上的特效
  1048. function UIModelCommon:RemoveAllParticle()
  1049. for id,_ in pairs(self.particle_list) do
  1050. self.particle_mgr:DelEffect(id)
  1051. end
  1052. self.particle_list = {}
  1053. end
  1054. function UIModelCommon:GetCacheBones(transform, bone_name)
  1055. self.cache_bones = self.cache_bones or {}
  1056. local temp_bone = self.cache_bones[bone_name]
  1057. if temp_bone and not IsNull(temp_bone) then
  1058. return temp_bone
  1059. end
  1060. local transform = transform or self.transform
  1061. temp_bone = FindBone(transform, bone_name)
  1062. self.cache_bones[bone_name] = temp_bone
  1063. return temp_bone
  1064. end
  1065. function UIModelCommon:StopSkillPreViewTimer()
  1066. if self.duration_timer then
  1067. GlobalTimerQuest:CancelQuest(self.duration_timer)
  1068. self.duration_timer = nil
  1069. end
  1070. end
  1071. function UIModelCommon:GetRolePositionOffset()
  1072. local pos = Vector3(0, 0, 0)
  1073. if self.role_position_offset and (self.type == SceneBaseType.Role or self.type == SceneBaseType.MainRole) and self.clothe_res_id then
  1074. local career = 0
  1075. career = math.floor(self.clothe_res_id / 1000 )
  1076. if career and UIModelClassByRT.Role_Position_Offset[career] then
  1077. pos = UIModelClassByRT.Role_Position_Offset[career]
  1078. end
  1079. end
  1080. return pos
  1081. end
  1082. function UIModelCommon:ChangeModelLocalPosition(x, y, z)
  1083. if not self.role then return end
  1084. local offset = self:GetRolePositionOffset()
  1085. x = x or (self.role.transform.localPosition.x - offset.x)
  1086. y = y or (self.role.transform.localPosition.y - offset.y)
  1087. z = z or (self.role.transform.localPosition.z - offset.z)
  1088. self.role.transform.localPosition = Vector3(x, y, z) + offset
  1089. end
  1090. function UIModelCommon:GetModelDefaultLocalPosition( )
  1091. return self.default_position
  1092. end
  1093. function UIModelCommon:SetData(parent,model_data)
  1094. end
  1095. function UIModelCommon:LoadRole(model_data, role_con)
  1096. self.role_con = role_con
  1097. self.model_data = model_data
  1098. self.career = model_data.career
  1099. self.clothe_res_id = model_data.clothe_res_id
  1100. self.weapon_res_id = model_data.weapon_res_id
  1101. self.weapon_clothe_id = model_data.weapon_clothe_id
  1102. self.type = model_data.role_type or model_data.type or nil
  1103. self.size = model_data.size or Vector2(600,360)
  1104. model_data.action_name_list = model_data.action_name_list or {"show"}
  1105. self.action_name_list = model_data.action_name_list
  1106. self.replay_action_name = self.action_name_list[#self.action_name_list] or "show"
  1107. self.can_rotate = model_data.can_rotate == nil or model_data.can_rotate == true
  1108. self.scale = model_data.scale
  1109. self.position = model_data.position
  1110. self.fashion_model_id = model_data.fashion_model_id
  1111. self.texture_id = model_data.texture_id
  1112. self.action_delta = model_data.action_delta
  1113. self.renderSize = model_data.renderSize
  1114. self.partner_id = model_data.partner_id
  1115. self.skill_id = model_data.skill_id
  1116. self.lCallBack = model_data.lCallBack
  1117. self.wing_id = model_data.wing_id
  1118. self.image_id = model_data.image_id
  1119. self.head_wear_id = model_data.head_wear_id
  1120. self.head_clothe_id = model_data.head_clothe_id
  1121. self.footmark_id = model_data.footmark_id
  1122. self.light_id = model_data.light_id
  1123. self.warSoul_effect_res = model_data.warSoul_effect_res
  1124. self.warSoul_effect_pos = model_data.warSoul_effect_pos
  1125. self.warSoul_effect_scale = model_data.warSoul_effect_scale
  1126. self.use_bloom = model_data.use_bloom
  1127. self.free_param = model_data.free_param
  1128. self.pearl_vo = model_data.pearl_vo
  1129. self.pearl_pos = model_data.pearl_pos
  1130. self.rotate = model_data.rotate or 0
  1131. if self.type == SceneBaseType.Include_Horse then--self.free_param为契兽id
  1132. self.weapon_res_id = nil--坐骑上不要武器
  1133. end
  1134. if model_data.load_dance_pose then -- 如果是加载跳舞的模型,需要屏蔽武器
  1135. self.weapon_res_id = nil
  1136. end
  1137. -- self.bloom_camera = self.gameObject.transform:Find("Camera/BloomClipCamera"):GetComponent("Camera")
  1138. self.skill_preview = model_data.skill_preview
  1139. self.skill_preview_callback = model_data.skill_preview_callback
  1140. self.camera_args = model_data.camera_args
  1141. self.using_material = model_data.using_material --or "render_texture"
  1142. self.using_sprite_bg = model_data.using_sprite_bg
  1143. self.role_position_offset = model_data.role_position_offset
  1144. self.layer_name = model_data.layer_name or "UI"
  1145. self.talisman_id = model_data.talisman_id
  1146. self.show_reflection = model_data.show_reflection
  1147. self.reflect_pos = model_data.reflect_pos
  1148. self.show_root = model_data.show_root == nil and true or model_data.show_root
  1149. self.hat_wear_id = model_data.hat_wear_id
  1150. self.dynamic_bone = model_data.dynamic_bone
  1151. self.use_light_data = model_data.use_light_data
  1152. self.psionic_effect = model_data.psionic_effect -- 圣物光环特效
  1153. self.pokemon_diamond_effect = model_data.pokemon_diamond_effect --宠物宝石光环特效
  1154. self.show_baby_attack_effect = model_data.show_baby_attack_effect -- 宝宝攻击特效
  1155. self.show_jarvis_all_figure_data = model_data.show_jarvis_all_figure_data -- ai娘模型展示包括翅膀磁炮幻甲全套装备,如有需要使用请参考排行榜传参
  1156. self.effect_obj_type = model_data.effect_obj_type --特效主体类型
  1157. self.role_action_sound = model_data.role_action_sound
  1158. self.need_play_skill_effect = 101091 or model_data.need_play_skill_effect
  1159. self.do_not_main_role_cloth_res_change = model_data.do_not_main_role_cloth_res_change--时装更改广播之后,不要刷新uimodelcommon的改变
  1160. local anName,resName = GameResPath.GetModelClotheRes(self.type, self.clothe_res_id, self.dynamic_bone)
  1161. if self.fashion_model_id then --时装
  1162. anName,resName = GameResPath.GetModelClotheRes(self.type, self.fashion_model_id, self.dynamic_bone)
  1163. elseif self.type == SceneBaseType.Baby_Include_Horse then -- 宝宝骑载具
  1164. anName,resName = GameResPath.GetModelClotheRes(SceneBaseType.Baby, self.clothe_res_id, self.dynamic_bone)
  1165. end
  1166. local function loadRoleCallback(objs, is_gameObject)
  1167. if self._use_delete_method then
  1168. return
  1169. end
  1170. if not objs or not objs[0] then
  1171. return
  1172. end
  1173. self:RemoveAllParticle()
  1174. if self.role then
  1175. destroy(self.role)
  1176. end
  1177. self.role = is_gameObject and objs[0] or newObject(objs[0])
  1178. local animator = self.role:GetComponent("Animator")
  1179. if not IsNull(animator) then
  1180. local custom_speed = Config.ConfigModelSpeed.ModelActionSpeed[tonumber(self.clothe_res_id)]
  1181. if custom_speed then
  1182. if animator then
  1183. animator.speed = custom_speed
  1184. end
  1185. end
  1186. if self.type == SceneBaseType.Role or self.type == SceneBaseType.MainRole then
  1187. if animator then
  1188. self.custom_speed = Config.ConfigModelSpeed.MainRoleActionSpeed.Idle
  1189. animator.speed = self.custom_speed
  1190. end
  1191. end
  1192. animator.cullingMode = UnityEngine.AnimatorCullingMode.AlwaysAnimate
  1193. end
  1194. if ClientConfig.is_use_model_render or self.model_type == UIModelCommon.ModelType.Model or self.model_type == UIModelCommon.ModelType.BackModel then
  1195. self.role.transform:SetParent(self.parent.transform)
  1196. else
  1197. self.role.transform:SetParent(role_con)
  1198. end
  1199. self.role.transform.localRotation = self.model_data.model_rotation and Quaternion.Euler(self.model_data.model_rotation) or Quaternion.identity
  1200. self.transform = self.role.transform
  1201. self.role.gameObject:SetActive(self.show_root)
  1202. if self.type == SceneBaseType.Include_Horse or --self.free_param为契兽id
  1203. self.type == SceneBaseType.Baby_Include_Horse then -- 普通载具或宝宝载具
  1204. local horse_abName,horse_resName
  1205. if self.type == SceneBaseType.Baby_Include_Horse then -- 宝宝载具
  1206. horse_abName,horse_resName = GameResPath.GetModelClotheRes(SceneBaseType.Baby_Horse, self.free_param)
  1207. elseif self.type == SceneBaseType.Include_Horse then -- 普通载具
  1208. horse_abName,horse_resName = GameResPath.GetModelClotheRes(SceneBaseType.Horse, self.free_param)
  1209. end
  1210. local function loadHorseCallback(objs, is_gameObject)
  1211. if self._use_delete_method then
  1212. return
  1213. end
  1214. if not objs or not objs[0] then
  1215. return
  1216. end
  1217. if self.horse_gameObject then
  1218. destroy(self.horse_gameObject)
  1219. end
  1220. self.horse_gameObject = is_gameObject and objs[0] or newObject(objs[0])
  1221. self.horse_transform = self.horse_gameObject.transform
  1222. self.horse_gameObject:GetComponent("Animator").cullingMode = UnityEngine.AnimatorCullingMode.AlwaysAnimate
  1223. self.horse_transform.localScale = Vector3.one
  1224. if ClientConfig.is_use_model_render or self.model_type == UIModelCommon.ModelType.Model or self.model_type == UIModelCommon.ModelType.BackModel then
  1225. self.horse_transform:SetParent(self.parent.transform)
  1226. else
  1227. self.horse_transform:SetParent(role_con)
  1228. end
  1229. self.horse_transform.localPosition = Vector3.zero
  1230. if self.position then
  1231. self.horse_transform.localPosition = Vector3(self.position.x, self.position.y,self.position.z)
  1232. else
  1233. self.horse_transform.localPosition = Vector3.zero
  1234. end
  1235. if self.scale then
  1236. self.horse_transform.localScale = Vector3(self.scale*50,self.scale*50,self.scale*50)
  1237. else
  1238. self.horse_transform.localScale = Vector3.one
  1239. end
  1240. if self.transform then
  1241. local bone = FindBone(self.horse_transform, AttachNode.Ride)
  1242. if bone == nil then
  1243. return
  1244. end
  1245. self.transform:SetParent(bone)
  1246. self.transform.localPosition = Vector3.zero
  1247. self.transform.localScale = Vector3.one
  1248. self.transform.localRotation = Quaternion.Euler(Vector3.zero)
  1249. end
  1250. local rotate_type = type(self.rotate)
  1251. if rotate_type == "number" then
  1252. self.horse_transform:Rotate(Vector3(0, 270 + (self.rotate), 0))
  1253. elseif rotate_type == "table" then
  1254. self.horse_transform:Rotate(self.rotate)
  1255. else
  1256. self.horse_transform:Rotate(Vector3(0, self.rotate, 0))
  1257. end
  1258. if ClientConfig.is_use_model_render or self.model_type == UIModelCommon.ModelType.BackModel then
  1259. self:SetUIbackRoleLayer(self.parent.transform)
  1260. elseif self.model_type == UIModelCommon.ModelType.Model then
  1261. self:SetUILayer(self.parent.transform)
  1262. end
  1263. --部件特效,参数为部件类型与id
  1264. if self.type ~= SceneBaseType.Baby_Include_Horse then
  1265. self:CreateEffect(SceneBaseType.Horse, self.free_param, self.horse_gameObject)
  1266. self:SetParticleDepth(self.horse_gameObject)
  1267. end
  1268. local horse_animator = self.horse_gameObject:GetComponent("Animator")
  1269. self.horse_animator = horse_animator
  1270. if self.horse_action_name then
  1271. self.horse_animator:CrossFade(self.horse_action_name, 0, 0, 0)
  1272. end
  1273. --有坐骑的,加载完坐骑,才执行回调
  1274. if self.lCallBack then self.lCallBack(self) end
  1275. end
  1276. LuaResManager:getInstance():loadPrefab(self,horse_abName,horse_resName, loadHorseCallback)
  1277. end
  1278. if self.model_data.attach_game_root then
  1279. AttachGameRoot(self.role.transform)
  1280. end
  1281. if ClientConfig.is_use_model_render or self.model_type == UIModelCommon.ModelType.BackModel then
  1282. if self.type == SceneBaseType.Include_Horse or
  1283. self.type == SceneBaseType.Baby_Include_Horse then
  1284. self.role.transform.localPosition = Vector3.zero
  1285. else
  1286. self.role.transform.localPosition = self.position or Vector3(0,75,-300)
  1287. end
  1288. elseif self.model_type == UIModelCommon.ModelType.Model then
  1289. if self.type == SceneBaseType.Include_Horse or
  1290. self.type == SceneBaseType.Baby_Include_Horse then
  1291. self.role.transform.localPosition = Vector3.zero
  1292. else
  1293. if self.position then
  1294. self.role.transform.localPosition = self.position
  1295. else
  1296. self.role.transform.localPosition = Vector3.zero
  1297. end
  1298. end
  1299. else
  1300. if self.type == SceneBaseType.Include_Horse or
  1301. self.type == SceneBaseType.Baby_Include_Horse then
  1302. self.role.transform.localPosition = Vector3.zero
  1303. else
  1304. if self.position and not self.show_shadow then
  1305. self.role.transform.localPosition = self.position + self:GetRolePositionOffset()
  1306. else
  1307. if self.show_shadow then
  1308. self.role.transform.localPosition = Vector3(0, 119, 0) + self:GetRolePositionOffset()
  1309. else
  1310. self.role.transform.localPosition = Vector3.zero + self:GetRolePositionOffset()
  1311. end
  1312. end
  1313. end
  1314. end
  1315. if ClientConfig.is_use_model_render or self.model_type == UIModelCommon.ModelType.BackModel then
  1316. self:SetUIbackRoleLayer(self.parent.transform)
  1317. elseif self.model_type == UIModelCommon.ModelType.Model then
  1318. self:SetUILayer(self.parent.transform)
  1319. -- if self.type == SceneBaseType.Equip or self.type == SceneBaseType.FWing or self.type == SceneBaseType.MainRole then
  1320. local shinned_meshRender_com_list = self.role:GetComponentsInChildren(typeof(UnityEngine.SkinnedMeshRenderer),true)
  1321. if shinned_meshRender_com_list.Length > 0 then
  1322. for i=1,shinned_meshRender_com_list.Length do
  1323. shinned_meshRender_com_list[i-1].sortingOrder = self:GetCurrLayerDepth(self.layer_name)
  1324. -- shinned_meshRender_com_list[i-1].sortingOrder = self:GetCurrLayerDepth(self.layer_name)+1
  1325. end
  1326. end
  1327. -- end
  1328. end
  1329. -- 保存一次默认坐标
  1330. self.default_position = self.default_position or self.role.transform.localPosition
  1331. if self.scale then
  1332. if self.type == SceneBaseType.Include_Horse or
  1333. self.type == SceneBaseType.Baby_Include_Horse then
  1334. --如果是坐骑模式,这里不要重新设置角色的scale,否则会导致大人开小车或小人开大车的情况
  1335. else
  1336. self.role.transform.localScale = Vector3(self.scale,self.scale,self.scale)
  1337. end
  1338. else
  1339. self.role.transform.localScale = Vector3(100,100,100)
  1340. end
  1341. if self.type == SceneBaseType.Include_Horse or
  1342. self.type == SceneBaseType.Baby_Include_Horse then
  1343. --如果是坐骑模式,也没必要再设置rotate了
  1344. else
  1345. local rotate_type = type(self.rotate)
  1346. if rotate_type == "number" then
  1347. local rotate_x = 0
  1348. if self.model_type == UIModelCommon.ModelType.Model and self.rotate == 0 then
  1349. rotate_x = 10
  1350. end
  1351. self.role.transform:Rotate(Vector3(rotate_x, 180 + (self.rotate), 0))
  1352. self.rotate = self.rotate or self.rotate
  1353. elseif rotate_type == "table" then
  1354. self.role.transform:Rotate(self.rotate)
  1355. self.rotate = self.rotate.y or self.rotate.y
  1356. else
  1357. self.role.transform:Rotate(Vector3(0, 180, 0))
  1358. self.rotate = self.rotate or 0
  1359. end
  1360. end
  1361. --主体模型特效,参数为主体的类型与id
  1362. self:CreateEffect(self.type, self.clothe_res_id, nil, nil, self.effect_obj_type)
  1363. local real_model = self.role.gameObject.transform:Find(resName)
  1364. if real_model then
  1365. self:CheckShadow(real_model, resName)
  1366. end
  1367. local action_delta = model_data.action_delta
  1368. local action_name_list = model_data.action_name_list
  1369. if not IsTableEmpty(action_name_list) then
  1370. local action_name = action_delta and action_name_list[1] or table.remove(action_name_list, 1)
  1371. if action_name then
  1372. local animator = self.role:GetComponent("Animator")
  1373. if IsNull(animator) then
  1374. return
  1375. end
  1376. --用来判断是否是骑着马的
  1377. if self.type == SceneBaseType.Include_Horse then
  1378. local ride_action_cfg = Config.otherFightInfo.on_horse_action[self.free_param] or Config.otherFightInfo.on_horse_action[0]
  1379. self.horse_action_name = action_name
  1380. if self.horse_animator then
  1381. self.horse_animator:CrossFade(action_name, 0, 0, 0)
  1382. end
  1383. if action_name == "idle" or action_name == "casual" or action_name == "hited" or action_name == "show" then
  1384. if ride_action_cfg then
  1385. self.curr_body_action_name = ride_action_cfg.idle_action
  1386. else
  1387. self.curr_body_action_name = "ride"
  1388. end
  1389. elseif action_name == "run" or action_name == "fly" then
  1390. if ride_action_cfg then
  1391. self.curr_body_action_name = ride_action_cfg.run_action
  1392. else
  1393. self.curr_body_action_name = "riderun"
  1394. end
  1395. end
  1396. elseif self.type == SceneBaseType.Baby_Include_Horse then -- 宝宝坐骑
  1397. local ride_action_cfg = Config.otherFightInfo.on_baby_horse_action[self.free_param] or Config.otherFightInfo.on_baby_horse_action[0]
  1398. self.horse_action_name = action_name
  1399. if self.horse_animator then
  1400. self.horse_animator:CrossFade(action_name, 0, 0, 0)
  1401. end
  1402. if action_name == "idle" or action_name == "casual" or action_name == "hited" or action_name == "show" then
  1403. if ride_action_cfg then
  1404. self.curr_body_action_name = ride_action_cfg.idle_action
  1405. else
  1406. self.curr_body_action_name = "ride"
  1407. end
  1408. elseif action_name == "run" or action_name == "fly" then
  1409. if ride_action_cfg then
  1410. self.curr_body_action_name = ride_action_cfg.run_action
  1411. else
  1412. self.curr_body_action_name = "ride"
  1413. end
  1414. end
  1415. else
  1416. self.curr_body_action_name = action_name
  1417. end
  1418. --动作音效
  1419. if self.role_action_sound then
  1420. lua_soundM:PlayEffect(self, self.role_action_sound, false, LuaSoundManager.SOUND_TYPE.ROLE, 1)
  1421. end
  1422. --动作
  1423. animator:CrossFade(self.curr_body_action_name,0, 0.0 )
  1424. --动作特效
  1425. self:CreateEffect(self.type, self.clothe_res_id, self.role, self.curr_body_action_name)
  1426. if not IsTableEmpty(action_name_list) then
  1427. self.delay_play_action_timer_list = self.delay_play_action_timer_list or {}
  1428. if action_delta then
  1429. self:DelayPlayNextActionLoop(animator, action_name_list, action_delta)
  1430. else
  1431. self:DelayPlayNextAction(animator, action_name_list, model_data.delay_action_delta)
  1432. end
  1433. end
  1434. end
  1435. else
  1436. end
  1437. if self.weapon_res_id and self.weapon_res_id ~= 0 then
  1438. self:CreateWeapon(self.type, self.weapon_res_id, self.career, self.weapon_clothe_id)
  1439. self:CreateClothTexture(self.fashion_model_id, self.texture_id)
  1440. end
  1441. if self.pearl_vo then
  1442. self:CreatePearls(self.pearl_vo)
  1443. end
  1444. if self.wing_id then
  1445. self:CreateWing(SceneBaseType.FWing, self.wing_id)
  1446. end
  1447. if self.image_id then
  1448. self:CreateLivenessImage(self.type,self.image_id)
  1449. end
  1450. if self.head_wear_id then
  1451. self:CreateHeadWear(self.type, self.head_wear_id, self.head_clothe_id)
  1452. end
  1453. if self.hat_wear_id then
  1454. self:CreateHatWear(self.hat_wear_id)
  1455. end
  1456. if self.footmark_id then
  1457. self:CreateFootmark(self.footmark_id)
  1458. end
  1459. --针对怪物跟伙伴的贴图设置材质图片
  1460. if self.texture_id and (self.type == SceneBaseType.Partner or self.type == SceneBaseType.Monster or self.type == SceneBaseType.Npc or SceneBaseType.Horse) then
  1461. self:CreateClothTexture(self.clothe_res_id, self.texture_id)
  1462. end
  1463. if self.light_id and self.light_id > 0 then
  1464. --挂人物身上的幻光在这里加
  1465. self:CreateLightEffect(self.light_id)
  1466. end
  1467. if self.warSoul_effect_res and self.warSoul_effect_res ~= nil then
  1468. self:CreateWarSoulEffect(self.warSoul_effect_res,self.warSoul_effect_pos,self.warSoul_effect_scale)
  1469. end
  1470. --宝具
  1471. if self.talisman_id and self.talisman_id ~= 0 then
  1472. self:CreateTalisman(self.talisman_id)
  1473. end
  1474. self:SetCameraArgs()
  1475. -- if self.use_bloom then
  1476. -- self:CreateRoleBloomEffect(self.camera, self.bloom_camera)
  1477. -- end
  1478. --如果不是坐骑模式,才加载完人物模型返回加载回调
  1479. if self.type ~= SceneBaseType.Include_Horse or
  1480. self.type == SceneBaseType.Baby_Include_Horse then
  1481. if self.lCallBack then self.lCallBack(self) end
  1482. end
  1483. -- 发行需求 设置绿幕模式
  1484. self:UpdateModelGreenScreen()
  1485. --灯光参数
  1486. if self.use_light_data then
  1487. self:ApplyLightData()
  1488. end
  1489. -- 圣物光环特效
  1490. if self.psionic_effect then
  1491. local show_type = (self.model_type == UIModelCommon.ModelType.BackModel) and "UIBackRole" or "UI"
  1492. local function load_callback( ... )
  1493. if self.psionic_effect_id then
  1494. self.particle_mgr:SetEffectScale(self.psionic_effect_id, PsionicConst.EffectSize[self.psionic_effect])
  1495. self.particle_mgr:SetEffectOrder(self.psionic_effect_id, self:GetCurrLayerDepth(self.layer_name))
  1496. end
  1497. end
  1498. self.psionic_effect_id = self.particle_mgr:AddTargetEffect(self.psionic_effect, self.role, true, nil, nil, 7,nil,nil,1,nil,show_type,load_callback)
  1499. self.particle_list[self.psionic_effect_id] = self.psionic_effect_id
  1500. end
  1501. --宠物宝石光环特效
  1502. if self.type == SceneBaseType.Pokemon and self.pokemon_diamond_effect then
  1503. local show_type = (self.model_type == UIModelCommon.ModelType.BackModel) and "UIBackRole" or "UI"
  1504. self.pokemon_diamond_effect_id = self.particle_mgr:AddTargetEffect(self.pokemon_diamond_effect, self.role, true, nil, nil, 7,nil,nil,1,nil,show_type)
  1505. self.particle_list[self.pokemon_diamond_effect_id] = self.pokemon_diamond_effect_id
  1506. end
  1507. if self.show_baby_attack_effect then
  1508. local play_effect_func = function ( )
  1509. local show_type = (self.model_type == UIModelCommon.ModelType.BackModel) and "UIBackRole" or "UI"
  1510. local temp_cfg = ChildConst.SKILL_EFFECT_SHOW_CFG[self.show_baby_attack_effect] or {}
  1511. -- local scale = temp_cfg.scale or 0.5
  1512. self.show_baby_attack_effect_id = self.particle_mgr:AddTargetEffect(self.show_baby_attack_effect, self.role, false, nil, dir, 7,nil,nil,1,nil, show_type)
  1513. if temp_cfg.scale then
  1514. -- print('Msh:UIModelCommon.lua[1543] temp_cfg.scale', temp_cfg.scale)
  1515. self.particle_mgr:SetEffectScale(self.show_baby_attack_effect_id, temp_cfg.scale)
  1516. end
  1517. self.particle_list[self.show_baby_attack_effect_id] = self.show_baby_attack_effect_id
  1518. end
  1519. setTimeout(play_effect_func, 0.4)
  1520. end
  1521. --ai娘全套装备模型展示
  1522. if self.type == SceneBaseType.Pet and self.show_jarvis_all_figure_data then
  1523. self:CreateJarvisAll()
  1524. end
  1525. --技能特效
  1526. if self.need_play_skill_effect then
  1527. self:PlaySkillEffect(self.role, self.skill_id)
  1528. end
  1529. end
  1530. if self.type == SceneBaseType.FWeapon then
  1531. --创建左右手武器,单独显示用,不走上面的逻辑
  1532. local career = self.career or RoleManager.Instance.mainRoleInfo.career
  1533. local weapon_res_id = GameResPath:GetFWeaponResName( career,self.fashion_model_id or self.clothe_res_id )
  1534. local abName,weapon_attach_list,weapon_res_list = GameResPath.GetWeaponRes(SceneBaseType.FWeapon,weapon_res_id,career)
  1535. local function localWeaponCallback( objs, is_gameObject )
  1536. if self.weapon_container then
  1537. for k,v in pairs(self.weapon_container) do
  1538. destroy(v.go)
  1539. end
  1540. end
  1541. self:CreateWeaponOnly(objs, is_gameObject, weapon_attach_list)
  1542. -- 发行需求 设置绿幕模式
  1543. self:UpdateModelGreenScreen()
  1544. end
  1545. LuaResManager:getInstance():loadPrefabs(self,abName,weapon_res_list, localWeaponCallback)
  1546. else
  1547. LuaResManager:getInstance():loadPrefab(self,anName,resName, loadRoleCallback)
  1548. end
  1549. end
  1550. function UIModelCommon:SetCameraArgs(use_default)
  1551. end
  1552. ---------排行榜ai娘总榜把ai娘的磁炮星翼幻甲等全套装备一起展示出来-------------------------->>>>>>>
  1553. function UIModelCommon:CreateJarvisAll( )
  1554. self:CreateJarvisGun()--磁炮
  1555. self:CreateJarvisCloud()--星翼
  1556. self:CreateJarvisArmour()--幻甲
  1557. end
  1558. function UIModelCommon:CreateJarvisGun( )
  1559. if not self.show_jarvis_all_figure_data.f_gun_figure_id then return end
  1560. local abName, resName = GameResPath.GetModelClotheRes(SceneBaseType.FGun, self.show_jarvis_all_figure_data.f_gun_figure_id)
  1561. local function localGunCallback(objs, is_gameObject)
  1562. if self._use_delete_method then
  1563. return
  1564. end
  1565. if not objs or not objs[0] then
  1566. logWarn("cannot find wing res = "..self.show_jarvis_all_figure_data.f_gun_figure_id)
  1567. return
  1568. end
  1569. local go = is_gameObject and objs[0] or newObject(objs[0])
  1570. go:SetActive(true)
  1571. local bone = FindBone(self.role.transform, AttachNode.Root)
  1572. if bone == nil then
  1573. return
  1574. end
  1575. go.transform:SetParent(bone)
  1576. go.transform.localPosition = Vector3.zero
  1577. go.transform.localRotation = Quaternion.identity
  1578. go.transform.localScale = Vector3.one
  1579. if ClientConfig.is_use_model_render or self.model_type == UIModelCommon.ModelType.BackModel then
  1580. self:SetUIbackRoleLayer(self.parent.transform)
  1581. elseif self.model_type == UIModelCommon.ModelType.Model then
  1582. self:SetUILayer(self.parent.transform)
  1583. end
  1584. local animator = go:GetComponent("Animator")
  1585. if not IsNull(animator) then
  1586. animator.cullingMode = UnityEngine.AnimatorCullingMode.AlwaysAnimate
  1587. animator:CrossFade( "idle",0, 0.0 )
  1588. end
  1589. --部件特效,参数为部件类型与id
  1590. self:CreateEffect(SceneBaseType.FGun, self.show_jarvis_all_figure_data.f_gun_figure_id, go)
  1591. end
  1592. if self.role.transform and abName and resName then
  1593. LuaResManager:getInstance():loadPrefab(self,abName,resName, localGunCallback)
  1594. end
  1595. end
  1596. function UIModelCommon:CreateJarvisCloud( )
  1597. if not self.show_jarvis_all_figure_data.f_cloud_figure_id then return end
  1598. local abName, resName = GameResPath.GetModelClotheRes(SceneBaseType.FCloud, self.show_jarvis_all_figure_data.f_cloud_figure_id)
  1599. local function localWingCallback(objs, is_gameObject)
  1600. if self._use_delete_method then
  1601. return
  1602. end
  1603. if not objs or not objs[0] then
  1604. logWarn("cannot find wing res = "..self.show_jarvis_all_figure_data.f_cloud_figure_id)
  1605. return
  1606. end
  1607. local go = is_gameObject and objs[0] or newObject(objs[0])
  1608. go:SetActive(true)
  1609. local bone = FindBone(self.role.transform, AttachNode.Wing)
  1610. if bone == nil then
  1611. return
  1612. end
  1613. go.transform:SetParent(bone)
  1614. go.transform.localPosition = Vector3.zero
  1615. go.transform.localRotation = Quaternion.identity
  1616. go.transform.localScale = Vector3.one
  1617. if ClientConfig.is_use_model_render or self.model_type == UIModelCommon.ModelType.BackModel then
  1618. self:SetUIbackRoleLayer(self.parent.transform)
  1619. elseif self.model_type == UIModelCommon.ModelType.Model then
  1620. self:SetUILayer(self.parent.transform)
  1621. end
  1622. local animator = go:GetComponent("Animator")
  1623. if not IsNull(animator) then
  1624. animator.cullingMode = UnityEngine.AnimatorCullingMode.AlwaysAnimate
  1625. animator:CrossFade( "idle",0, 0.0 )
  1626. end
  1627. --部件特效,参数为部件类型与id
  1628. self:CreateEffect(SceneBaseType.FCloud, self.show_jarvis_all_figure_data.f_cloud_figure_id, go)
  1629. end
  1630. if self.role.transform and abName and resName then
  1631. LuaResManager:getInstance():loadPrefab(self,abName,resName, localWingCallback)
  1632. end
  1633. end
  1634. function UIModelCommon:CreateJarvisArmour( )
  1635. if not self.show_jarvis_all_figure_data.f_armour_figure_id then return end
  1636. local abName, resName = GameResPath.GetModelClotheRes(SceneBaseType.FArmour, self.show_jarvis_all_figure_data.f_armour_figure_id)
  1637. local function localWingCallback(objs, is_gameObject)
  1638. if self._use_delete_method then
  1639. return
  1640. end
  1641. if not objs or not objs[0] then
  1642. logWarn("cannot find wing res = "..self.show_jarvis_all_figure_data.f_armour_figure_id)
  1643. return
  1644. end
  1645. local go = is_gameObject and objs[0] or newObject(objs[0])
  1646. go:SetActive(true)
  1647. local bone = FindBone(self.role.transform, AttachNode.Root)
  1648. if bone == nil then
  1649. return
  1650. end
  1651. go.transform:SetParent(bone)
  1652. go.transform.localPosition = Vector3.zero
  1653. go.transform.localRotation = Quaternion.identity
  1654. go.transform.localScale = Vector3.one
  1655. if ClientConfig.is_use_model_render or self.model_type == UIModelCommon.ModelType.BackModel then
  1656. self:SetUIbackRoleLayer(self.parent.transform)
  1657. elseif self.model_type == UIModelCommon.ModelType.Model then
  1658. self:SetUILayer(self.parent.transform)
  1659. end
  1660. local animator = go:GetComponent("Animator")
  1661. if not IsNull(animator) then
  1662. animator.cullingMode = UnityEngine.AnimatorCullingMode.AlwaysAnimate
  1663. animator:CrossFade( "idle",0, 0.0 )
  1664. end
  1665. --部件特效,参数为部件类型与id
  1666. self:CreateEffect(SceneBaseType.FArmour, self.show_jarvis_all_figure_data.f_armour_figure_id, go)
  1667. end
  1668. if self.role.transform and abName and resName then
  1669. LuaResManager:getInstance():loadPrefab(self,abName,resName, localWingCallback)
  1670. end
  1671. end
  1672. ---------排行榜ai娘总榜把ai娘的磁炮星翼幻甲等全套装备一起展示出来--------------------------<<<<<<<<<<<<
  1673. function UIModelCommon:CreatePearls( vo )
  1674. if IsTableEmpty(vo) then
  1675. return
  1676. end
  1677. if self.transform and self.role.transform then
  1678. local info = vo
  1679. self.pearl_list = self.pearl_list or {}
  1680. self.pearl_parent = self.pearl_parent or {}
  1681. local ellipse_config = Config.otherFightInfo.PearlEllipse
  1682. local around_ellipse_config = Config.otherFightInfo.PearlUIEllipse
  1683. for i=1, #info do
  1684. if info[i] and info[i].type_id ~= 0 or info[i].skin_model_id then
  1685. local temp_pearl = self.pearl_list[i]
  1686. if not temp_pearl then
  1687. temp_pearl = GalaxyPearl.New(self.role.transform,ellipse_config,around_ellipse_config)
  1688. temp_pearl:SetStartPostion(1/#info * i)
  1689. self.pearl_list[i] = temp_pearl
  1690. end
  1691. temp_pearl:LoadPearlVo(self, false, info[i], false, info[i].skin_model_id, true)
  1692. end
  1693. end
  1694. end
  1695. end
  1696. --在人物旁边展示宝具
  1697. function UIModelCommon:CreateTalisman(talisman_id)
  1698. _type = SceneBaseType.FPearl
  1699. local abName, resName = GameResPath.GetModelClotheRes(_type, talisman_id)
  1700. local function localTalismanCallback(objs, is_gameObject)
  1701. if self._use_delete_method then
  1702. return
  1703. end
  1704. if not objs or not objs[0] then
  1705. logWarn("cannot find talisman res = "..self.talisman_id)
  1706. return
  1707. end
  1708. local go = is_gameObject and objs[0] or newObject(objs[0])
  1709. go:SetActive(true)
  1710. -- local bone = FindBone(self.role.transform, AttachNode.Wing)
  1711. -- if bone == nil then
  1712. -- return
  1713. -- end
  1714. go.transform:SetParent(self.role.transform)
  1715. go.transform.localPosition = Vector3(-0.8,0.6,-0.8)
  1716. go.transform.localRotation = Quaternion.identity
  1717. go.transform.localScale = Vector3.one
  1718. if ClientConfig.is_use_model_render or self.model_type == UIModelCommon.ModelType.BackModel then
  1719. self:SetUIbackRoleLayer(self.parent.transform)
  1720. elseif self.model_type == UIModelCommon.ModelType.Model then
  1721. self:SetUILayer(self.parent.transform)
  1722. end
  1723. local animator = go:GetComponent("Animator")
  1724. if not IsNull(animator) then
  1725. animator.cullingMode = UnityEngine.AnimatorCullingMode.AlwaysAnimate
  1726. animator:CrossFade( "idle",0, 0.0 )
  1727. end
  1728. --部件特效,参数为部件类型与id
  1729. self:CreateEffect(SceneBaseType.FPearl, self.talisman_id, go)
  1730. end
  1731. if self.role.transform and abName and resName then
  1732. LuaResManager:getInstance():loadPrefab(self,abName,resName, localTalismanCallback)
  1733. end
  1734. end
  1735. --创建左右手武器,单独显示用
  1736. function UIModelCommon:CreateWeaponOnly(objs,is_gameObject,weapon_attach_list)
  1737. if self._use_delete_method then return end
  1738. self.weapon_hand_list = self.weapon_hand_list or {}
  1739. self.weapon_container = {}
  1740. -------------------------
  1741. self:RemoveAllParticle()
  1742. if self.role then
  1743. destroy(self.role)
  1744. end
  1745. -------------------------
  1746. for i,v in ipairs(weapon_attach_list) do
  1747. if self.weapon_hand_list[i] then
  1748. destroy(self.weapon_hand_list[i])
  1749. end
  1750. if objs and objs[i - 1] then
  1751. self.weapon_hand_list[i] = is_gameObject and objs[i] or newObject(objs[i - 1])
  1752. self.weapon_container[i] = {go = self.weapon_hand_list[i]}
  1753. local animator = self.weapon_hand_list[i]:GetComponent("Animator")
  1754. if not IsNull(animator) then
  1755. local custom_speed = Config.ConfigModelSpeed.ModelActionSpeed[tonumber(self.clothe_res_id)]
  1756. if custom_speed then
  1757. if animator then
  1758. animator.speed = custom_speed
  1759. end
  1760. end
  1761. animator.cullingMode = UnityEngine.AnimatorCullingMode.AlwaysAnimate
  1762. end
  1763. local paredt_node = false
  1764. if ClientConfig.is_use_model_render or self.model_type == UIModelCommon.ModelType.Model or self.model_type == UIModelCommon.ModelType.BackModel then
  1765. paredt_node = self.parent.transform
  1766. else
  1767. paredt_node = self.role_con
  1768. end
  1769. self.weapon_hand_list[i].transform:SetParent(paredt_node)
  1770. -------------------------
  1771. if ClientConfig.is_use_model_render or self.model_type == UIModelCommon.ModelType.BackModel then
  1772. self:SetUIbackRoleLayer(paredt_node)
  1773. elseif self.model_type == UIModelCommon.ModelType.Model then
  1774. self:SetUILayer(paredt_node)
  1775. end
  1776. --角度,要反向
  1777. self.weapon_hand_list[i].transform.localRotation = Quaternion.Euler(Vector3(0,180,0))
  1778. --缩放
  1779. if self.scale then
  1780. self.weapon_hand_list[i].transform.localScale = Vector3(self.scale,self.scale,self.scale)
  1781. else
  1782. self.weapon_hand_list[i].transform.localScale = Vector3(100,100,100)
  1783. end
  1784. --坐标
  1785. if ClientConfig.is_use_model_render or self.model_type == UIModelCommon.ModelType.BackModel then
  1786. self.weapon_hand_list[i].transform.localPosition = self.position or Vector3(0,75,-300)
  1787. elseif self.model_type == UIModelCommon.ModelType.Model then
  1788. if self.position then
  1789. self.weapon_hand_list[i].transform.localPosition = self.position
  1790. else
  1791. self.weapon_hand_list[i].transform.localPosition = Vector3.zero
  1792. end
  1793. else
  1794. if self.position and not self.show_shadow then
  1795. self.weapon_hand_list[i].transform.localPosition = self.position + self:GetRolePositionOffset()
  1796. else
  1797. if self.show_shadow then
  1798. self.weapon_hand_list[i].transform.localPosition = Vector3(0, 119, 0) + self:GetRolePositionOffset()
  1799. else
  1800. self.weapon_hand_list[i].transform.localPosition = Vector3.zero + self:GetRolePositionOffset()
  1801. end
  1802. end
  1803. end
  1804. local action_delta = self.action_delta
  1805. local action_name_list = self.action_name_list
  1806. local animator = self.weapon_hand_list[i]:GetComponent("Animator")
  1807. if IsNull(animator) then
  1808. return
  1809. end
  1810. animator:CrossFade("show3",0, 0.0 )
  1811. --动作特效
  1812. if not IsTableEmpty(action_name_list) then
  1813. if action_delta then
  1814. self:DelayPlayNextActionLoop(animator, action_name_list, action_delta)
  1815. else
  1816. self:DelayPlayNextAction(animator, action_name_list)
  1817. end
  1818. end
  1819. end
  1820. end
  1821. self:CreateEffect(self.type, self.clothe_res_id, self.role)
  1822. end
  1823. -- 发行需求:切换绿幕
  1824. function UIModelCommon:UpdateModelGreenScreen( )
  1825. -- 获取模型节点根节点
  1826. if self.model_data and self.model_data.use_green_screen then
  1827. -- camera_type:1 主摄像机 2 UI摄像机 3 UIModel摄像机
  1828. CheatModel:getInstance():SetupGreenScreenEffect(true, self, self.model_data.green_screen_camera_type)
  1829. end
  1830. end
  1831. --灯光参数
  1832. function UIModelCommon:ApplyLightData( )
  1833. self:ApplyCameraLightData()
  1834. local cfg = Config.lightsData
  1835. local temp_vet4 = Vector4(0,0,0,0)
  1836. for k,v in pairs(cfg) do
  1837. temp_vet4.x = v[1]
  1838. temp_vet4.y = v[2]
  1839. temp_vet4.z = v[3]
  1840. temp_vet4.w = v[4]
  1841. Shader.SetGlobalVector(k, temp_vet4)
  1842. end
  1843. end
  1844. function UIModelCommon:ApplyCameraLightData( )
  1845. local light_camera = MainCamera.Instance.camera_gameObject
  1846. if not IsNull(light_camera) then
  1847. local dir = -light_camera.transform.forward;
  1848. dir:Normalize()
  1849. Shader.SetGlobalVector("_GlobalLightDir", Vector4(dir.x, dir.y, dir.z, 1))
  1850. end
  1851. end
  1852. function UIModelCommon:SetAnimatorSpeed(speed)
  1853. if self.role then
  1854. local animator = self.role:GetComponent("Animator")
  1855. if animator then
  1856. animator.speed = speed
  1857. end
  1858. end
  1859. end