|
|
- CheatBloomView = CheatBloomView or BaseClass(BaseView)
- local CheatBloomView = CheatBloomView
-
- function CheatBloomView:__init()
- self.base_file = "cheat"
- self.layout_file = "CheatBloomView"
- self.layer_name = "Top"
- self.destroy_imm = true
- self.use_background = false
- self.change_scene_close = true
- self.is_show = true
- self.is_on = false
-
- self.load_callback = function ()
- self:LoadSuccess()
- self:AddEvent()
- end
- self.open_callback = function ( )
- self:OpenSuccess()
- end
- self.destroy_callback = function ( )
- self:DestroySuccess()
- end
- end
-
- function CheatBloomView:Open( )
- --self.data = data
- BaseView.Open(self)
- end
-
- function CheatBloomView:LoadSuccess()
- self.threshold_slider = self:GetChild("threshold/countSlider"):GetComponent("Slider")
- self.threshold_value = self:GetChild("threshold/value"):GetComponent("Text")
-
- self.intensity_slider = self:GetChild("intensity/countSlider"):GetComponent("Slider")
- self.intensity_value = self:GetChild("intensity/value"):GetComponent("Text")
- self.intensity_slider.maxValue = 300
-
- self.blurSize_slider = self:GetChild("blurSize/countSlider"):GetComponent("Slider")
- self.blurSize_value = self:GetChild("blurSize/value"):GetComponent("Text")
-
- self.blurIteration_slider = self:GetChild("blurIteration/countSlider"):GetComponent("Slider")
- self.blurIteration_value = self:GetChild("blurIteration/value"):GetComponent("Text")
-
- self.close_btn = self:GetChild("closeBtn").gameObject
- self.hideBtn = self:GetChild("hideBtn").gameObject
-
- self.tog_btn = self:GetChild("show_toggle/Background").gameObject
- self.tog_btn_mask = self:GetChild("show_toggle/Background/Checkmark").gameObject
-
- self.cam_tog_btn = self:GetChild("cam_toggle/Background").gameObject
- self.cam_tog_btn_mask = self:GetChild("cam_toggle/Background/Checkmark").gameObject
-
- -- 泛光模糊算法
- self.dual_bloom_toggle = self:GetChild("dual_bloom_toggle"):GetComponent("Toggle")
- -- self.transform.anchorMin = Vector2(0.5,0.5)
- -- self.transform.anchorMax = Vector2(0.5,0.5)
- -- SetAnchoredPosition(self.transform, (ScreenWidth-366)/2, 0)
- SetAnchoredPosition(self.transform, -ClientConfig.iphone_x_offset_right, 0)
-
- self:InitCamera()
- end
-
- function CheatBloomView:InitCamera( )
- local is_ui_mode = self.cam_tog_btn_mask.activeSelf
- local temp_camera
- if is_ui_mode then
- temp_camera = GameObject.Find("root").transform:Find("UIBackRoleCamera")
- else
- temp_camera = MainCamera.Instance.camera_gameObject
- end
- print("tanar: [CheatBloomView 65]=> temp_camera: ",temp_camera)
- if temp_camera then
- -- self.bloom_effect = temp_camera:GetComponent(typeof(UnityStandardAssets.ImageEffects.BloomOptimized))
- self.bloom_effect = temp_camera:GetComponent(typeof(PostEffect))
- end
-
- if not IsNull(self.bloom_effect) then
- self.is_on = self.bloom_effect.EnableBloom
- end
- end
-
- function CheatBloomView:AddEvent()
- local function onBtnClickHandler( target )
- if target == self.close_btn then
- self:Close()
- elseif target == self.hideBtn then
- self:HideAction(not self.is_show)
- elseif target == self.tog_btn then
- self.is_on = not self.is_on
- self:UpdateTog()
- elseif target == self.cam_tog_btn then
- local is_ui_mode = self.cam_tog_btn_mask.activeSelf
- is_ui_mode = not is_ui_mode
- self.cam_tog_btn_mask:SetActive(is_ui_mode)
- self:InitCamera()
- self:UpdateView()
- elseif target == self.dual_bloom_toggle.gameObject then
- self:UpdateDualBloom()
- end
- end
- AddClickEvent(self.close_btn, onBtnClickHandler)
- AddClickEvent(self.hideBtn, onBtnClickHandler)
- AddClickEvent(self.tog_btn, onBtnClickHandler)
- AddClickEvent(self.cam_tog_btn, onBtnClickHandler)
- AddClickEvent(self.dual_bloom_toggle.gameObject, onBtnClickHandler)
-
- local function onSliderDragEnd(target)
- local value = target:GetComponent("Slider").value
- if target == self.threshold_slider.gameObject then
- local temp_value = tonumber(string.format("%.2f", value/100))
- self.threshold_value.text = temp_value
- if self.bloom_effect then
- self.bloom_effect.threshold = temp_value
- end
- self:ApplyBloom()
- elseif target == self.intensity_slider.gameObject then
- local temp_value = tonumber(string.format("%.2f", value/100))
- self.intensity_value.text = temp_value
- if self.bloom_effect then
- self.bloom_effect.intensity = temp_value
- end
- self:ApplyBloom()
- elseif target == self.blurSize_slider.gameObject then
- local temp_value = tonumber(string.format("%.2f", value/100))
- self.blurSize_value.text = temp_value
- if self.bloom_effect then
- self.bloom_effect.blurSize = temp_value
- end
- elseif target == self.blurIteration_slider.gameObject then
- local temp_value = value
- self.blurIteration_value.text = temp_value
- if self.bloom_effect then
- self.bloom_effect.blurIterations = temp_value
- end
- end
- end
- AddDragEvent(self.threshold_slider.gameObject,onSliderDragEnd)
- AddDragEvent(self.intensity_slider.gameObject,onSliderDragEnd)
- AddDragEvent(self.blurSize_slider.gameObject,onSliderDragEnd)
- AddDragEvent(self.blurIteration_slider.gameObject,onSliderDragEnd)
- end
-
- function CheatBloomView:UpdateTog( )
- self.tog_btn_mask:SetActive(self.is_on)
- self.bloom_effect.EnableBloom = self.is_on
- end
-
- function CheatBloomView:UpdateDualBloom( )
- self.bloom_effect.use_dual_bloom = self.dual_bloom_toggle.isOn
- end
-
- function CheatBloomView:OpenSuccess()
- self:UpdateView()
- end
-
- function CheatBloomView:UpdateView()
- if IsNull(self.bloom_effect) then
- return
- end
-
- local value = self.bloom_effect.threshold
- local temp_value = value*100
- self.threshold_value.text = string.format("%.2f", value)
- self.threshold_slider.value = temp_value
-
- local value = self.bloom_effect.intensity
- local temp_value = value*100
- self.intensity_value.text = value
- self.intensity_slider.value = temp_value
-
- local value = self.bloom_effect.blurSize
- local temp_value = value*100
- self.blurSize_value.text = value
- self.blurSize_slider.value = temp_value
-
- local value = self.bloom_effect.blurIterations
- local temp_value = value
- self.blurIteration_value.text = value
- self.blurIteration_slider.value = temp_value
-
- self.dual_bloom_toggle.isOn = self.bloom_effect.use_dual_bloom
- end
-
- function CheatBloomView:ApplyBloom( )
- local function apply_bloom()
- if self.bloom_effect then
- if self.bloom_effect.use_dual_bloom then
- self.bloom_effect:ApplyBloomMaterialProperties()
- end
- end
- end
- TimeManager.GetInstance():StartTime("CheatBloomView_ApplyBloom", 0.5, apply_bloom)
- end
-
- function CheatBloomView:HideAction(show)
- self.is_show = show
- self.hideBtn.transform.localRotation = Quaternion.Euler(Vector3(0, 0, self.is_show and 90 or 270))
- local target_pos_x = (self.is_show and 0 or 366 ) - ClientConfig.iphone_x_offset_right
- self.con_anim_id = TweenLite.to(self, self.transform, TweenLite.UiAnimationType.ANCHORED_POSX, target_pos_x, 0.3, nil, TweenFunc.EASE_OUT_QUINT)
- end
-
- function CheatBloomView:StopHideAction( )
- if self.con_anim_id then
- TweenLite.Stop(self.con_anim_id)
- SetAnchoredPositionX(self.transform, (self.is_show and 0 or 366 ) - ClientConfig.iphone_x_offset_right)
- end
- end
-
- function CheatBloomView:DestroySuccess( )
- self:StopHideAction()
- end
|