源战役客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

212 行
7.0 KiB

  1. CheatBloomView = CheatBloomView or BaseClass(BaseView)
  2. local CheatBloomView = CheatBloomView
  3. function CheatBloomView:__init()
  4. self.base_file = "cheat"
  5. self.layout_file = "CheatBloomView"
  6. self.layer_name = "Top"
  7. self.destroy_imm = true
  8. self.use_background = false
  9. self.change_scene_close = true
  10. self.is_show = true
  11. self.is_on = false
  12. self.load_callback = function ()
  13. self:LoadSuccess()
  14. self:AddEvent()
  15. end
  16. self.open_callback = function ( )
  17. self:OpenSuccess()
  18. end
  19. self.destroy_callback = function ( )
  20. self:DestroySuccess()
  21. end
  22. end
  23. function CheatBloomView:Open( )
  24. --self.data = data
  25. BaseView.Open(self)
  26. end
  27. function CheatBloomView:LoadSuccess()
  28. self.threshold_slider = self:GetChild("threshold/countSlider"):GetComponent("Slider")
  29. self.threshold_value = self:GetChild("threshold/value"):GetComponent("Text")
  30. self.intensity_slider = self:GetChild("intensity/countSlider"):GetComponent("Slider")
  31. self.intensity_value = self:GetChild("intensity/value"):GetComponent("Text")
  32. self.intensity_slider.maxValue = 300
  33. self.blurSize_slider = self:GetChild("blurSize/countSlider"):GetComponent("Slider")
  34. self.blurSize_value = self:GetChild("blurSize/value"):GetComponent("Text")
  35. self.blurIteration_slider = self:GetChild("blurIteration/countSlider"):GetComponent("Slider")
  36. self.blurIteration_value = self:GetChild("blurIteration/value"):GetComponent("Text")
  37. self.close_btn = self:GetChild("closeBtn").gameObject
  38. self.hideBtn = self:GetChild("hideBtn").gameObject
  39. self.tog_btn = self:GetChild("show_toggle/Background").gameObject
  40. self.tog_btn_mask = self:GetChild("show_toggle/Background/Checkmark").gameObject
  41. self.cam_tog_btn = self:GetChild("cam_toggle/Background").gameObject
  42. self.cam_tog_btn_mask = self:GetChild("cam_toggle/Background/Checkmark").gameObject
  43. -- 泛光模糊算法
  44. self.dual_bloom_toggle = self:GetChild("dual_bloom_toggle"):GetComponent("Toggle")
  45. -- self.transform.anchorMin = Vector2(0.5,0.5)
  46. -- self.transform.anchorMax = Vector2(0.5,0.5)
  47. -- SetAnchoredPosition(self.transform, (ScreenWidth-366)/2, 0)
  48. SetAnchoredPosition(self.transform, -ClientConfig.iphone_x_offset_right, 0)
  49. self:InitCamera()
  50. end
  51. function CheatBloomView:InitCamera( )
  52. local is_ui_mode = self.cam_tog_btn_mask.activeSelf
  53. local temp_camera
  54. if is_ui_mode then
  55. temp_camera = GameObject.Find("root").transform:Find("UIBackRoleCamera")
  56. else
  57. temp_camera = MainCamera.Instance.camera_gameObject
  58. end
  59. print("tanar: [CheatBloomView 65]=> temp_camera: ",temp_camera)
  60. if temp_camera then
  61. -- self.bloom_effect = temp_camera:GetComponent(typeof(UnityStandardAssets.ImageEffects.BloomOptimized))
  62. self.bloom_effect = temp_camera:GetComponent(typeof(PostEffect))
  63. end
  64. if not IsNull(self.bloom_effect) then
  65. self.is_on = self.bloom_effect.EnableBloom
  66. end
  67. end
  68. function CheatBloomView:AddEvent()
  69. local function onBtnClickHandler( target )
  70. if target == self.close_btn then
  71. self:Close()
  72. elseif target == self.hideBtn then
  73. self:HideAction(not self.is_show)
  74. elseif target == self.tog_btn then
  75. self.is_on = not self.is_on
  76. self:UpdateTog()
  77. elseif target == self.cam_tog_btn then
  78. local is_ui_mode = self.cam_tog_btn_mask.activeSelf
  79. is_ui_mode = not is_ui_mode
  80. self.cam_tog_btn_mask:SetActive(is_ui_mode)
  81. self:InitCamera()
  82. self:UpdateView()
  83. elseif target == self.dual_bloom_toggle.gameObject then
  84. self:UpdateDualBloom()
  85. end
  86. end
  87. AddClickEvent(self.close_btn, onBtnClickHandler)
  88. AddClickEvent(self.hideBtn, onBtnClickHandler)
  89. AddClickEvent(self.tog_btn, onBtnClickHandler)
  90. AddClickEvent(self.cam_tog_btn, onBtnClickHandler)
  91. AddClickEvent(self.dual_bloom_toggle.gameObject, onBtnClickHandler)
  92. local function onSliderDragEnd(target)
  93. local value = target:GetComponent("Slider").value
  94. if target == self.threshold_slider.gameObject then
  95. local temp_value = tonumber(string.format("%.2f", value/100))
  96. self.threshold_value.text = temp_value
  97. if self.bloom_effect then
  98. self.bloom_effect.threshold = temp_value
  99. end
  100. self:ApplyBloom()
  101. elseif target == self.intensity_slider.gameObject then
  102. local temp_value = tonumber(string.format("%.2f", value/100))
  103. self.intensity_value.text = temp_value
  104. if self.bloom_effect then
  105. self.bloom_effect.intensity = temp_value
  106. end
  107. self:ApplyBloom()
  108. elseif target == self.blurSize_slider.gameObject then
  109. local temp_value = tonumber(string.format("%.2f", value/100))
  110. self.blurSize_value.text = temp_value
  111. if self.bloom_effect then
  112. self.bloom_effect.blurSize = temp_value
  113. end
  114. elseif target == self.blurIteration_slider.gameObject then
  115. local temp_value = value
  116. self.blurIteration_value.text = temp_value
  117. if self.bloom_effect then
  118. self.bloom_effect.blurIterations = temp_value
  119. end
  120. end
  121. end
  122. AddDragEvent(self.threshold_slider.gameObject,onSliderDragEnd)
  123. AddDragEvent(self.intensity_slider.gameObject,onSliderDragEnd)
  124. AddDragEvent(self.blurSize_slider.gameObject,onSliderDragEnd)
  125. AddDragEvent(self.blurIteration_slider.gameObject,onSliderDragEnd)
  126. end
  127. function CheatBloomView:UpdateTog( )
  128. self.tog_btn_mask:SetActive(self.is_on)
  129. self.bloom_effect.EnableBloom = self.is_on
  130. end
  131. function CheatBloomView:UpdateDualBloom( )
  132. self.bloom_effect.use_dual_bloom = self.dual_bloom_toggle.isOn
  133. end
  134. function CheatBloomView:OpenSuccess()
  135. self:UpdateView()
  136. end
  137. function CheatBloomView:UpdateView()
  138. if IsNull(self.bloom_effect) then
  139. return
  140. end
  141. local value = self.bloom_effect.threshold
  142. local temp_value = value*100
  143. self.threshold_value.text = string.format("%.2f", value)
  144. self.threshold_slider.value = temp_value
  145. local value = self.bloom_effect.intensity
  146. local temp_value = value*100
  147. self.intensity_value.text = value
  148. self.intensity_slider.value = temp_value
  149. local value = self.bloom_effect.blurSize
  150. local temp_value = value*100
  151. self.blurSize_value.text = value
  152. self.blurSize_slider.value = temp_value
  153. local value = self.bloom_effect.blurIterations
  154. local temp_value = value
  155. self.blurIteration_value.text = value
  156. self.blurIteration_slider.value = temp_value
  157. self.dual_bloom_toggle.isOn = self.bloom_effect.use_dual_bloom
  158. end
  159. function CheatBloomView:ApplyBloom( )
  160. local function apply_bloom()
  161. if self.bloom_effect then
  162. if self.bloom_effect.use_dual_bloom then
  163. self.bloom_effect:ApplyBloomMaterialProperties()
  164. end
  165. end
  166. end
  167. TimeManager.GetInstance():StartTime("CheatBloomView_ApplyBloom", 0.5, apply_bloom)
  168. end
  169. function CheatBloomView:HideAction(show)
  170. self.is_show = show
  171. self.hideBtn.transform.localRotation = Quaternion.Euler(Vector3(0, 0, self.is_show and 90 or 270))
  172. local target_pos_x = (self.is_show and 0 or 366 ) - ClientConfig.iphone_x_offset_right
  173. self.con_anim_id = TweenLite.to(self, self.transform, TweenLite.UiAnimationType.ANCHORED_POSX, target_pos_x, 0.3, nil, TweenFunc.EASE_OUT_QUINT)
  174. end
  175. function CheatBloomView:StopHideAction( )
  176. if self.con_anim_id then
  177. TweenLite.Stop(self.con_anim_id)
  178. SetAnchoredPositionX(self.transform, (self.is_show and 0 or 366 ) - ClientConfig.iphone_x_offset_right)
  179. end
  180. end
  181. function CheatBloomView:DestroySuccess( )
  182. self:StopHideAction()
  183. end