源战役客户端
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

354 righe
17 KiB

4 settimane fa
  1. -- <*
  2. -- @Author: Saber
  3. -- @Description: 摄像机FXAA调试界面
  4. -- *>
  5. CheatFXAAView = CheatFXAAView or BaseClass(BaseView)
  6. local CheatFXAAView = CheatFXAAView
  7. -- local LuminanceMode = FXAAEffect.LuminanceMode
  8. function CheatFXAAView:__init()
  9. self.base_file = "cheat"
  10. self.layout_file = "CheatFXAAView"
  11. self.layer_name = "Top"
  12. self.destroy_imm = true
  13. self.use_background = false --全屏界面默认使用这个参数,非全屏界面自行设置
  14. self.is_show = true
  15. self.main_camera = nil
  16. self.ui_model_camera = nil
  17. self.setting_errcode = {
  18. [1] = "当前发布设置的HDR Mode为R11G11B10,无法使用当前明度计算类型",
  19. [2] = "该明度计算类型无需gamma补偿",
  20. }
  21. self.load_callback = function ()
  22. self:LoadSuccess()
  23. self:AddEvent()
  24. end
  25. self.open_callback = function ( )
  26. self:UpdateView()
  27. end
  28. self.destroy_callback = function ( )
  29. self:DestroySuccess()
  30. end
  31. end
  32. function CheatFXAAView:Open( )
  33. BaseView.Open(self)
  34. end
  35. function CheatFXAAView:LoadSuccess()
  36. -- 按钮部分
  37. self.closeBtn = self:GetChild("closeBtn").gameObject
  38. self.main_cam_btn = self:GetChild("main_cam_btn").gameObject -- 激活模型摄像机参数界面
  39. self.ui_cam_btn = self:GetChild("ui_cam_btn").gameObject -- 激活主摄像机参数界面
  40. self.hideBtn = self:GetChild("hideBtn").gameObject -- 隐藏界面
  41. -------------------------------------------
  42. -- 主摄像机参数节点
  43. self.main_node = self:GetChild("main").gameObject
  44. self.main_content = self:GetChild("main/Viewport/main_content")
  45. self.main_enable_toggle = self:GetChild("main/Viewport/main_content/main_enable_toggle"):GetComponent("Toggle")
  46. -- 主摄对比度阈值
  47. self.main_c_th_sl = self:GetChild("main/Viewport/main_content/main_c_threshold/main_c_th_sl"):GetComponent("Slider")
  48. self.main_c_th_val = self:GetChild("main/Viewport/main_content/main_c_threshold/main_c_th_val"):GetComponent(typeof(TMPro.TextMeshProUGUI))
  49. -- 主摄相对对比度阈值
  50. self.main_r_th_sl = self:GetChild("main/Viewport/main_content/main_r_threshold/main_r_th_sl"):GetComponent("Slider")
  51. self.main_r_th_val = self:GetChild("main/Viewport/main_content/main_r_threshold/main_r_th_val"):GetComponent(typeof(TMPro.TextMeshProUGUI))
  52. -- 混合比例
  53. self.main_sp_b_sl = self:GetChild("main/Viewport/main_content/main_subpix_blend/main_sp_b_sl"):GetComponent("Slider")
  54. self.main_sp_b_val = self:GetChild("main/Viewport/main_content/main_subpix_blend/main_sp_b_val"):GetComponent(typeof(TMPro.TextMeshProUGUI))
  55. -- 低质量步长
  56. self.main_low_qua_toggle = self:GetChild("main/Viewport/main_content/main_low_qua_toggle"):GetComponent("Toggle")
  57. -- 主摄FOV
  58. self.main_cam_fov_sl = self:GetChild("main/Viewport/main_content/main_cam_fov/main_cam_fov_sl"):GetComponent("Slider")
  59. self.main_cam_fov_val = self:GetChild("main/Viewport/main_content/main_cam_fov/main_cam_fov_val"):GetComponent(typeof(TMPro.TextMeshProUGUI))
  60. -- 主摄双重模糊
  61. self.main_dual_blur_tog = self:GetChild("main/Viewport/main_content/main_dual_blur_tog"):GetComponent("Toggle")
  62. -- 主摄采样类型
  63. self.main_combox_node = self:GetChild("main/Viewport/main_content/main_combox")
  64. SetSizeDeltaY(self.main_content, 720)
  65. -------------------------------------------
  66. -------------------------------------------
  67. -- 模型摄像机参数节点
  68. self.ui_node = self:GetChild("ui").gameObject
  69. self.ui_content = self:GetChild("ui/Viewport/ui_content")
  70. self.ui_enable_toggle = self:GetChild("ui/Viewport/ui_content/ui_enable_toggle"):GetComponent("Toggle")
  71. -- 主摄对比度阈值
  72. self.ui_c_th_sl = self:GetChild("ui/Viewport/ui_content/ui_c_threshold/ui_c_th_sl"):GetComponent("Slider")
  73. self.ui_c_th_val = self:GetChild("ui/Viewport/ui_content/ui_c_threshold/ui_c_th_val"):GetComponent(typeof(TMPro.TextMeshProUGUI))
  74. -- 主摄相对对比度阈值
  75. self.ui_r_th_sl = self:GetChild("ui/Viewport/ui_content/ui_r_threshold/ui_r_th_sl"):GetComponent("Slider")
  76. self.ui_r_th_val = self:GetChild("ui/Viewport/ui_content/ui_r_threshold/ui_r_th_val"):GetComponent(typeof(TMPro.TextMeshProUGUI))
  77. -- 混合比例
  78. self.ui_sp_b_sl = self:GetChild("ui/Viewport/ui_content/ui_subpix_blend/ui_sp_b_sl"):GetComponent("Slider")
  79. self.ui_sp_b_val = self:GetChild("ui/Viewport/ui_content/ui_subpix_blend/ui_sp_b_val"):GetComponent(typeof(TMPro.TextMeshProUGUI))
  80. -- 低质量步长
  81. self.ui_low_qua_toggle = self:GetChild("ui/Viewport/ui_content/ui_low_qua_toggle"):GetComponent("Toggle")
  82. -- 模摄FOV
  83. self.ui_cam_fov_sl = self:GetChild("ui/Viewport/ui_content/ui_cam_fov/ui_cam_fov_sl"):GetComponent("Slider")
  84. self.ui_cam_fov_val = self:GetChild("ui/Viewport/ui_content/ui_cam_fov/ui_cam_fov_val"):GetComponent(typeof(TMPro.TextMeshProUGUI))
  85. -- UI摄像机双重模糊
  86. self.ui_dual_blur_tog = self:GetChild("ui/Viewport/ui_content/ui_dual_blur_tog"):GetComponent("Toggle")
  87. -- 模摄采样类型
  88. self.ui_combox_node = self:GetChild("ui/Viewport/ui_content/ui_combox")
  89. SetSizeDeltaY(self.ui_content, 720)
  90. -------------------------------------------
  91. SetAnchoredPosition(self.transform, -ClientConfig.iphone_x_offset_right, 0)
  92. end
  93. function CheatFXAAView:AddEvent()
  94. local function click_event(target)
  95. if target == self.closeBtn then
  96. self:Close()
  97. elseif target == self.main_cam_btn then -- 打开主摄参数面板,下面反之亦然
  98. self.main_node:SetActive(true)
  99. self.ui_node:SetActive(false)
  100. elseif target == self.ui_cam_btn then
  101. self.main_node:SetActive(false)
  102. self.ui_node:SetActive(true)
  103. elseif target == self.hideBtn then -- 隐藏/显示界面
  104. self:HideAction(not self.is_show)
  105. -- 主摄参数部分
  106. elseif target == self.main_enable_toggle.gameObject then -- 启用/禁用FXAA
  107. if self.main_FXAA then
  108. self.main_FXAA.EnableFXAA = self.main_enable_toggle.isOn
  109. end
  110. elseif target == self.main_low_qua_toggle.gameObject then -- 启用/低质量步长
  111. if self.main_FXAA then
  112. self.main_FXAA.lowQuality = self.main_low_qua_toggle.isOn
  113. end
  114. -- 模摄参数部分
  115. elseif target == self.ui_enable_toggle.gameObject then -- 启用/禁用FXAA
  116. if self.ui_FXAA then
  117. self.ui_FXAA.EnableFXAA = self.ui_enable_toggle.isOn
  118. end
  119. elseif target == self.ui_low_qua_toggle.gameObject then -- 启用/低质量步长
  120. if self.ui_FXAA then
  121. self.ui_FXAA.lowQuality = self.ui_low_qua_toggle.isOn
  122. end
  123. end
  124. self:ApplyFXAASetting()
  125. end
  126. AddClickEvent(self.closeBtn, click_event)
  127. AddClickEvent(self.main_cam_btn, click_event)
  128. AddClickEvent(self.ui_cam_btn, click_event)
  129. AddClickEvent(self.hideBtn, click_event)
  130. AddClickEvent(self.main_enable_toggle.gameObject, click_event)
  131. AddClickEvent(self.main_low_qua_toggle.gameObject, click_event)
  132. AddClickEvent(self.ui_enable_toggle.gameObject, click_event)
  133. AddClickEvent(self.ui_low_qua_toggle.gameObject, click_event)
  134. local function onSliderDrag(target)
  135. local value = target:GetComponent("Slider").value
  136. -- 主摄像机部分
  137. if target == self.main_c_th_sl.gameObject then
  138. self.main_c_th_val.text = tonumber(string.format("%.4f", value))
  139. if self.main_FXAA then
  140. self.main_FXAA.contrastThreshold = value
  141. end
  142. elseif target == self.main_r_th_sl.gameObject then
  143. self.main_r_th_val.text = tonumber(string.format("%.4f", value))
  144. if self.main_FXAA then
  145. self.main_FXAA.relativeThreshold = value
  146. end
  147. elseif target == self.main_sp_b_sl.gameObject then
  148. self.main_sp_b_val.text = tonumber(string.format("%.4f", value))
  149. if self.main_FXAA then
  150. self.main_FXAA.subpixelBlending = value
  151. end
  152. elseif target == self.main_cam_fov_sl.gameObject then
  153. self.main_cam_fov_val.text = value
  154. if self.main_camera then
  155. self.main_camera.fieldOfView = value
  156. end
  157. -- 模型摄像机部分
  158. elseif target == self.ui_c_th_sl.gameObject then
  159. self.ui_c_th_val.text = tonumber(string.format("%.4f", value))
  160. if self.ui_FXAA then
  161. self.ui_FXAA.contrastThreshold = value
  162. end
  163. elseif target == self.ui_r_th_sl.gameObject then
  164. self.ui_r_th_val.text = tonumber(string.format("%.4f", value))
  165. if self.ui_FXAA then
  166. self.ui_FXAA.relativeThreshold = value
  167. end
  168. elseif target == self.ui_sp_b_sl.gameObject then
  169. self.ui_sp_b_val.text = tonumber(string.format("%.4f", value))
  170. if self.ui_FXAA then
  171. self.ui_FXAA.subpixelBlending = value
  172. end
  173. elseif target == self.ui_cam_fov_sl.gameObject then
  174. self.ui_cam_fov_val.text = value
  175. if self.ui_model_camera then
  176. self.ui_model_camera.fieldOfView = value
  177. end
  178. end
  179. self:ApplyFXAASetting()
  180. end
  181. AddDragEvent(self.main_c_th_sl.gameObject, onSliderDrag)
  182. AddDragEvent(self.main_r_th_sl.gameObject, onSliderDrag)
  183. AddDragEvent(self.main_sp_b_sl.gameObject, onSliderDrag)
  184. AddDragEvent(self.main_cam_fov_sl.gameObject, onSliderDrag)
  185. AddDragEvent(self.ui_c_th_sl.gameObject, onSliderDrag)
  186. AddDragEvent(self.ui_r_th_sl.gameObject, onSliderDrag)
  187. AddDragEvent(self.ui_sp_b_sl.gameObject, onSliderDrag)
  188. AddDragEvent(self.ui_cam_fov_sl.gameObject, onSliderDrag)
  189. local function onOrientationChange()
  190. SetAnchoredPosition(self.transform, -ClientConfig.iphone_x_offset_right, 0)
  191. end
  192. self:BindEvent(GlobalEventSystem, EventName.ORIENTATION_DID_CHANGE, onOrientationChange)
  193. end
  194. function CheatFXAAView:UpdateView()
  195. self:InitCamsData()
  196. -- self:InitLuminanceCombox()
  197. self.main_node:SetActive(true)
  198. self.ui_node:SetActive(false)
  199. self:HideAction(true)
  200. end
  201. function CheatFXAAView:InitCamsData( )
  202. -- 获取摄像机
  203. if not self.main_camera then
  204. self.main_camera = MainCamera.Instance.camera
  205. end
  206. if not self.ui_model_camera then
  207. self.ui_model_camera = GameObject.Find("root").transform:Find("UIBackRoleCamera"):GetComponent("Camera")
  208. end
  209. -- 获取FXAA类
  210. if not self.main_FXAA then
  211. self.main_FXAA = self.main_camera.gameObject:GetComponent(typeof(PostEffect))
  212. end
  213. if not self.ui_FXAA then
  214. self.ui_FXAA = self.ui_model_camera.gameObject:GetComponent(typeof(PostEffect))
  215. end
  216. -- 初始化摄像机参数和FXAA参数
  217. self.main_enable_toggle.isOn = self.main_FXAA.EnableFXAA
  218. self.main_c_th_sl.value = self.main_FXAA.contrastThreshold
  219. self.main_c_th_val.text = tonumber(string.format("%.4f", self.main_FXAA.contrastThreshold))
  220. self.main_r_th_sl.value = self.main_FXAA.relativeThreshold
  221. self.main_r_th_val.text = tonumber(string.format("%.4f", self.main_FXAA.relativeThreshold))
  222. self.main_sp_b_sl.value = self.main_FXAA.subpixelBlending
  223. self.main_sp_b_val.text = tonumber(string.format("%.4f", self.main_FXAA.subpixelBlending))
  224. self.main_low_qua_toggle.isOn = self.main_FXAA.lowQuality
  225. self.main_cam_fov_sl.value = self.main_camera.fieldOfView
  226. self.main_cam_fov_val.text = self.main_camera.fieldOfView
  227. self.ui_enable_toggle.isOn = self.ui_FXAA.EnableFXAA
  228. self.ui_c_th_sl.value = self.ui_FXAA.contrastThreshold
  229. self.ui_c_th_val.text = tonumber(string.format("%.4f", self.ui_FXAA.contrastThreshold))
  230. self.ui_r_th_sl.value = self.ui_FXAA.relativeThreshold
  231. self.ui_r_th_val.text = tonumber(string.format("%.4f", self.ui_FXAA.relativeThreshold))
  232. self.ui_sp_b_sl.value = self.ui_FXAA.subpixelBlending
  233. self.ui_sp_b_val.text = tonumber(string.format("%.4f", self.ui_FXAA.subpixelBlending))
  234. self.ui_low_qua_toggle.isOn = self.ui_FXAA.lowQuality
  235. self.ui_cam_fov_sl.value = self.ui_model_camera.fieldOfView
  236. self.ui_cam_fov_val.text = self.ui_model_camera.fieldOfView
  237. end
  238. function CheatFXAAView:ApplyFXAASetting( )
  239. local function apply_setting()
  240. if self.main_FXAA then
  241. self.main_FXAA:ApplyFXAAMaterialProperties()
  242. end
  243. if self.ui_FXAA then
  244. self.ui_FXAA:ApplyFXAAMaterialProperties()
  245. end
  246. end
  247. TimeManager.GetInstance():StartTime("CheatFXAAView_ApplyFXAASetting", 0.5, apply_setting)
  248. end
  249. -- -- 初始化明度计算下拉框
  250. -- function CheatFXAAView:InitLuminanceCombox(just_reselect)
  251. -- local list = {
  252. -- {luminanceMode = LuminanceMode.Alpha},
  253. -- {luminanceMode = LuminanceMode.Green},
  254. -- {luminanceMode = LuminanceMode.Calculate},
  255. -- }
  256. -- local combox_str_list = {
  257. -- "Alpha",
  258. -- "Green",
  259. -- "Calculate",
  260. -- }
  261. -- self.cur_main_lm_mode_index = 1
  262. -- if self.main_FXAA.luminanceSource == LuminanceMode.Green then
  263. -- self.cur_main_lm_mode_index = 2
  264. -- elseif self.main_FXAA.luminanceSource == LuminanceMode.Calculate then
  265. -- self.cur_main_lm_mode_index = 3
  266. -- end
  267. -- local function update_main_luminance_func(index)
  268. -- self.cur_main_lm_mode_index = index
  269. -- self.main_FXAA.luminanceSource = list[index].luminanceMode
  270. -- -- self:ApplySetting()
  271. -- end
  272. -- local main_prefab_data = {Combox = "Combox",ComboxView = "ComboxView", ComboxItem = "ComboxItem", offset_y = -#list*ComboxItem.Height-9}
  273. -- if not self.main_combox then
  274. -- self.main_combox = Combox.New(self.main_combox_node, combox_str_list, update_main_luminance_func, 122, 38, nil, main_prefab_data, self.layer_name)
  275. -- SetAnchoredPositionX(self.main_combox.transform, 0, 0)
  276. -- self.main_combox:ResetData(combox_str_list, self.cur_main_lm_mode_index, update_main_luminance_func, 122, 38, nil, true)
  277. -- else
  278. -- self.main_combox:ResetData(combox_str_list, self.cur_main_lm_mode_index, update_main_luminance_func, 122, 38, nil, just_reselect)
  279. -- end
  280. -- self.cur_ui_lm_mode_index = 1
  281. -- if self.ui_FXAA.luminanceSource == LuminanceMode.Green then
  282. -- self.cur_ui_lm_mode_index = 2
  283. -- elseif self.ui_FXAA.luminanceSource == LuminanceMode.Calculate then
  284. -- self.cur_ui_lm_mode_index = 3
  285. -- end
  286. -- local function update_ui_luminance_func(index)
  287. -- self.cur_ui_lm_mode_index = index
  288. -- self.ui_FXAA.luminanceSource = list[index].luminanceMode
  289. -- -- self:ApplySetting()
  290. -- end
  291. -- local ui_prefab_data = {Combox = "Combox",ComboxView = "ComboxView", ComboxItem = "ComboxItem", offset_y = -#list*ComboxItem.Height-9}
  292. -- if not self.ui_combox then
  293. -- self.ui_combox = Combox.New(self.ui_combox_node, combox_str_list, update_ui_luminance_func, 122, 38, nil, ui_prefab_data, self.layer_name)
  294. -- SetAnchoredPositionX(self.ui_combox.transform, 0, 0)
  295. -- self.ui_combox:ResetData(combox_str_list, self.cur_ui_lm_mode_index, update_ui_luminance_func, 122, 38, nil, true)
  296. -- else
  297. -- self.ui_combox:ResetData(combox_str_list, self.cur_ui_lm_mode_index, update_ui_luminance_func, 122, 38, nil, just_reselect)
  298. -- end
  299. -- end
  300. function CheatFXAAView:HideAction(show)
  301. self.is_show = show
  302. -- SetLocalRotation(self.hideBtn.transform, 0, 0, self.is_show and 90 or 270)
  303. self.hideBtn.transform.localRotation = Quaternion.Euler(Vector3(0, 0, self.is_show and 90 or 270))
  304. local target_pos_x = (self.is_show and 0 or 366 ) - ClientConfig.iphone_x_offset_right
  305. self.con_anim_id = TweenLite.to(self, self.transform, TweenLite.UiAnimationType.ANCHORED_POSX, target_pos_x, 0.3, nil, TweenFunc.EASE_OUT_QUINT)
  306. end
  307. -- function CheatFXAAView:ApplySetting( )
  308. -- local errcode, err_msg
  309. -- if self.main_FXAA then
  310. -- errcode = self.main_FXAA:ApplySetting()
  311. -- err_msg = self.setting_errcode[errcode]
  312. -- if err_msg then
  313. -- print("Saber:CheatFXAAView [start:306] ------------------------------------------")
  314. -- Message.show(err_msg, "fault")
  315. -- end
  316. -- end
  317. -- if self.ui_FXAA then
  318. -- errcode = self.ui_FXAA:ApplySetting()
  319. -- err_msg = self.setting_errcode[errcode]
  320. -- if err_msg then
  321. -- print("Saber:CheatFXAAView [start:314] ------------------------------------------")
  322. -- Message.show(err_msg, "fault")
  323. -- end
  324. -- end
  325. -- self:InitCamsData()
  326. -- self:InitLuminanceCombox(true)
  327. -- end
  328. function CheatFXAAView:StopHideAction( )
  329. if self.con_anim_id then
  330. TweenLite.Stop(self.con_anim_id)
  331. SetAnchoredPositionX(self.transform, (self.is_show and 0 or 366 ) - ClientConfig.iphone_x_offset_right)
  332. end
  333. end
  334. function CheatFXAAView:DestroySuccess( )
  335. self:StopHideAction()
  336. end