源战役客户端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

96 řádky
2.6 KiB

před 1 měsícem
  1. --需要处理 z值深度的ui对象
  2. UIZDepth = UIZDepth or BaseClass(EventDispatcher)
  3. local UIZDepth = UIZDepth
  4. local rawget = rawget
  5. local SetLocalPositionZ = SetLocalPositionZ
  6. --每一步的深度值
  7. UIZDepth.STEP_VALUE = 1000
  8. --界面模型的深度值
  9. UIZDepth.MODEL_Z_VALUE = -UIZDepth.STEP_VALUE + 300
  10. --每个layer的起始值
  11. UIZDepth.Start_ZDepth_list = {
  12. ["Scene"] = 0,
  13. ["Main"] = 0,
  14. ["UI"] = 1,
  15. ["Activity"] = 12,
  16. ["Top"] = 25,
  17. ["UpTop"] = 30,
  18. }
  19. --每个layer的当前层数
  20. UIZDepth.curr_ZDepth_list = {
  21. ["Scene"] = UIZDepth.Start_ZDepth_list.Scene,
  22. ["Main"] = UIZDepth.Start_ZDepth_list.Main,
  23. ["UI"] = UIZDepth.Start_ZDepth_list.UI,
  24. ["Activity"] = UIZDepth.Start_ZDepth_list.Activity,
  25. ["Top"] = UIZDepth.Start_ZDepth_list.Top,
  26. ["UpTop"] = UIZDepth.Start_ZDepth_list.UpTop,
  27. }
  28. function UIZDepth:__init()
  29. self.layer_name = "Main"
  30. self.zdepth_counter = 0
  31. end
  32. function UIZDepth:__delete()
  33. UIZDepth.ResetUIZDepth(self)
  34. end
  35. function UIZDepth:DeleteCurrLayerZDepth(layer_name,count)
  36. if UIZDepth.curr_ZDepth_list[layer_name] then
  37. UIZDepth.curr_ZDepth_list[layer_name] = UIZDepth.curr_ZDepth_list[layer_name] - count
  38. end
  39. UIZDepth.SetUIZDepth(self)
  40. end
  41. function UIZDepth:GetCurrLayerZDepth(layer_name)
  42. return UIZDepth.curr_ZDepth_list[layer_name]
  43. end
  44. --打开界面的时候 加UI z深度
  45. function UIZDepth:AddUIZDepth()
  46. if self.layer_name and self.layer_name ~= "Main" then
  47. self.zdepth_counter = self.zdepth_counter + 1
  48. if UIZDepth.curr_ZDepth_list[self.layer_name] then
  49. UIZDepth.curr_ZDepth_list[self.layer_name] = UIZDepth.curr_ZDepth_list[self.layer_name] + 1
  50. end
  51. UIZDepth.SetUIZDepth(self)
  52. return UIZDepth.curr_ZDepth_list[self.layer_name]
  53. end
  54. end
  55. --真正设置ui的深度
  56. function UIZDepth:SetUIZDepth()
  57. local curr_count = UIZDepth.GetCurrLayerZDepth(self, self.layer_name)
  58. if self.transform and curr_count > 0 then
  59. local camare_depth = 500 -curr_count * UIZDepth.STEP_VALUE * 0.01
  60. SetGlobalPositionZ(self.transform, camare_depth)
  61. end
  62. end
  63. --ui控件要在模型上面显示
  64. function UIZDepth:CoverMode(ui_transform)
  65. if ui_transform then
  66. SetLocalPositionZ(ui_transform, -UIZDepth.STEP_VALUE + 1)
  67. end
  68. end
  69. --关闭界面的时候重置UI z深度
  70. function UIZDepth:ResetUIZDepth(count)
  71. if rawget(self, "layer_name") and self.layer_name ~= "Main" then
  72. if count then
  73. if count > 0 then
  74. UIZDepth.DeleteCurrLayerZDepth(self, self.layer_name,count)
  75. self.zdepth_counter = self.zdepth_counter - count
  76. end
  77. else
  78. if self.zdepth_counter > 0 then
  79. UIZDepth.DeleteCurrLayerZDepth(self, self.layer_name,self.zdepth_counter )
  80. self.zdepth_counter = 0
  81. end
  82. end
  83. end
  84. end