源战役客户端
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

739 lines
22 KiB

  1. --需要处理例子特效的ui对象 需要继承该类 比如baseview baseitem
  2. UIPartical = UIPartical or BaseClass(UIZDepth)
  3. local UIPartical = UIPartical
  4. local UIDepth = UIDepth
  5. local rawget = rawget
  6. local IsNull = IsNull
  7. --每个layer的起始值
  8. UIPartical.Start_SortingOrder_list = {
  9. ["Scene"] = 0,
  10. ["Main"] = 200,
  11. ["UI"] = 400,
  12. ["Activity"] = 600,
  13. ["Top"] = 800,
  14. ["UpTop"] = 1000,
  15. }
  16. --每个layer的当前层数
  17. UIPartical.curr_SortingOrder_list = {
  18. ["Scene"] = UIPartical.Start_SortingOrder_list.Scene,
  19. ["Main"] = UIPartical.Start_SortingOrder_list.Main,
  20. ["UI"] = UIPartical.Start_SortingOrder_list.UI,
  21. ["Activity"] = UIPartical.Start_SortingOrder_list.Activity,
  22. ["Top"] = UIPartical.Start_SortingOrder_list.Top,
  23. ["UpTop"] = UIPartical.Start_SortingOrder_list.UpTop,
  24. }
  25. --设置渲染特效所在的layer层
  26. UIPartical.RenderingOther_List = {
  27. DEFAULT = 0,
  28. UI = 5,
  29. UIForward = 8,
  30. Role = 9,
  31. Blackground = 10,
  32. UIBackward = 14,
  33. UIBackRole = 15,
  34. Reflection = 29,
  35. Ground = 30,
  36. UI3D = 16,
  37. }
  38. function UIPartical:__init()
  39. self.layer_name = "Main"
  40. self.depth_counter = 0
  41. self.partical_list = {}
  42. self.callback_list = {}
  43. self.lastTime_list = {}
  44. self.cache_partical_map = {}
  45. self.show_partical_map = {}
  46. self.wait_load_effect_trans = {}
  47. self.speed = 1
  48. self.effect_cd_list = {}--特效冷却时间列表
  49. self.effect_timer_list = {}--特效时间定时器列表
  50. end
  51. function UIPartical:__delete()
  52. self:ClearAllEffect()
  53. self:ClearCacheEffect()
  54. end
  55. function UIPartical:ClearCacheEffect()
  56. for abname,state in pairs(self.cache_partical_map) do
  57. lua_resM:ClearObjPool(abname)
  58. end
  59. self.cache_partical_map = {}
  60. self.wait_load_effect_trans = {}
  61. self.show_partical_map = {}
  62. end
  63. function UIPartical:DeleteCurrLayerDepth(layer_name,count)
  64. if UIPartical.curr_SortingOrder_list[layer_name] then
  65. UIPartical.curr_SortingOrder_list[layer_name] = UIPartical.curr_SortingOrder_list[layer_name] - count
  66. end
  67. if UIPartical.Start_SortingOrder_list[layer_name] then
  68. if self:GetCurrLayerDepth(layer_name) < UIPartical.Start_SortingOrder_list[layer_name] then
  69. UIPartical.curr_SortingOrder_list[layer_name] = UIPartical.Start_SortingOrder_list[layer_name]
  70. end
  71. end
  72. end
  73. function UIPartical:AddCurrLayerDepth(layer_name,count)
  74. if UIPartical.curr_SortingOrder_list[layer_name] then
  75. UIPartical.curr_SortingOrder_list[layer_name] = UIPartical.curr_SortingOrder_list[layer_name] + (count or 1)
  76. end
  77. end
  78. function UIPartical:GetCurrLayerDepth(layer_name)
  79. return UIPartical.curr_SortingOrder_list[layer_name]
  80. end
  81. --打开界面的时候 设置UI SortingOrder深度
  82. function UIPartical:SetUIDepth(gameObject)
  83. if self.layer_name and self.layer_name ~= "Main" then
  84. if UIPartical.GetCurrLayerDepth(self, self.layer_name) < UIPartical.Start_SortingOrder_list[self.layer_name] then
  85. UIPartical.curr_SortingOrder_list[self.layer_name] = UIPartical.Start_SortingOrder_list[self.layer_name]
  86. end
  87. self.depth_counter = self.depth_counter + 1
  88. UIPartical.AddCurrLayerDepth(self, self.layer_name)
  89. gameObject.layer = LayerMask.NameToLayer("UI")
  90. UIDepth.SetUIDepth(gameObject,true,self:GetCurrLayerDepth(self.layer_name))
  91. end
  92. end
  93. function UIPartical:SetGameObjectDepth(gameObject)
  94. if gameObject == nil then return end
  95. if self.layer_name and self.layer_name ~= "Main" then
  96. self.depth_counter = self.depth_counter + 1
  97. UIPartical.AddCurrLayerDepth(self, self.layer_name)
  98. UIDepth.SetUIDepth(gameObject,true,self:GetCurrLayerDepth(self.layer_name))
  99. gameObject.layer = LayerMask.NameToLayer("UI")
  100. end
  101. end
  102. function UIPartical:SetGameObjectDepthByLayerName(gameObject, layer_name)
  103. if gameObject == nil then return end
  104. layer_name = layer_name or "UI"
  105. self.depth_counter = self.depth_counter + 1
  106. UIPartical.AddCurrLayerDepth(self, layer_name)
  107. UIDepth.SetUIDepth(gameObject,true,self:GetCurrLayerDepth(layer_name))
  108. gameObject.layer = LayerMask.NameToLayer("UI")
  109. end
  110. --关闭界面的时候重置UI深度
  111. function UIPartical:ResetUIDepth(count)
  112. if rawget(self, "layer_name") and (self.layer_name ~= "Main" or self.need_to_reset_layer) then
  113. if count then
  114. if count > 0 then
  115. UIPartical.DeleteCurrLayerDepth(self, self.layer_name,count )
  116. self.depth_counter = self.depth_counter - count
  117. end
  118. else
  119. if self.depth_counter > 0 then
  120. UIPartical.DeleteCurrLayerDepth(self, self.layer_name,self.depth_counter )
  121. self.depth_counter = 0
  122. end
  123. end
  124. end
  125. end
  126. --这里分为UI层跟其它层,UI层的粒子层级加1,而其他层级,例如主界面,则固定为1
  127. function UIPartical:SetParticleDepth(gameObject, forceAdd)
  128. if self.layer_name then
  129. if self.layer_name == "Main" and not forceAdd then
  130. local depth = UIPartical.Start_SortingOrder_list[self.layer_name] + 1
  131. if depth ~= nil then
  132. UIDepth.SetUIDepth(gameObject,false,depth)
  133. end
  134. else
  135. self.depth_counter = self.depth_counter + 1
  136. UIPartical.AddCurrLayerDepth(self, self.layer_name)
  137. UIDepth.SetUIDepth(gameObject,false,self:GetCurrLayerDepth(self.layer_name))
  138. end
  139. end
  140. end
  141. --添加屏幕特效
  142. function UIPartical:AddScreenEffect(resname, pos, scale, is_loop ,last_time)
  143. local parent_go = UiFactory.createChild(panelMgr:GetParent(self.layer_name), UIType.EmptyObject, resname)
  144. local function call_back_func()
  145. destroy(parent_go)
  146. end
  147. self:AddUIEffect(resname, parent_go.transform, self.layer_name, pos, scale, is_loop ,last_time, nil, call_back_func)
  148. end
  149. --[[
  150. UI上的特效 baseview里面设置特效 opencallback方法里设置才行 baseitem需要再baseview调用opencallback的时候重新设置
  151. uiTranform
  152. . lastTime为-1
  153. save_by_batch: useMask是互斥关系resname相同时useMask另一个用save_by_batch
  154. ]]
  155. function UIPartical:AddUIEffectConfig(config)
  156. config = config or {}
  157. local resname = config.resname
  158. local pos = config.pos
  159. local scale = config.scale or 1
  160. local is_loop = config.is_loop
  161. local last_time = config.last_time
  162. local useMask = config.useMask
  163. local call_back_func = config.call_back_func
  164. local load_finish_func = config.load_finish_func
  165. local speed = config.speed
  166. local layer = config.layer
  167. local not_delete_old_ps = config.not_delete_old_ps
  168. local save_by_batch = config.save_by_batch
  169. local need_cache = config.need_cache
  170. local uiTranform = config.uiTranform
  171. local layer_name = config.layer_name
  172. local use_ex_depth = config.use_ex_depth --修改深度时候处理隐藏节点,根据特效决定是否使用
  173. self:AddUIEffect(resname, uiTranform, layer_name, pos, scale, is_loop ,last_time, useMask, call_back_func,load_finish_func, speed, layer, not_delete_old_ps, save_by_batch, need_cache, use_ex_depth)
  174. end
  175. function UIPartical:AddUIEffect(resname, uiTranform, layer_name, pos, scale, is_loop ,last_time, useMask, call_back_func,load_finish_func, speed, layer, not_delete_old_ps, save_by_batch, need_cache, use_ex_depth)
  176. if uiTranform then
  177. local instance_id = uiTranform:GetInstanceID()
  178. if self.wait_load_effect_trans[instance_id] then
  179. return
  180. end
  181. self.layer_name = layer_name or self.layer_name
  182. pos = pos or Vector3.zero
  183. scale = scale
  184. if is_loop == nil then
  185. is_loop = true
  186. end
  187. if need_cache == nil then
  188. need_cache = true
  189. end
  190. local function load_call_back(objs, is_gameObject)
  191. self.wait_load_effect_trans[instance_id] = false
  192. if self.transform then --没有删除根变换
  193. if self._use_delete_method then
  194. return
  195. end
  196. if IsNull(uiTranform) then return end
  197. --如果没特效,则返回
  198. if not objs or not objs[0] then
  199. return
  200. end
  201. local curr_effect_sortingOrder = nil
  202. if self.layer_name and self.layer_name ~= "Main" then
  203. self.depth_counter = self.depth_counter + 1
  204. self:AddCurrLayerDepth(self.layer_name)
  205. curr_effect_sortingOrder = self:GetCurrLayerDepth(self.layer_name)
  206. end
  207. local go = is_gameObject and objs[0] or newObject(objs[0])
  208. local shader_mask = UIParticleMaskShader.Res[resname]
  209. if shader_mask then
  210. local objs = go:GetComponentsInChildren(typeof(UnityEngine.Renderer))
  211. for i=1,objs.Length do
  212. local mats = objs[i-1].sharedMaterials
  213. for i=0, mats.Length - 1 do
  214. if mats[i] then
  215. local shader_config = UIParticleMaskShader.Shader[mats[i].shader.name]
  216. if shader_config then
  217. mats[i].shader = ShaderTools.GetShader(shader_config)
  218. end
  219. end
  220. end
  221. end
  222. end
  223. self.partical_list[go] = true
  224. local gameobject_id = go:GetInstanceID()
  225. self.show_partical_map[gameobject_id] = resname
  226. local transform = go.transform
  227. transform:SetParent(uiTranform)
  228. transform.localPosition = pos
  229. SetLocalRotation(transform)
  230. if type(scale) == "number" then
  231. if scale ~= -1 then
  232. -- if not is_gameObject or (Scene and Scene.Instance:IsPreLoadPoolEffect(resname)) then
  233. -- 备注Hierarchy = 0,Local = 1,Shape = 2
  234. -- local particleSystems = go:GetComponentsInChildren(typeof(UnityEngine.ParticleSystem))
  235. -- if particleSystems and scale ~= 1 then
  236. -- for i = 0, particleSystems.Length - 1 do
  237. -- particleSystems[i].main.scalingMode = UnityEngine.ParticleSystemScalingMode.IntToEnum(1)
  238. -- end
  239. -- end
  240. -- cs_particleM:SetScale(go,scale)
  241. -- end
  242. transform.localScale = Vector3.one * scale * 100
  243. end
  244. elseif type(scale) == "table" then
  245. local particleSystems = go:GetComponentsInChildren(typeof(UnityEngine.ParticleSystem))
  246. if scale.z == nil then scale.z = 1 end
  247. for i = 0, particleSystems.Length - 1 do
  248. local ps = particleSystems[i]
  249. ps.main.scalingMode = UnityEngine.ParticleSystemScalingMode.IntToEnum(1)
  250. ps.transform.localScale = Vector3(scale.x, scale.y, scale.z)
  251. end
  252. transform.localScale = Vector3(scale.x, scale.y, scale.z) * 100
  253. else
  254. transform.localScale = Vector3(72,72,72)
  255. end
  256. PrintParticleInfo(go)
  257. self:SetSpeed(go, speed)
  258. go:SetActive(false)
  259. go:SetActive(true)
  260. self:SetUILayer(uiTranform, layer)
  261. if useMask then
  262. self:SetEffectMask(go)
  263. else
  264. if curr_effect_sortingOrder then
  265. if use_ex_depth then
  266. self:SetUIDepthEx(go, false, curr_effect_sortingOrder)
  267. else
  268. UIDepth.SetUIDepth(go, false, curr_effect_sortingOrder)
  269. end
  270. else
  271. self:SetParticleDepth(go, maskID)
  272. end
  273. if save_by_batch then
  274. --需要动态批处理,设置共享材质
  275. local renders = go:GetComponentsInChildren(typeof(UnityEngine.Renderer))
  276. for i = 0, renders.Length - 1 do
  277. local mats = renders[i].sharedMaterials
  278. for j = 0, mats.Length - 1 do
  279. mats[j]:SetFloat("_Stencil", 0)
  280. end
  281. end
  282. local curTrans = go.transform.parent
  283. local maskImage
  284. while(curTrans and curTrans.name ~= "Canvas") do
  285. maskImage = curTrans:GetComponent("Mask")
  286. if maskImage then
  287. break
  288. else
  289. curTrans = curTrans.parent
  290. end
  291. end
  292. if maskImage then
  293. local canvas = curTrans:GetComponent("Canvas")
  294. if canvas then
  295. UIDepth.SetUIDepth(go,false,canvas.sortingOrder + 1)
  296. end
  297. end
  298. else
  299. --由于使用遮罩的材质调用了共享材质,这里对不使用遮罩的特效使用实例化材质
  300. local renders = go:GetComponentsInChildren(typeof(UnityEngine.Renderer))
  301. for i = 0, renders.Length - 1 do
  302. local mats = renders[i].materials
  303. for j = 0, mats.Length - 1 do
  304. mats[j]:SetFloat("_Stencil", 0)
  305. end
  306. end
  307. end
  308. end
  309. self.callback_list[go] = call_back_func
  310. if last_time and last_time > 0 and not self.lastTime_list[go] then
  311. local function onDelayFunc()
  312. self.show_partical_map[gameobject_id] = nil
  313. self:PlayEnd(go,need_cache,resname)
  314. if not need_cache and not self._use_delete_method then
  315. lua_resM:reduceRefCount(self, resname)
  316. end
  317. end
  318. self.lastTime_list[go] = GlobalTimerQuest:AddDelayQuest(onDelayFunc,last_time)
  319. end
  320. if is_loop then
  321. cs_particleM:SetLoop(go,is_loop)
  322. elseif last_time ~= -1 and not self.lastTime_list[go] then
  323. local function playEndCallback(go)
  324. self.show_partical_map[gameobject_id] = nil
  325. self:PlayEnd(go,need_cache,resname)
  326. if not need_cache and not self._use_delete_method then
  327. lua_resM:reduceRefCount(self, resname)
  328. end
  329. end
  330. ParticleManager:getInstance():AddUIPartical(go,playEndCallback)
  331. end
  332. if load_finish_func then
  333. load_finish_func(go)
  334. end
  335. ClearTrailRenderer(go)
  336. end
  337. end
  338. if not not_delete_old_ps then
  339. self:ClearUIEffect(uiTranform)
  340. end
  341. self.wait_load_effect_trans[instance_id] = true
  342. lua_resM:loadPrefab(self,resname,resname, load_call_back,false,ASSETS_LEVEL.HIGHT)
  343. end
  344. end
  345. function UIPartical:SetUIDepthEx( go, isUI, order )
  346. if isUI then
  347. local canvas = go:GetComponent(typeof(UnityEngine.Canvas))
  348. if (canvas == nil) then
  349. canvas = go:AddComponent(typeof(UnityEngine.Canvas))
  350. end
  351. canvas.overrideSorting = true
  352. canvas.sortingOrder = order
  353. else
  354. local renders = go:GetComponentsInChildren(typeof(UnityEngine.Renderer), true)
  355. if renders then
  356. for i=0,renders.Length-1 do
  357. renders[i].sortingOrder = order
  358. end
  359. end
  360. end
  361. end
  362. -- {resname,--资源名
  363. -- uiTranform, --
  364. -- layer_name,
  365. -- pos, scale,
  366. -- is_loop
  367. -- ,last_time, --持续时间
  368. -- useMask, --遮罩
  369. -- call_back_func,
  370. -- load_finish_func,
  371. -- speed, --速度
  372. -- layer, --
  373. -- not_delete_old_ps--不删除旧特效
  374. --}
  375. --id唯一 判断是否是同一个类型(类型不一定是特效不相等)比如"SceneSpecialTipView_ui_effcet_rolelvup"
  376. function UIPartical:AddUIEffectByTime(data, time_cd, id)
  377. if not data or not data.resname then
  378. print("huangcong:UIPartical [269]特效资源名为空: ")
  379. return
  380. end
  381. time_cd = time_cd or 1
  382. id = id or data.resname
  383. if not self.effect_cd_list[id] then
  384. self.effect_cd_list[id] = {id = id, can_effect = false}
  385. elseif self.effect_cd_list[id] and self.effect_cd_list[id].can_effect then
  386. self.effect_cd_list[id].can_effect = false
  387. else
  388. print("huangcong:UIPartical [289]特效还在冷却!: ",data.id)
  389. return
  390. end
  391. self.effect_timer_list[id] = GlobalTimerQuest:AddDelayQuest(function()
  392. self.effect_cd_list[id].can_effect = true
  393. self.effect_timer_list[id] = nil
  394. end, time_cd)
  395. self:AddUIEffect(
  396. data.resname,
  397. data.uiTranform,
  398. data.layer_name,
  399. data.pos,
  400. data.scale,
  401. data.is_loop,
  402. data.last_time,
  403. data.useMask,
  404. data.call_back_func,
  405. data.load_finish_func,
  406. data.speed,
  407. data.layer,
  408. data.not_delete_old_ps)
  409. end
  410. function UIPartical:SetSpeed(go, speed)
  411. self.speed = speed or self.speed
  412. if self.partical_list[go] and self.speed then
  413. cs_particleM:SetSpeed(go,self.speed)
  414. end
  415. end
  416. --清除挂接在父容器的所有对象, 判断进入对象缓存池
  417. function UIPartical:ClearUIEffect(uiTranform)
  418. if not IsNull(uiTranform) then
  419. for i = 0,uiTranform.childCount - 1 do
  420. local go = uiTranform:GetChild(0).gameObject
  421. local cache_res = self.show_partical_map[go:GetInstanceID()]
  422. if cache_res then
  423. self:PlayEnd(go,cache_res,cache_res)
  424. end
  425. end
  426. else
  427. PrintCallStack()
  428. end
  429. end
  430. --删除所有特效
  431. function UIPartical:ClearAllEffect()
  432. UIPartical.ResetUIDepth(self)
  433. for go,callback in pairs(self.callback_list) do
  434. callback()
  435. self.partical_list[go] = nil
  436. end
  437. for go,last_time_id in pairs(self.lastTime_list) do
  438. TimerQuest.CancelQuest(GlobalTimerQuest, last_time_id)
  439. self.lastTime_list[go] = nil
  440. end
  441. for go,_ in pairs(self.partical_list) do
  442. ParticleManager.RemoveUIPartical(ParticleManager:getInstance(), go)
  443. local gomeobject_id = go:GetInstanceID()
  444. local cache_res = self.show_partical_map[gomeobject_id]
  445. if cache_res then
  446. self.show_partical_map[gomeobject_id] = nil
  447. if not IsNull(go) then
  448. go:SetActive(false)
  449. lua_resM:AddObjToPool(self, cache_res, cache_res, go)
  450. self.cache_partical_map[cache_res] = true
  451. end
  452. else
  453. destroy(go,true)
  454. end
  455. self.partical_list[go] = nil
  456. end
  457. end
  458. --单个特效播放结束
  459. function UIPartical:PlayEnd(go,need_cache,resname)
  460. if go and not IsNull(go) then
  461. local callback = self.callback_list[go]
  462. if callback and not self._use_delete_method then
  463. callback()
  464. end
  465. self.callback_list[go] = nil
  466. local last_time_id = self.lastTime_list[go]
  467. if last_time_id then
  468. TimerQuest.CancelQuest(GlobalTimerQuest, last_time_id)
  469. end
  470. self.lastTime_list[go] = nil
  471. ParticleManager.RemoveUIPartical(ParticleManager:getInstance(), go)
  472. self.partical_list[go] = nil
  473. if need_cache and resname then
  474. self.cache_partical_map[resname] = true
  475. go:SetActive(false)
  476. lua_resM:AddObjToPool(self, resname, resname, go)
  477. else
  478. destroy(go,true)
  479. end
  480. if self.layer_name ~= "Main" and self.depth_counter > 0 then
  481. self.depth_counter = self.depth_counter - 1
  482. UIPartical.DeleteCurrLayerDepth(self, self.layer_name, 1)
  483. end
  484. end
  485. end
  486. function UIPartical:SetUILayer(obj, layer)
  487. layer = layer or UIPartical.RenderingOther_List.UIForward
  488. if IsNull(obj) then
  489. return
  490. end
  491. for i = 0,obj.childCount - 1 do
  492. obj:GetChild(i).gameObject.layer = layer
  493. self:SetUILayer(obj:GetChild(i), layer)
  494. end
  495. end
  496. function UIPartical:SetForwardUILayer(obj, layer)
  497. layer = layer or UIPartical.RenderingOther_List.UIForward
  498. if IsNull(obj) then
  499. return
  500. end
  501. for i = 0,obj.childCount - 1 do
  502. obj:GetChild(i).gameObject.layer = layer
  503. self:SetUILayer(obj:GetChild(i), layer)
  504. end
  505. end
  506. function UIPartical:SetRTUILayer(obj, layer)
  507. layer = layer or UIPartical.RenderingOther_List.UI3D
  508. if IsNull(obj) then
  509. return
  510. end
  511. for i = 0,obj.childCount - 1 do
  512. obj:GetChild(i).gameObject.layer = layer
  513. self:SetUILayer(obj:GetChild(i), layer)
  514. end
  515. end
  516. function UIPartical:SetUIBackwardLayer(obj, layer)
  517. layer = layer or UIPartical.RenderingOther_List.UIBackward
  518. if IsNull(obj) then
  519. return
  520. end
  521. for i = 0,obj.childCount - 1 do
  522. obj:GetChild(i).gameObject.layer = layer
  523. self:SetUILayer(obj:GetChild(i), layer)
  524. end
  525. end
  526. function UIPartical:SetUIbackRoleLayer(obj, layer)
  527. layer = layer or UIPartical.RenderingOther_List.UIBackRole
  528. if IsNull(obj) then
  529. return
  530. end
  531. for i = 0,obj.childCount - 1 do
  532. obj:GetChild(i).gameObject.layer = layer
  533. self:SetUILayer(obj:GetChild(i), layer)
  534. end
  535. end
  536. function UIPartical:SetEffectMask(obj)
  537. local renders = obj:GetComponentsInChildren(typeof(UnityEngine.Renderer))
  538. for i = 0, renders.Length - 1 do
  539. --使用Renderer.material获取Material引用时,会把Render里Materials列表第一个预设的Material进行实例,这样每个object都有各自的材质对象,无法实现批处理draw call
  540. local mats = renders[i].sharedMaterials
  541. for j = 0, mats.Length - 1 do
  542. if mats[j] then
  543. mats[j]:SetFloat("_Stencil", 1)
  544. end
  545. end
  546. end
  547. local curTrans = obj.transform.parent
  548. local maskImage
  549. while(curTrans and curTrans.name ~= "Canvas") do
  550. maskImage = curTrans:GetComponent("Mask")
  551. if maskImage then
  552. break
  553. else
  554. curTrans = curTrans.parent
  555. end
  556. end
  557. if maskImage then
  558. local canvas = curTrans:GetComponent("Canvas")
  559. if canvas then
  560. UIDepth.SetUIDepth(obj,false,canvas.sortingOrder + 1)
  561. end
  562. end
  563. end
  564. function UIPartical:RegisterMask(maskImage)
  565. self:ApplyMaskID(maskImage, 1)
  566. self.need_to_reset_layer = true
  567. return 1
  568. end
  569. function UIPartical:ApplyMaskID(maskImage, maskID)
  570. local function callback(objs)
  571. if objs and objs[0] and not IsNull(maskImage) then
  572. maskImage.material = Material.New(objs[0])
  573. maskImage.material:SetFloat("_StencilID", maskID)
  574. end
  575. end
  576. resMgr:LoadMaterial("scene_material", "mat_mask_image" , callback, ASSETS_LEVEL.HIGHT)
  577. maskImage.gameObject.layer = UIPartical.RenderingOther_List.UI
  578. self:SetUILayer(maskImage.transform)
  579. self.depth_counter = self.depth_counter + 1
  580. self:AddCurrLayerDepth(self.layer_name)
  581. local oldMask = maskImage:GetComponent("Mask")
  582. local showMaskGraphic = oldMask.showMaskGraphic
  583. UnityEngine.Object.DestroyImmediate(oldMask)
  584. local newMask = maskImage.gameObject:AddComponent(typeof(EffectMask))
  585. newMask.showMaskGraphic = showMaskGraphic
  586. UIDepth.SetUIDepth(maskImage.gameObject,true,self:GetCurrLayerDepth(self.layer_name))
  587. if self.stencilGo then
  588. return
  589. end
  590. self.stencilGo = UiFactory.createChild(maskImage.transform.parent,UIType.ImageExtend,"StencilImage")
  591. self.stencilGo:SetActive(true)
  592. local stencilTrans,img,rect = self.stencilGo.transform, self.stencilGo:GetComponent("Image"),maskImage.transform.rect
  593. stencilTrans.localPosition = Vector2(rect.center.x, rect.center.y, 0)
  594. stencilTrans:SetSiblingIndex(maskImage.transform:GetSiblingIndex() + 1)
  595. local sizeDelta = maskImage.transform.sizeDelta
  596. stencilTrans.sizeDelta = Vector2(rect.width, rect.height)
  597. img.alpha = 0
  598. img.raycastTarget = false
  599. img.material:SetFloat("_Stencil", 1)
  600. img.material:SetFloat("_StencilOp", 1)
  601. img.material:SetFloat("_StencilComp",8)
  602. local canvas = self.stencilGo:AddComponent(typeof(UnityEngine.Canvas))
  603. canvas.overrideSorting = true
  604. self:AddCurrLayerDepth(self.layer_name)
  605. self:AddCurrLayerDepth(self.layer_name)
  606. self.depth_counter = self.depth_counter + 2
  607. canvas.sortingOrder = self:GetCurrLayerDepth(self.layer_name)
  608. end
  609. function UIPartical:UnRegisterMask(maskID)
  610. end
  611. function UIPartical:AddUIComponent( ui_component )
  612. if not ui_component then return end
  613. ui_component = ui_component.New()--不想在外部.New,因为ui_component不需要在外部DeleteMe的,这样就破坏了New和DeleteMe成对出现的规范了
  614. ui_component:Init(self)
  615. if self.is_loaded then
  616. ui_component:OnLoad()
  617. end
  618. self.ui_components = self.ui_components or {}
  619. table.insert(self.ui_components, ui_component)
  620. return ui_component
  621. end
  622. function UIPartical:RemoveUIComponent( ui_component )
  623. if not ui_component then return end
  624. for k,v in pairs(self.ui_components or {}) do
  625. if v == ui_component then
  626. ui_component:OnDestroy()
  627. table.remove(self.ui_components, k)
  628. break
  629. end
  630. end
  631. end
  632. function UIPartical:BeforeLoad( )
  633. if self.ui_components then
  634. for i,v in ipairs(self.ui_components) do
  635. if v.OnLoad then
  636. v:OnLoad()
  637. end
  638. end
  639. end
  640. end
  641. function UIPartical:AfterDestroy( )
  642. if self.ui_components then
  643. for i,v in ipairs(self.ui_components) do
  644. if v.OnDestroy then
  645. v:OnDestroy()
  646. v:DeleteMe()
  647. end
  648. end
  649. self.ui_components = nil
  650. end
  651. end