源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2528 lines
70 KiB

  1. require("game.scene.sceneobj.SceneEffect")
  2. require("game.scene.sceneobj.AlphaObj")
  3. MapView = MapView or BaseClass(BaseController)
  4. local MapView = MapView
  5. local lua_resM = lua_resM
  6. local string_find = string.find
  7. local Material_New = Material.New
  8. local math_floor = math.floor
  9. local GameMath_GetDistance = GameMath.GetDistance
  10. MapView.DefaultMapRes = 1001
  11. MapView.NoAreaLoadEffect =
  12. {
  13. -- ["scene_tiaoyue"] = true,
  14. ["effect_gate_001"] = true,
  15. }
  16. MapView.NoLoadModel =
  17. {
  18. -- ["scene_tiaoyue"] = true,
  19. ["XSCCZ_TT03_05"] = true,
  20. }
  21. MapView.CustomEffect = {
  22. [1001] = {name = "1001effect", customEffect = true, layer = 1, x = 0, y = 0, z = 0, bound = {off_x = 0, off_y = 0,off_z=0, size_x = 50, size_y = 50,size_z = 50}, speed = 1, euler_x = 0, euler_y = 0, euler_z = 0, effectScale_x = 1, effectScale_y = 1, effectScale_z = 1, level = 1},
  23. [1003] = {name = "1003effect", customEffect = true, layer = 1, x = 0, y = 0, z = 0, bound = {off_x = 0, off_y = 0,off_z=0, size_x = 50, size_y = 50,size_z = 50}, speed = 1, euler_x = 0, euler_y = 0, euler_z = 0, effectScale_x = 1, effectScale_y = 1, effectScale_z = 1, level = 1},
  24. [1005] = {name = "1005_effect_1", customEffect = true, layer = 1, x = 0, y = 0, z = 0, bound = {off_x = 0, off_y = 0,off_z=0, size_x = 50, size_y = 50,size_z = 50}, speed = 1, euler_x = 0, euler_y = 0, euler_z = 0, effectScale_x = 1, effectScale_y = 1, effectScale_z = 1, level = 1},
  25. }
  26. MapView.CustomEffectBox =
  27. {
  28. -- ["scene_fountain01"] = 1000,
  29. -- ["xsc_shui_worldwaterdark"] = 900000,
  30. -- ["scene1004_worldwater"] = 900000,
  31. -- ["scene1004_poolwater"] = 900000,
  32. -- ["scene1002worldwater"] = 900000,
  33. -- ["shamo_shui_1_2"] = 900000,
  34. -- ["shamo_shui_1_1"] = 900000,
  35. }
  36. MapView.LoadBigScene =
  37. {
  38. --[1000] = true,
  39. --[1002] = true,
  40. --[1003] = true,
  41. --[1004] = true,
  42. --[1005] = true,
  43. --[1006] = true,
  44. --[5801] = true,
  45. }
  46. MapView.FullScreenEffect =
  47. {
  48. -- name = "1000effect", layer = 1, x = 0, y = 0,z = 0,bound = {off_x = 0, off_y = 0,off_z=0, size_x = 30000, size_y = 30000,size_z = 30000}, speed = 1, euler_x = 0, euler_y = 0, euler_z = 0, effectScale_x =1, effectScale_y = 1, effectScale_z = 1, level = 1,
  49. }
  50. MapView.WaveList = {
  51. -- ["screenwave"] = false,
  52. -- ["screenwave3"] = false,
  53. -- ["haidi_g11_2"] = false,
  54. }
  55. MapView.MustAreaLoadEffect =
  56. {
  57. -- ["scene_zudangmen"] = true
  58. }
  59. --不使用模型合批的地图
  60. MapView.NoCombineModel =
  61. {
  62. -- [5801] = true,
  63. }
  64. MapView.HideEffectScene =
  65. {
  66. -- [6610] = {
  67. -- ["shamo_shui_1_1"] = true,
  68. -- ["shamo_shui_1_2"] = true,
  69. -- ["scene_firebig01"] = true,
  70. -- ["scene_firebig01 (1)"] = true,
  71. -- ["scene_waterfall01"] = true,
  72. -- ["scene_sunshine04 (4)"] = true,
  73. -- },
  74. -- [6611] = {
  75. -- ["shamo_shui_1_1"] = true,
  76. -- ["shamo_shui_1_2"] = true,
  77. -- ["scene_firebig01"] = true,
  78. -- ["scene_firebig01 (1)"] = true,
  79. -- ["scene_waterfall01"] = true,
  80. -- ["scene_sunshine04 (4)"] = true,
  81. -- },
  82. -- [6612] = {
  83. -- ["shamo_shui_1_1"] = true,
  84. -- ["shamo_shui_1_2"] = true,
  85. -- ["scene_firebig01"] = true,
  86. -- ["scene_firebig01 (1)"] = true,
  87. -- ["scene_waterfall01"] = true,
  88. -- ["scene_sunshine04 (4)"] = true,
  89. -- },
  90. -- [6613] = {
  91. -- ["shamo_shui_1_1"] = true,
  92. -- ["shamo_shui_1_2"] = true,
  93. -- ["scene_firebig01"] = true,
  94. -- ["scene_firebig01 (1)"] = true,
  95. -- ["scene_waterfall01"] = true,
  96. -- ["scene_sunshine04 (4)"] = true,
  97. -- },
  98. }
  99. --全加载地图
  100. MapView.AllLoadScene = {
  101. [1001] = true,
  102. }
  103. --不使用动态剔除的场景
  104. MapView.NoDisibleLoadScene = {
  105. -- [1001] = true,
  106. }
  107. MapView.EnterSceneLoad = {
  108. -- [1001] = true,
  109. -- [1002] = true,
  110. -- [1006] = true,
  111. -- [1008] = true,
  112. -- [1009] = true,
  113. }
  114. MapView.FindWayVector2One = Vector2(0,0)
  115. MapView.FindWayVector2Second = Vector2(0,0)
  116. function MapView:__init()
  117. MapView.Instance = self
  118. self.mapLoaded = false
  119. self.curMapData = nil
  120. self.async_load_map_obj = nil
  121. self.effect_list = {}
  122. self.move_obj_list = {}
  123. self.specialModel_list = {}
  124. self.load_prefab_temp_target = {}
  125. self.preload_prefab_temp_target = {}
  126. self.preload_scene_id = nil
  127. self.model_list = {}
  128. self.area_load_mode = true
  129. self.load_model_count = nil
  130. self.enter_scene_want_load_count = 0
  131. self.alpha_model_list = {}
  132. self.material_obj_list = {}
  133. self.material_ab_list = {}
  134. self.last_cache_model_check_time = 0
  135. self.model_cache_map = {}
  136. self.model_id_res_map = {}
  137. self.open_model_cache_state = true
  138. self.open_abres_immediately_delete_mode = false
  139. self.combine_mini_model = {}
  140. self.model_root_map = {}
  141. self.model_local_state = {}
  142. self.combine_model_state = false
  143. self.min_combine_count = 5
  144. self.timeout_enter_scene = false
  145. self.regiest_model_new_mode = true
  146. self.open_big_scene_mode = false
  147. self.have_combine_model = {}
  148. self.open_dynamic_visible_model = false
  149. self.cache_effect_obj = {}
  150. self.cache_effect_mode = false
  151. self.zone_height = {}
  152. self.zone_block = {}
  153. self.zone_type = {}
  154. self.area_type_cache = {}
  155. self.has_water_effect = {}
  156. if SystemRuntimePlatform.IsIphone() then
  157. self.open_model_cache_state = false
  158. self.open_abres_immediately_delete_mode = true
  159. end
  160. if tonumber(AppConst.EnglineVer) > 70 then
  161. mapMgr.logicWidth = SceneObj.LogicRealRatio.x
  162. mapMgr.logicHeight = SceneObj.LogicRealRatio.y
  163. end
  164. local account_change = function()
  165. self:ForceChangeMap(true)
  166. end
  167. local role_change = function()
  168. self:ForceChangeMap(false)
  169. end
  170. GlobalEventSystem:Bind(EventName.CHANGE_ACCOUNT, account_change)
  171. GlobalEventSystem:Bind(EventName.CHANGE_ROLE, role_change)
  172. local timeout_enter_scene = function()
  173. self.timeout_enter_scene = true
  174. SapManager.Instance:WaitLoadTerrainFinish(false)
  175. end
  176. GlobalEventSystem:Bind(EventName.TIMEOUT_ENTER_SCENE,timeout_enter_scene)
  177. local func = function()
  178. local data = {}
  179. local effect_count = 0
  180. for k,v in pairs(self.effect_list) do
  181. effect_count = effect_count + 1
  182. end
  183. local model_count = 0
  184. for k,v in pairs(self.model_list) do
  185. model_count = model_count + 1
  186. end
  187. local model_cache_map_count = 0
  188. for k,v in pairs(self.model_cache_map) do
  189. model_cache_map_count = model_cache_map_count + 1
  190. end
  191. data.effect_count = effect_count
  192. data.model_count = model_count
  193. data.model_cache_map_count = model_cache_map_count
  194. GlobalEventSystem:Fire(EventName.SENT_MODULE_DEBUG_DATA,"mapview", data)
  195. end
  196. GlobalEventSystem:Bind(EventName.CHECK_MODULE_DEBUG_DATA,func)
  197. local callfunc = function(module_name,func)
  198. self.set_root_visible_data_tab = self.set_root_visible_data_tab or {
  199. ["mapview@showbuhongpei"] = {node_name = "buhongpei", bool = true},
  200. ["mapview@hidebuhongpei"] = {node_name = "buhongpei", bool = false},
  201. ["mapview@showmodelcom"] = {node_name = "model_com_root", bool = true},
  202. ["mapview@hidemodelcom"] = {node_name = "model_com_root", bool = false},
  203. ["mapview@showsplitmodel"] = {node_name = "splitmodel", bool = true},
  204. ["mapview@hidesplitmodel"] = {node_name = "splitmodel", bool = false},
  205. ["mapview@showdongzuo"] = {node_name = "dongzuo", bool = true},
  206. ["mapview@hidedongzuo"] = {node_name = "dongzuo", bool = false},
  207. ["mapview@showway"] = {node_name = "xunlu", bool = true},
  208. ["mapview@hideway"] = {node_name = "xunlu", bool = false},
  209. ["mapview@showterrain"] = {node_name = "special", bool = true},
  210. ["mapview@hideterrain"] = {node_name = "special", bool = false},
  211. ["mapview@showshui"] = {node_name = "shui", bool = true},
  212. ["mapview@hideshui"] = {node_name = "shui", bool = false},
  213. ["mapview@showfog"] = {node_name = "fog", bool = true},
  214. ["mapview@hidefog"] = {node_name = "fog", bool = false},
  215. ["mapview@showaction"] = {node_name = "action", bool = true},
  216. ["mapview@hideaction"] = {node_name = "action", bool = false},
  217. ["mapview@showwater"] = {node_name = "water", bool = true},
  218. ["mapview@hidewater"] = {node_name = "water", bool = false},
  219. ["mapview@showspecial"] = {node_name = "special", bool = true},
  220. ["mapview@hidespecial"] = {node_name = "special", bool = false},
  221. }
  222. if module_name and func and self.set_root_visible_data_tab[module_name.."@"..func] then
  223. --简单的节点修改就直接在上面添加走这里,免得看起来太累赘
  224. local temp = self.set_root_visible_data_tab[module_name.."@"..func]
  225. self.set_root_show_call(GameObject.Find(temp.node_name) or self[temp.node_name],temp.bool)
  226. elseif module_name == "mapview" and func == "clear" then
  227. self:ClearData()
  228. elseif module_name == "mapview" and func == "combine" then
  229. self:CombineModel()
  230. elseif module_name == "mapview" and func == "hidescene" then
  231. self.model_root = GameObject.Find("model")
  232. self.set_root_show_call(self.model_root,false)
  233. if self.model_parent and self.model_parent ~= GameObject.Find("root").transform then
  234. self.set_root_show_call(self.model_parent,false)
  235. end
  236. elseif module_name == "mapview" and func == "showscene" then
  237. self.set_root_show_call(self.model_root,true)
  238. if self.model_parent and self.model_parent ~= GameObject.Find("root").transform then
  239. self.set_root_show_call(self.model_parent,true)
  240. end
  241. elseif module_name == "mapview" and func == "hidesky" then
  242. self.sky_root = GameObject.Find("Sky")
  243. self.sky_root_2 = GameObject.Find("sky")
  244. self.set_root_show_call(self.sky_root,false)
  245. self.set_root_show_call(self.sky_root_2,false)
  246. elseif module_name == "mapview" and func == "showsky" then
  247. self.set_root_show_call(self.sky_root,true)
  248. self.set_root_show_call(self.sky_root_2,true)
  249. elseif module_name == "mapview" and func == "hiderootall" then
  250. self:SetAllRootShow(false)
  251. elseif module_name == "mapview" and func == "showrootall" then
  252. self:SetAllRootShow(true)
  253. end
  254. end
  255. self.rootshowcall = callfunc
  256. self.set_root_show_call = function( root,bool )
  257. if not IsNull(root) and not IsNull(root.gameObject) then
  258. root.gameObject:SetActive(bool)
  259. end
  260. end
  261. GlobalEventSystem:Bind(EventName.DO_MODULE_DEBUG_FUNC,callfunc)
  262. end
  263. function MapView:SetAllRootShow( bool )
  264. if not self.rootshowcall or not self.set_root_show_call then
  265. return
  266. end
  267. if bool then
  268. if SceneManager.Instance:GetSceneId() ~= 1001 then
  269. self.rootshowcall("mapview","showscene")
  270. end
  271. self.rootshowcall("mapview","showsky")
  272. else
  273. if SceneManager.Instance:GetSceneId() ~= 1001 then
  274. self.rootshowcall("mapview","hidescene")
  275. end
  276. self.rootshowcall("mapview","hidesky")
  277. end
  278. -------------------------
  279. if self.set_root_visible_data_tab then
  280. for k,v in pairs(self.set_root_visible_data_tab) do
  281. if string.find(k, bool and "show" or "hide") then
  282. local obj = self[v.node_name]
  283. if IsNull(obj) then
  284. obj = GameObject.Find(v.node_name)
  285. if not IsNull(obj) then
  286. self[v.node_name] = obj
  287. end
  288. end
  289. self.set_root_show_call(obj , bool)
  290. end
  291. end
  292. end
  293. end
  294. function MapView:CheckCombineModel()
  295. self.support_model_combine = false
  296. if tonumber(AppConst.EnglineVer) >= 74 and self:CheckIOSCombine() then
  297. if self.curResId then
  298. local no_combine = MapView.NoCombineModel[tonumber(self.curResId)]
  299. if not no_combine then
  300. self.support_model_combine = true
  301. end
  302. else
  303. self.support_model_combine = true
  304. end
  305. end
  306. if not self.regiest_model_new_mode then
  307. self.support_model_combine = false
  308. end
  309. end
  310. function MapView:CheckIOSCombine()
  311. if SystemRuntimePlatform.IsIphone() then
  312. if RoleManager.Instance.mainRoleInfo.level == 1 and SystemMemoryLevel.Cur == SystemMemoryLevel.Hight then
  313. return true
  314. else
  315. return false
  316. end
  317. else
  318. return true
  319. end
  320. end
  321. function MapView:getInstance()
  322. if MapView.Instance == nil then
  323. MapView.New()
  324. end
  325. return MapView.Instance
  326. end
  327. function MapView:GetResID( is_minimap )
  328. if is_minimap then
  329. return Config.ConfigMiniMap[tonumber(self.curMapId)] or self.curResId
  330. end
  331. return self.curResId
  332. end
  333. function MapView:GetResIDByScene( scene, func )
  334. local scene_id = tonumber(scene)
  335. local res_id = Config.ConfigMiniMap[scene_id]
  336. if res_id then
  337. func(res_id)
  338. return
  339. end
  340. local load_call_back = function(objs)
  341. if objs and objs[0] then
  342. local txt = objs[0]
  343. mapMgr:LoadOtherMap(scene_id,txt)
  344. local mapdata = mapMgr:MapByScene(scene_id)
  345. func(mapdata.resId)
  346. if scene_id ~= self.curMapId then
  347. mapMgr:ClearMap(scene_id)
  348. end
  349. end
  350. end
  351. lua_resM:loadTextAsset(self.load_prefab_temp_target,"mapdata" .. scene_id,tonumber(scene_id),load_call_back,ASSETS_LEVEL.HIGHT)
  352. end
  353. function MapView:GetMapSize()
  354. if self.curMapData then
  355. return co.TableXY(self.curMapData.mapWidth,self.curMapData.mapHeight)
  356. else
  357. return co.TableXY(0,0)
  358. end
  359. end
  360. function MapView:Update( cam_pos )
  361. --print("-------Update-------")
  362. for index,obj in pairs(self.move_obj_list) do
  363. obj:Update()
  364. end
  365. self:CheckOuttimeCacheMode()
  366. end
  367. function MapView:Load( mapId, load_map_func, load_effect_finish )
  368. print("tanar: [MapView 420]=> Load: ",mapId)
  369. self.wait_clear_map = false
  370. local call_out_succeed = false
  371. local load_terrain_succeed = function()
  372. if call_out_succeed then
  373. return
  374. end
  375. self:DeletePreLoadMap()
  376. self.mapLoaded = true
  377. call_out_succeed = true
  378. load_map_func()
  379. self:ProcessSpecialModel()
  380. self:ProcessSkyModel()
  381. if not self.curResId then
  382. return
  383. end
  384. self.area_load_mode = true
  385. -- if MapView.NoDisibleLoadScene[tonumber(self.curResId)] then
  386. -- self.open_dynamic_visible_model = false
  387. -- else
  388. -- self.open_dynamic_visible_model = true
  389. -- end
  390. -- if SceneManager.Instance:IsStarFightScene() then
  391. -- self.open_dynamic_visible_model = false
  392. -- end
  393. if not SystemRuntimePlatform.IsIphone() then
  394. --使用全加载模式
  395. self.open_dynamic_visible_model = false
  396. end
  397. ShaderTools.ClearMaterialData()
  398. self:CheckCombineMiniModel()
  399. self:RegiestEffectList()
  400. --模型创建方式
  401. -- if not MapView.EnterSceneLoad[tonumber(self.curResId)] then
  402. -- if self.regiest_model_new_mode then
  403. -- self:RegiestModelListNew()
  404. -- else
  405. -- self:RegiestModelList()
  406. -- end
  407. -- end
  408. self:RegiestMoveObjList()
  409. self:RegiestAlphaModelList()
  410. self:RegisterElevatorModelList()
  411. load_effect_finish(1)
  412. --[[
  413. if not self.load_model_count or self.enter_scene_want_load_count == 0 then
  414. load_effect_finish(1)
  415. else
  416. self.load_effect_finish_func = load_effect_finish
  417. local timeout_finfish = function()
  418. if self.load_effect_finish_func then
  419. self.load_effect_finish_func(1)
  420. self.load_effect_finish_func = nil
  421. self.timeout_enter_scene = true
  422. SapManager.Instance:WaitLoadTerrainFinish(false)
  423. end
  424. end
  425. self.check_load_model_event = setTimeout(timeout_finfish,25)
  426. end
  427. ]]
  428. -- if not G_DEBUG_MODE then
  429. -- self:LoadSpiltModelList() --全加载
  430. self:RegiestModelListNew() --SAP
  431. -- end
  432. SapManager:getInstance():ForceCheckFarModelLoad()
  433. --新手场景特殊处理
  434. if self.curResId and self.curResId == 1001 then
  435. Shader.SetGlobalFloat("_GlobalSceneAlpha", 1.0)
  436. end
  437. end
  438. local load_finish = function( same_scene )
  439. -- if G_DEBUG_MODE then
  440. -- load_terrain_succeed()
  441. -- return
  442. -- end
  443. -- if Config.ConfigSceneWaveModel[self.curResId] then
  444. -- self:LoadWaterMaterial()
  445. -- end
  446. local load_scene_call_back
  447. load_scene_call_back = function(objs)
  448. if mapId ~= self.curMapId then
  449. return
  450. end
  451. if objs then
  452. self.async_load_map_obj = UnitySceneManager.LoadSceneAsync(self:GetLoadSceneRes(tostring(self.curResId)))
  453. self.async_load_map_obj.allowSceneActivation = true
  454. local load_into = function()
  455. if self.check_load_event then
  456. GlobalTimerQuest:CancelQuest(self.check_load_event)
  457. self.check_load_event = nil
  458. end
  459. if self.async_load_map_obj then
  460. self.async_load_map_obj = nil
  461. end
  462. load_terrain_succeed()
  463. end
  464. local try_load_time = 0
  465. local check_load = function()
  466. if self.async_load_map_obj then
  467. local progress = self.async_load_map_obj.progress
  468. --尝试加载资源去触发场景加载回调,别问
  469. if progress > 0.88 and Time.time - try_load_time > 1 then
  470. try_load_time = Time.time
  471. GlobalEventSystem:Fire(EventName.OPEN_WORLD_LEVEL_VIEW)
  472. GlobalEventSystem:Fire(EventName.CLOSE_WORLD_LEVEL_VIEW)
  473. end
  474. local max_progress = SystemRuntimePlatform.IsWindowsEditor() and 0.89 or 1
  475. if progress >= max_progress then
  476. load_into()
  477. elseif self.open_big_scene_mode then
  478. load_effect_finish(progress)
  479. end
  480. end
  481. end
  482. if self.check_load_event then
  483. GlobalTimerQuest:CancelQuest(self.check_load_event)
  484. end
  485. self.check_load_event = GlobalTimerQuest:AddPeriodQuest(check_load, 0.05, -1)
  486. local time_out = function()
  487. self.init_terrain_timeout_handle = nil
  488. if not call_out_succeed then
  489. self.load_terrain_timeout = true
  490. end
  491. print("tanar: MapView [525] =========== ")
  492. load_into()
  493. end
  494. self.init_terrain_timeout_handle = setTimeout(time_out,15)
  495. else
  496. local load_again = function()
  497. lua_resM:loadPrefabs(self.load_prefab_temp_target,"terrain_scene_" .. self:GetLoadSceneRes(self.curResId),{}, load_scene_call_back, false, ASSETS_LEVEL.HIGHT)
  498. end
  499. setTimeout(load_again,0.3)
  500. end
  501. end
  502. if not same_scene then
  503. lua_resM:loadPrefabs(self.load_prefab_temp_target,"terrain_scene_" .. self:GetLoadSceneRes(self.curResId),{}, load_scene_call_back, false, ASSETS_LEVEL.HIGHT)
  504. else
  505. setTimeout(load_terrain_succeed,0.1)
  506. end
  507. local time_out = function()
  508. self.load_terrain_timeout_handle = nil
  509. if not call_out_succeed then
  510. self.load_terrain_timeout = true
  511. end
  512. load_terrain_succeed()
  513. end
  514. self.load_terrain_timeout_handle = setTimeout(time_out,25)
  515. end
  516. self:LoadMapData(mapId, load_finish)
  517. end
  518. function MapView:LoadMapData( mapId, load_finish)
  519. self.curMapData = nil
  520. local load_call_back
  521. load_call_back = function(objs)
  522. if objs and objs[0] then
  523. local txt = objs[0]
  524. mapMgr:LoadMap(mapId,txt)
  525. local same_scene = false
  526. local newCurMapData = mapMgr:CurMap()
  527. if self.curResId == newCurMapData.resId then
  528. same_scene = true
  529. end
  530. if self.curResId then
  531. self:ClearData(same_scene)
  532. end
  533. self.curResId = newCurMapData.resId
  534. self.curMapData = newCurMapData
  535. self.curMapId = mapId
  536. self:CheckCombineModel()
  537. if self.scene_effect_container == nil then
  538. self.scene_effect_container = UiFactory.createChild(panelMgr:GetParent("SceneContainer"), UIType.EmptyObject, "effect_container")
  539. end
  540. if load_finish then
  541. load_finish(same_scene)
  542. load_finish = nil
  543. end
  544. else
  545. local loadagain = function()
  546. lua_resM:loadTextAsset(self.load_prefab_temp_target,"mapdata" .. mapId,tonumber(mapId),load_call_back,ASSETS_LEVEL.HIGHT)
  547. end
  548. setTimeout(loadagain,1)
  549. end
  550. end
  551. lua_resM:loadTextAsset(self.load_prefab_temp_target,"mapdata" .. mapId,tonumber(mapId),load_call_back,ASSETS_LEVEL.HIGHT)
  552. local check_load_finish = function()
  553. if load_finish then
  554. GameError.Instance:SendErrorToPHP("load map data error when want to change scene " .. mapId)
  555. end
  556. end
  557. self.load_mapdata_handle = setTimeout(check_load_finish,15)
  558. end
  559. --- area_type:AreaDataIndex
  560. function MapView:SetDynamicArea(area_id,area_type)
  561. if self.curMapData then
  562. --动态区域改变清理缓存
  563. self.zone_block = {}
  564. self.zone_type = {}
  565. self.curMapData:SetDynamicArea(area_id,area_type)
  566. end
  567. end
  568. function MapView:GetSceneCenterPos()
  569. if not self.curMapData then
  570. Debugger.LogWarning("GetSceneCenterPos when map not load")
  571. return Vector3(0,0,0)
  572. end
  573. return Vector3(self.curMapData.mapWidth/MainCamera.PixelsToUnits/2, self.curMapData.mapHeight/MainCamera.PixelsToUnits/2, 0)
  574. end
  575. function MapView:DetectFirstUnblockPoint(pos,dir,max_dist)
  576. if not self.curMapData then
  577. print(debug.traceback())
  578. Debugger.LogWarning("DetectFirstUnblockPoint when map not load")
  579. return nil
  580. end
  581. dir.y = -dir.y
  582. local p = self.curMapData:DetectFirstUnblockPoint(pos,dir,max_dist)
  583. return p
  584. end
  585. function MapView:FindWay(pos1,pos2,range)
  586. if not self.curMapData then
  587. print(debug.traceback())
  588. Debugger.LogWarning("FindWay when map not load")
  589. return nil
  590. end
  591. MapView.FindWayVector2One.x = pos1.x
  592. MapView.FindWayVector2One.y = pos1.y
  593. MapView.FindWayVector2Second.x = pos2.x
  594. MapView.FindWayVector2Second.y = pos2.y
  595. local objs = self.curMapData:FindWay(MapView.FindWayVector2One,MapView.FindWayVector2Second,range)
  596. if objs then
  597. local ret = {}
  598. for i=1,objs.Length do
  599. local ret_obj = co.TableXY(objs[objs.Length-i].x,objs[objs.Length-i].y)
  600. table.insert(ret,ret_obj)
  601. end
  602. return ret
  603. end
  604. return objs
  605. end
  606. function MapView:IsStraightLine(pos1,pos2)
  607. if not self.curMapData then
  608. print(debug.traceback())
  609. -- Debugger.LogWarning("IsStraightLine when map not load")
  610. return false
  611. end
  612. return self.curMapData:IsStraightLine(pos1,pos2)
  613. end
  614. function MapView:DetectLastUnblockPoint(pos,dir,dist,jump_state)
  615. if not self.curMapData then
  616. print(debug.traceback())
  617. -- Debugger.LogWarning("DetectLastUnblockPoint when map not load")
  618. return pos
  619. end
  620. --dir.y = -dir.y
  621. jump_state = false
  622. local point = nil
  623. point = self.curMapData:DetectLastUnblockPoint(pos,dir,dist,jump_state)
  624. return point
  625. end
  626. function MapView:GetZoneHeight(x, y)
  627. if not self.curMapData then
  628. return -1
  629. end
  630. x = math_floor(x)
  631. y = math_floor(y)
  632. local index = x .. "-" .. y
  633. local cache = self.zone_height[index]
  634. if cache then
  635. return cache
  636. end
  637. local height = self.curMapData:GetZoneHeight(x+1,y+1)/100
  638. self.zone_height[index] = height
  639. return height
  640. end
  641. function MapView:IsBlockXY(x, y)
  642. if not self.curMapData then
  643. return nil
  644. end
  645. x = math_floor(x)
  646. y = math_floor(y)
  647. local index = x .. "-" .. y
  648. local cache = self.zone_block[index]
  649. if cache ~= nil then
  650. return cache
  651. end
  652. local block = self.curMapData:IsBlock(x,y,false)
  653. self.zone_block[index] = block
  654. return block
  655. end
  656. -- AreaDataIndex:area_type
  657. function MapView:IsAreaType(x, y, area_type)
  658. if not self.curMapData then
  659. return false
  660. end
  661. -- if area_type == AreaDataIndex.JumpType then
  662. -- return false
  663. -- end
  664. x = math_floor(x)
  665. y = math_floor(y)
  666. local index = x .. "-" .. y .. "-" .. area_type
  667. local cache = self.zone_type[index]
  668. if cache ~= nil then
  669. return cache
  670. end
  671. local result = false
  672. local cur_type = self.curMapData:GetAreaType(x,y)
  673. if bit.band(cur_type,area_type) ~= 0 then
  674. result = true
  675. end
  676. self.zone_type[index] = result
  677. return result
  678. end
  679. function MapView:GetAreaType(x, y)
  680. if not self.curMapData then
  681. return
  682. end
  683. x = math_floor(x)
  684. y = math_floor(y)
  685. local index = x .. "-" .. y
  686. local _type = self.area_type_cache[index]
  687. if _type == nil then
  688. _type = self.curMapData:GetAreaType(x,y)
  689. self.area_type_cache[index] = _type
  690. end
  691. return _type
  692. end
  693. function MapView:PreLoadMapRes( scene_id, callback )
  694. if not scene_id then
  695. return
  696. end
  697. local func = function(res_id)
  698. if tonumber(res_id) == tonumber(self.curResId) then
  699. --前后场景地图资源一样不需走预加载
  700. if callback then
  701. callback()
  702. end
  703. return
  704. end
  705. self.preload_scene_id = res_id
  706. lua_resM:loadPrefabs(self.preload_prefab_temp_target,"terrain_scene_" .. self:GetLoadSceneRes(res_id),{}, callback, false, ASSETS_LEVEL.HIGHT)
  707. end
  708. self:GetResIDByScene( scene_id, func )
  709. end
  710. function MapView:DeletePreLoadMap()
  711. if self.preload_scene_id then
  712. lua_resM:clearReference(self.preload_prefab_temp_target)
  713. self.preload_scene_id = nil
  714. end
  715. end
  716. function MapView:ClearData(same_scene)
  717. self.action_obj_list = {}
  718. -- self:CancelFarModelTimer()
  719. self:UnRegiestEffectList()
  720. self:UnRegiestSpecialModelList()
  721. self:UnRegiestModelList()
  722. self:UnRegiestMoveObjList()
  723. self:UnRegiestAlphaModelList()
  724. self:UnRegiestElevatorModelList()
  725. self.mapLoaded = false
  726. for k,effect in pairs(self.effect_list) do
  727. effect:DeleteMe()
  728. end
  729. for k,v in pairs(self.specialModel_list) do
  730. v:DeleteMe()
  731. end
  732. for k,obj in pairs(self.move_obj_list) do
  733. obj:DeleteMe()
  734. end
  735. for k,v in pairs(MapView.WaveList) do
  736. MapView.WaveList[k] = false
  737. end
  738. self.effect_last_show_state = nil
  739. MainCamera.Instance:DestoryScreenEffectCamere()
  740. if not same_scene then
  741. lua_resM:clearReference(self.load_prefab_temp_target)
  742. self.material_ab_list = {}
  743. for k,cache_list in ipairs(self.model_cache_map) do
  744. for index,info in ipairs(cache_list) do
  745. destroy(info.obj)
  746. end
  747. end
  748. self.model_cache_map = {}
  749. for index,obj in ipairs(self.material_obj_list) do
  750. destroy(obj)
  751. end
  752. self.material_obj_list = {}
  753. for index,abname in ipairs(self.material_ab_list) do
  754. resMgr:UnloadAssetBundle(abname,true,1)
  755. end
  756. for index,obj in pairs(self.model_list) do
  757. destroy(obj)
  758. end
  759. for index,obj in pairs(self.model_root_map) do
  760. destroy(obj)
  761. end
  762. self.model_list = {}
  763. self.model_root_map = {}
  764. self.combine_mini_model = {}
  765. self.combine_model_state = false
  766. self.open_big_scene_mode = false
  767. self.model_parent = nil
  768. self.have_combine_model = {}
  769. if self.model_com_root then
  770. destroy(self.model_com_root)
  771. self.model_com_root = nil
  772. end
  773. local node = GameObject.Find("dongzuo")
  774. if node then
  775. node:SetActive(false)
  776. end
  777. end
  778. if self.curMapId then
  779. mapMgr:ClearMap(self.curMapId)
  780. end
  781. if self.load_mapdata_handle then
  782. GlobalTimerQuest:CancelQuest(self.load_mapdata_handle)
  783. self.load_mapdata_handle = nil
  784. end
  785. if self.check_load_model_event then
  786. GlobalTimerQuest:CancelQuest(self.check_load_model_event)
  787. self.check_load_model_event = nil
  788. end
  789. if self.bind_mainrole_move_event then
  790. GlobalTimerQuest:CancelQuest(self.bind_mainrole_move_event)
  791. self.bind_mainrole_move_event = nil
  792. end
  793. self.zone_block = {}
  794. self.zone_height = {}
  795. self.zone_type = {}
  796. self.area_type_cache = {}
  797. self.effect_list = {}
  798. self.specialModel_list = {}
  799. self.move_obj_list = {}
  800. self.model_id_res_map = {}
  801. self.has_water_effect = {}
  802. self.load_model_count = nil
  803. self.enter_scene_want_load_count = 0
  804. self.timeout_enter_scene = false
  805. self.load_terrain_timeout = false
  806. if self.load_terrain_timeout_handle then
  807. GlobalTimerQuest:CancelQuest(self.load_terrain_timeout_handle)
  808. self.load_terrain_timeout_handle = nil
  809. end
  810. if self.init_terrain_timeout_handle then
  811. GlobalTimerQuest:CancelQuest(self.init_terrain_timeout_handle)
  812. self.init_terrain_timeout_handle = nil
  813. end
  814. self.cache_effect_obj = {}
  815. if self.scene_effect_container then
  816. destroy(self.scene_effect_container)
  817. self.scene_effect_container = nil
  818. end
  819. if self.load_terrain_force_check_handle then
  820. TimerQuest.CancelQuest(GlobalTimerQuest, self.load_terrain_force_check_handle)
  821. self.load_terrain_force_check_handle = nil
  822. end
  823. self.regiest_model_finish = false
  824. end
  825. --全屏特效显示隐藏
  826. function MapView:UpdateFullScreenEffect( posx, posy )
  827. if IsTableEmpty(self.effect_list) then
  828. return
  829. end
  830. local cur_map_id = tonumber(self.curResId)
  831. --目前只有1001需要
  832. if cur_map_id and cur_map_id == 1001 then
  833. local hide_max_x, hide_max_y = 0, 29170 --超过这个边界需要隐藏
  834. local cur_show_state = true
  835. if (hide_max_x > 0 and posx > hide_max_x) or (hide_max_y > 0 and posy > hide_max_y) or self:IsAreaType(posx/SceneObj.LogicRealRatio.x, posy/SceneObj.LogicRealRatio.y, AreaDataIndex.IndoorType) then
  836. cur_show_state = false
  837. end
  838. if self.effect_last_show_state ~= nil and self.effect_last_show_state == cur_show_state then
  839. return
  840. end
  841. self.effect_last_show_state = cur_show_state
  842. for k,v in pairs(self.effect_list) do
  843. if v.fullScreen or v.customEffect then
  844. v:SetActive(cur_show_state)
  845. end
  846. end
  847. end
  848. end
  849. function MapView:RegiestEffectList()
  850. local scene_effect = Config.ConfigSceneEffect.EffectInfo[tonumber(self.curMapId)]
  851. local area_load = true
  852. if scene_effect then
  853. -- if SystemRuntimePlatform.IsIphone() then
  854. -- area_load = true
  855. -- end
  856. for effect_id,effect in pairs(scene_effect) do
  857. if area_load and not MapView.NoAreaLoadEffect[effect.name] then
  858. if not effect.disabled then
  859. if effect.fullScreen then
  860. self.effect_list[effect_id] = SceneEffect.New(effect,MainCamera:getInstance().camera_gameObject,tonumber(self.curMapId))
  861. self:RegiestMoveEvent()
  862. else
  863. effect.id = effect_id
  864. local obj =
  865. {
  866. id = effect_id,
  867. type = SapManager.ObjType.Effect,
  868. pos = co.TableXYZ(effect.x,effect.z,effect.y),
  869. bound_offset = co.TableXYZ(effect.bound.off_x * effect.effectScale_x,effect.bound.off_z * effect.effectScale_z, effect.bound.off_y * effect.effectScale_y),
  870. size = co.TableXY(effect.bound.size_x * effect.effectScale_x,effect.bound.size_z * effect.effectScale_z,effect.bound.size_y * effect.effectScale_y),
  871. data = {id = effect_id,obj = effect},
  872. }
  873. local custom_size = MapView.CustomEffectBox[effect.name]
  874. if custom_size then
  875. obj.size = co.TableXY(custom_size,custom_size,custom_size)
  876. end
  877. if self.area_load_mode then
  878. SapManager:getInstance():RegisterObj(obj)
  879. else
  880. self:CreateEffect(obj.data)
  881. end
  882. end
  883. end
  884. end
  885. end
  886. end
  887. local loadback = function(transform)
  888. local hide_effect = MapView.HideEffectScene[self.curMapId]
  889. if hide_effect then
  890. for effect_name,state in pairs(hide_effect) do
  891. local effect = transform:Find(effect_name)
  892. if effect then
  893. effect.gameObject:SetActive(false)
  894. end
  895. end
  896. end
  897. if not self.cache_effect_mode then
  898. SapManager.Instance:WaitLoadParticleFinish(false)
  899. return
  900. end
  901. if MapView.NoDisibleLoadScene[tonumber(self.curResId)] then
  902. SapManager.Instance:WaitLoadParticleFinish(false)
  903. return
  904. end
  905. if scene_effect and not IsNull(transform) then
  906. for effect_id,effect in pairs(scene_effect) do
  907. if not effect.obj_name then
  908. --旧版配置不支持
  909. SapManager.Instance:WaitLoadParticleFinish(false)
  910. return
  911. end
  912. effect.id = effect_id
  913. local obj =
  914. {
  915. id = effect_id,
  916. type = SapManager.ObjType.CacheEffect,
  917. pos = co.TableXYZ(effect.x,effect.z,effect.y),
  918. bound_offset = co.TableXYZ(effect.bound.off_x * effect.effectScale_x,effect.bound.off_z * effect.effectScale_z, effect.bound.off_y * effect.effectScale_y),
  919. size = co.TableXY(effect.bound.size_x * effect.effectScale_x,effect.bound.size_z * effect.effectScale_z,effect.bound.size_y * effect.effectScale_y),
  920. data = {id = effect_id,obj = effect},
  921. }
  922. local custom_size = MapView.CustomEffectBox[effect.name]
  923. if custom_size then
  924. obj.size = co.TableXY(custom_size,custom_size,custom_size)
  925. end
  926. SapManager:getInstance():RegisterObj(obj)
  927. end
  928. local length = transform.childCount
  929. if length > 0 then
  930. for i = 0,length -1 do
  931. local trans = transform:GetChild(i)
  932. if trans and trans.gameObject then
  933. trans.gameObject:SetActive(false)
  934. self.cache_effect_obj[trans.name] = trans.gameObject
  935. end
  936. end
  937. end
  938. end
  939. local next_frame = function()
  940. SapManager.Instance:WaitLoadParticleFinish(false)
  941. end
  942. setTimeout(next_frame,0.01)
  943. end
  944. if MapView.CustomEffect[tonumber(self.curResId)] then
  945. local effect_data = MapView.CustomEffect[tonumber(self.curResId)]
  946. local data = {
  947. id = self.curMapId,
  948. obj = effect_data,
  949. }
  950. if self.cache_effect_mode then
  951. SapManager.Instance:WaitLoadParticleFinish(true)
  952. end
  953. self.effect_list[data.id] = SceneEffect.New(data.obj,self.scene_effect_container,tonumber(self.curMapId),loadback)
  954. self.effect_last_show_state = nil
  955. end
  956. end
  957. function MapView:CreateCacheEffect( data )
  958. if data and data.obj then
  959. local name = data.obj.obj_name
  960. local game_object = self.cache_effect_obj[name]
  961. if game_object then
  962. game_object:SetActive(true)
  963. end
  964. end
  965. end
  966. function MapView:DeleteCacheEffect( name )
  967. if name then
  968. local game_object = self.cache_effect_obj[name]
  969. if game_object then
  970. game_object:SetActive(false)
  971. end
  972. end
  973. end
  974. function MapView:UnRegiestEffectList()
  975. if SystemMemoryLevel.Cur == SystemMemoryLevel.Low then
  976. -- return
  977. end
  978. if self.mapLoaded and self.area_load_mode then
  979. local scene_effect = Config.ConfigSceneEffect.EffectInfo[tonumber(self.curMapId)]
  980. if scene_effect then
  981. for effect_id,effect in pairs(scene_effect) do
  982. SapManager:getInstance():UnRegisterObj(SapManager.ObjType.Effect,effect_id)
  983. end
  984. end
  985. end
  986. end
  987. function MapView:CreateEffect( data )
  988. if not self.mapLoaded then
  989. LogError("want to create effect but map not load finfish, id = " .. data.id )
  990. return
  991. end
  992. if self.scene_effect_container then
  993. self.effect_list[data.id] = SceneEffect.New(data.obj,self.scene_effect_container,tonumber(self.curMapId))
  994. end
  995. end
  996. function MapView:RefreshEffect()
  997. if not self.mapLoaded then --特效设置为true就不走画质和帧率的再次刷新
  998. return
  999. end
  1000. local scene_effect = Config.ConfigSceneEffect.EffectInfo[tonumber(self.curMapId)]
  1001. if not scene_effect then
  1002. return
  1003. end
  1004. local settingLv = lua_settingM:GetEffectLevel()
  1005. for k,v in pairs(self.effect_list) do
  1006. local config = scene_effect[k] or MapView.FullScreenEffect
  1007. if config then
  1008. if config.level <= settingLv then
  1009. v:SetActive(true)
  1010. else
  1011. v:SetActive(false)
  1012. end
  1013. end
  1014. end
  1015. end
  1016. function MapView:DeleteEffect( obj_id )
  1017. local effect = self.effect_list[obj_id]
  1018. if effect then
  1019. effect:DeleteMe()
  1020. self.effect_list[obj_id] = nil
  1021. end
  1022. end
  1023. function MapView:RegiestSpecialModelList()
  1024. if SystemMemoryLevel.Cur == SystemMemoryLevel.Low then
  1025. return
  1026. end
  1027. local scene_effect = Config.ConfigSceneSpecialModel.SpecialModelInfo[tonumber(self.curMapId)]
  1028. if scene_effect then
  1029. for effect_id,effect in pairs(scene_effect) do
  1030. effect.id = effect_id
  1031. local obj =
  1032. {
  1033. id = effect_id,
  1034. type = SapManager.ObjType.SpecialModel,
  1035. pos = co.TableXYZ(effect.x,effect.z,effect.y),
  1036. bound_offset = co.TableXYZ(effect.bound.off_x * effect.effectScale_x,effect.bound.off_z * effect.effectScale_z, effect.bound.off_y * effect.effectScale_y),
  1037. size = co.TableXY(effect.bound.size_x * effect.effectScale_x,effect.bound.size_z * effect.effectScale_z,effect.bound.size_y * effect.effectScale_y),
  1038. data = {id = effect_id,obj = effect},
  1039. }
  1040. local custom_size = MapView.CustomEffectBox[effect.name]
  1041. if custom_size then
  1042. obj.size = co.TableXY(custom_size,custom_size,custom_size)
  1043. end
  1044. if self.area_load_mode then
  1045. SapManager:getInstance():RegisterObj(obj)
  1046. else
  1047. self:CreateEffect(obj.data)
  1048. end
  1049. end
  1050. end
  1051. end
  1052. function MapView:UnRegiestSpecialModelList()
  1053. if SystemMemoryLevel.Cur == SystemMemoryLevel.Low then
  1054. return
  1055. end
  1056. if self.mapLoaded and self.area_load_mode then
  1057. local scene_effect = Config.ConfigSceneSpecialModel.SpecialModelInfo[tonumber(self.curMapId)]
  1058. if scene_effect then
  1059. for effect_id,effect in pairs(scene_effect) do
  1060. SapManager:getInstance():UnRegisterObj(SapManager.ObjType.SpecialModel,effect_id)
  1061. end
  1062. end
  1063. end
  1064. end
  1065. function MapView:CreateSpecialModel( data )
  1066. if not self.mapLoaded then
  1067. LogError("want to create effect but map not load finfish, id = " .. data.id )
  1068. return
  1069. end
  1070. if self.scene_effect_container then
  1071. self.specialModel_list[data.id] = SceneEffect.New(data.obj,self.scene_effect_container,tonumber(self.curMapId))
  1072. end
  1073. end
  1074. function MapView:DeleteSpecialModel( obj_id )
  1075. local effect = self.specialModel_list[obj_id]
  1076. if effect then
  1077. effect:DeleteMe()
  1078. self.specialModel_list[obj_id] = nil
  1079. end
  1080. end
  1081. function MapView:RegiestMoveObjList()
  1082. local obj_config = Config.ConfigSceneMoveObj[self.curResId]
  1083. if obj_config then
  1084. for index, data in ipairs(obj_config) do
  1085. local pos = data.active_info.pos
  1086. local osize = data.active_info.size
  1087. local offset = data.active_info.offset
  1088. local modelobj =
  1089. {
  1090. id = index,
  1091. type = SapManager.ObjType.MoveObj,
  1092. pos = co.TableXYZ(pos.x* MainCamera.PixelsToUnits, pos.y* MainCamera.PixelsToUnits, pos.z* MainCamera.PixelsToUnits),
  1093. bound_offset = co.TableXYZ(offset.x* MainCamera.PixelsToUnits,offset.y* MainCamera.PixelsToUnits),
  1094. size = co.TableXY(osize.x * MainCamera.PixelsToUnits,osize.y * MainCamera.PixelsToUnits),
  1095. data = {id = index,obj = data},
  1096. }
  1097. SapManager:getInstance():RegisterObj(modelobj)
  1098. end
  1099. end
  1100. end
  1101. function MapView:UnRegiestMoveObjList()
  1102. local obj_config = Config.ConfigSceneMoveObj[self.curResId]
  1103. if obj_config then
  1104. for index, data in ipairs(obj_config) do
  1105. SapManager:getInstance():UnRegisterObj(SapManager.ObjType.MoveObj,index)
  1106. end
  1107. end
  1108. end
  1109. function MapView:CreateMoveObj( data )
  1110. local obj = MoveObj.New( data,self.curMapId,self.scene_effect_container )
  1111. obj:CreateModel()
  1112. if not self.move_obj_list[data.id] then
  1113. self.move_obj_list[data.id] = obj
  1114. else
  1115. LogError("want to create same moveobj id = " .. data.id )
  1116. end
  1117. end
  1118. function MapView:DeleteMoveObj( index )
  1119. local obj = self.move_obj_list[index]
  1120. if obj then
  1121. obj:DeleteMe()
  1122. obj = nil
  1123. end
  1124. self.move_obj_list[index] = nil
  1125. end
  1126. function MapView:RegiestModelList()
  1127. local model_root = GameObject.Find("splitmodel")
  1128. local model_config = Config["model" .. self.curResId]
  1129. if model_root and model_config then
  1130. self.model_parent = model_root.transform
  1131. SetGlobalPosition3D(self.model_parent,0, 0, 0)
  1132. SetLocalScale(self.model_parent,1,1,1)
  1133. self.model_parent.localEulerAngles = Vector3(0, 0, 0)
  1134. self.load_model_count = 0
  1135. for index, data in pairs(model_config) do
  1136. local info = {
  1137. id = index,
  1138. obj = data,
  1139. }
  1140. if not self.area_load_mode or self.combine_mini_model[data[1]] then
  1141. if not self.combine_model_state then
  1142. self:CreateModel(info,self.model_parent)
  1143. end
  1144. elseif self:IsLocalFile(data[1]) then
  1145. self:CreateModel(info,self.model_parent)
  1146. else
  1147. self:RegiestModel(info)
  1148. end
  1149. end
  1150. end
  1151. self.regiest_model_finish = true
  1152. end
  1153. function MapView:RegiestModel(info)
  1154. local data = info.obj
  1155. local index = info.id
  1156. local is_far = false
  1157. local pos_x = (data[3]) * MainCamera.PixelsToUnits
  1158. local pos_y = (data[5]) * MainCamera.PixelsToUnits
  1159. local pos_z = (data[4]) * MainCamera.PixelsToUnits
  1160. local max_size = math.max(math.max(data[15],data[17]),data[16]) * MainCamera.PixelsToUnits * 3
  1161. local bound_offset = co.TableXYZ(data[12]* MainCamera.PixelsToUnits,data[14]* MainCamera.PixelsToUnits, data[13]* MainCamera.PixelsToUnits)
  1162. --远景包围盒适配
  1163. local is_check_detail = false
  1164. local check_type = false
  1165. local offset = 0
  1166. if data[4] < -1 and max_size < 2000 then
  1167. is_check_detail = true
  1168. else
  1169. if Config.ConfigDetailMapViewCheckModel[self.curResId] then
  1170. if Config.ConfigDetailMapViewCheckModel[self.curResId][data[2]] then
  1171. is_check_detail = true
  1172. check_type = Config.ConfigDetailMapViewCheckModel[self.curResId][data[2]].type
  1173. end
  1174. end
  1175. end
  1176. if is_check_detail then
  1177. if check_type == 1 then
  1178. if SystemMemoryLevel.Cur == SystemMemoryLevel.Hight then --高端机采用更精确算法
  1179. pos_x = (data[3]) * MainCamera.PixelsToUnits
  1180. pos_y = (data[4]) * MainCamera.PixelsToUnits
  1181. pos_z = (data[5]) * MainCamera.PixelsToUnits
  1182. is_far = true
  1183. bound_offset = co.TableXYZ(data[12]* MainCamera.PixelsToUnits,data[13]* MainCamera.PixelsToUnits, data[14]* MainCamera.PixelsToUnits)
  1184. else
  1185. is_far = false
  1186. max_size = max_size * 3
  1187. bound_offset = co.TableXYZ(data[12]* MainCamera.PixelsToUnits,data[13]* MainCamera.PixelsToUnits, data[14]* MainCamera.PixelsToUnits + 2000)
  1188. end
  1189. elseif check_type == 2 then
  1190. is_far = false
  1191. max_size = max_size * 3
  1192. bound_offset = co.TableXYZ(data[12]* MainCamera.PixelsToUnits,data[13]* MainCamera.PixelsToUnits, data[14]* MainCamera.PixelsToUnits + 2000)
  1193. end
  1194. end
  1195. local modelobj =
  1196. {
  1197. id = index,
  1198. type = SapManager.ObjType.Model,
  1199. pos = co.TableXYZ(pos_x, pos_y, pos_z),
  1200. -- rot = Quaternion.Euler(data[6], data[7], data[8]), --这是一个四元数
  1201. bound_offset = bound_offset,
  1202. size = co.TableXYZ(max_size,max_size,max_size),
  1203. data = {id = index,obj = data},
  1204. is_far = is_far
  1205. }
  1206. SapManager:getInstance():RegisterObj(modelobj)
  1207. end
  1208. function MapView:RegiestModelListNew()
  1209. local model_root = GameObject.Find("splitmodel")
  1210. local model_config = Config["model" .. self.curResId]
  1211. if model_config then
  1212. --场景基础资源包加载超时失败,改成挂在通用根节点
  1213. if not model_root then
  1214. model_root = GameObject.Find("root")
  1215. end
  1216. self.model_parent = model_root.transform
  1217. SetGlobalPosition3D(self.model_parent,0, 0, 0)
  1218. SetLocalScale(self.model_parent,1,1,1)
  1219. self.model_parent.localEulerAngles = Vector3(0, 0, 0)
  1220. self.load_model_count = 0
  1221. SapManager.Instance:WaitLoadTerrainFinish(true)
  1222. local same_res_map = {}
  1223. for index, data in pairs(model_config) do
  1224. if not MapView.NoLoadModel[data[1]] then
  1225. local res = data[1]
  1226. if not same_res_map[res] then
  1227. same_res_map[res] = {}
  1228. end
  1229. table.insert(same_res_map[res],index)
  1230. end
  1231. end
  1232. for res,list in pairs(same_res_map) do
  1233. if not self.area_load_mode or self.combine_mini_model[res] then
  1234. if not self.combine_model_state or (self.combine_mini_model[res] and self.open_dynamic_visible_model) then
  1235. self:CreateModelList(res,list,model_config)
  1236. end
  1237. elseif self:IsLocalFile(res) then
  1238. self.combine_mini_model[res] = true
  1239. self:CreateModelList(res,list,model_config)
  1240. else
  1241. for key,index in pairs(list) do
  1242. local info = {
  1243. id = index,
  1244. obj = model_config[index],
  1245. }
  1246. self:RegiestModel(info)
  1247. end
  1248. end
  1249. end
  1250. end
  1251. self.regiest_model_finish = true
  1252. end
  1253. function MapView:CreateModelList(res,list,model_config)
  1254. self.enter_scene_want_load_count = self.enter_scene_want_load_count + 1
  1255. local cache_list = self.model_cache_map[res]
  1256. local map_res = self.curResId
  1257. local load_res = function( objs, cache )
  1258. if objs and ( cache or objs[0]) and self.mapLoaded then
  1259. if map_res ~= self.curResId then
  1260. if not cache and objs[0] then
  1261. destroy(objs[0])
  1262. end
  1263. return
  1264. end
  1265. for k,index in pairs(list) do
  1266. local last_model = self.model_list[index]
  1267. if not last_model then
  1268. if cache then
  1269. if #cache_list > 1 then
  1270. local info = table.remove(cache_list,#cache_list)
  1271. if info and not IsNull(info.obj) then
  1272. info.obj:SetActive(true)
  1273. self:InitObj( info.obj,nil,model_config[index],single_parent,index, res )
  1274. end
  1275. else
  1276. if cache_list[1] and not IsNull(cache_list[1].obj) then
  1277. cache_list[1].time = os.time()
  1278. cache_list[1].obj:SetActive(true)
  1279. self:InitObj( nil, cache_list[1].obj,model_config[index],single_parent,index, res )
  1280. cache_list[1].obj:SetActive(false)
  1281. end
  1282. end
  1283. else
  1284. self:InitObj( nil,objs[0],model_config[index],single_parent,index, res )
  1285. end
  1286. end
  1287. if self.open_dynamic_visible_model then
  1288. local info = {
  1289. id = index,
  1290. obj = model_config[index],
  1291. }
  1292. self:RegiestModel(info)
  1293. end
  1294. end
  1295. else
  1296. print("------load res error--------",res)
  1297. end
  1298. self.load_model_count = (self.load_model_count or 0) + 1
  1299. if self.support_model_combine then
  1300. self:CombineModelList(res,list)
  1301. end
  1302. local next_frame = function()
  1303. self:CheckTerrainLoadFinish()
  1304. end
  1305. if self.combine_model_state then
  1306. setTimeout(next_frame,0.01)
  1307. else
  1308. next_frame()
  1309. end
  1310. end
  1311. if cache_list then
  1312. if #cache_list > 0 then
  1313. load_res(true,true)
  1314. return
  1315. end
  1316. end
  1317. local ab_name = "terrain_prefab_" .. res
  1318. lua_resM:loadPrefabs(self.load_prefab_temp_target,ab_name,res, load_res, true, ASSETS_LEVEL.NORMAL)
  1319. end
  1320. function MapView:InitObj( cache_model,obj,data,parent,id,model_name )
  1321. local model = cache_model or newObject(obj)
  1322. model.name = data[2]
  1323. if parent then
  1324. model.transform:SetParent(parent)
  1325. end
  1326. SetLocalScale(model.transform, data[9], data[10], data[11])
  1327. model.transform.localEulerAngles = Vector3(data[6], data[7], data[8])
  1328. SetGlobalPosition3D(model.transform,data[3], data[5], data[4])
  1329. self:LoadModelLight(model,data)
  1330. self.model_list[id] = model
  1331. self.model_id_res_map[id] = model_name
  1332. self.model_local_state[data[1]] = true
  1333. end
  1334. function MapView:CombineModelList(res,list)
  1335. local single_parent = self:GetSingleParent(res)
  1336. for k,v in pairs(list) do
  1337. if not IsNull(self.model_list[v]) then
  1338. self.model_list[v].transform:SetParent(single_parent)
  1339. else
  1340. logWarn("CombineModelList Error:" .. res)
  1341. end
  1342. end
  1343. if self.combine_mini_model[res] and not self.combine_model_state and self.support_model_combine then
  1344. local root = self.model_root_map[res]
  1345. if not IsNull(root) then
  1346. Util.StaticBatchingUtilityCombine(root)
  1347. --GameError.Instance:SendErrorMsg("---CombineModelList---" .. res)
  1348. -- GameError.Instance:SendErrorMsg("---CombineModelList---" .. res)
  1349. end
  1350. end
  1351. if self.open_dynamic_visible_model then
  1352. for k,index in pairs(list) do
  1353. local model = self.model_list[index]
  1354. if not IsNull(model) then
  1355. model:SetActive(false)
  1356. self.have_combine_model[index] = true
  1357. else
  1358. print("model is null:" .. res .. "-" .. index)
  1359. end
  1360. end
  1361. end
  1362. end
  1363. function MapView:GetSingleParent(model_name)
  1364. if not self.support_model_combine then
  1365. return self.model_parent
  1366. end
  1367. local single_parent = self.model_root_map[model_name] or GameObject.Find("splitmodel/" .. model_name .. "_com")
  1368. if self.load_terrain_timeout and not single_parent then
  1369. single_parent = GameObject.Find("root/" .. model_name .. "_com")
  1370. end
  1371. if not single_parent then
  1372. if IsNull(self.model_parent) then
  1373. self.model_parent = GameObject.Find("root").transform
  1374. end
  1375. if IsNull(self.model_com_root) then
  1376. self.model_com_root = UiFactory.createChild(self.model_parent, UIType.EmptyObject, "scene_model_root")
  1377. end
  1378. self.model_com_root.layer = LayerMask.NameToLayer("Default")
  1379. local model_root = UiFactory.createChild(self.model_com_root.transform, UIType.EmptyObject, model_name .. "_com")
  1380. model_root.layer = LayerMask.NameToLayer("Default")
  1381. single_parent = model_root.transform
  1382. SetGlobalPosition3D(single_parent,0, 0, 0)
  1383. SetLocalScale(single_parent,1,1,1)
  1384. single_parent.localEulerAngles = Vector3(0, 0, 0)
  1385. if self.support_model_combine then
  1386. self.model_root_map[model_name] = model_root
  1387. end
  1388. else
  1389. if IsNull(single_parent) then
  1390. single_parent = self.model_parent
  1391. self.timeout_enter_scene = true
  1392. else
  1393. single_parent = single_parent.transform
  1394. end
  1395. end
  1396. return single_parent
  1397. end
  1398. function MapView:CreateModel(info,parent)
  1399. parent = parent or self.model_parent
  1400. if not info or not parent then
  1401. return
  1402. end
  1403. local visible_model = self.model_list[info.id]
  1404. if not IsNull(visible_model) then
  1405. visible_model:SetActive(true)
  1406. return
  1407. end
  1408. self.enter_scene_want_load_count = self.enter_scene_want_load_count + 1
  1409. local data = info.obj
  1410. local model_name = data[1]
  1411. local single_parent = self:GetSingleParent(model_name)
  1412. local map_res = self.curResId
  1413. local load_res = function( objs, cache )
  1414. if objs and ( cache or objs[0]) and self.mapLoaded then
  1415. if map_res ~= self.curResId then
  1416. if cache then
  1417. destory(objs)
  1418. end
  1419. return
  1420. end
  1421. if cache then
  1422. objs:SetActive(true)
  1423. self:InitObj(objs,nil,data,single_parent,info.id,model_name)
  1424. else
  1425. self:InitObj(nil,objs[0],data,single_parent,info.id,model_name)
  1426. end
  1427. else
  1428. print("------load res error--------",model_name)
  1429. end
  1430. self.load_model_count = (self.load_model_count or 0) + 1
  1431. local next_frame = function()
  1432. self:CheckTerrainLoadFinish()
  1433. end
  1434. if self.combine_model_state then
  1435. setTimeout(next_frame,0.01)
  1436. else
  1437. next_frame()
  1438. end
  1439. end
  1440. local function load_call_back(objs, cache)
  1441. local load = function()
  1442. load_res(objs, cache)
  1443. end
  1444. --避免模型在缓存中时直接返回打乱模型注册流程,延迟一帧加载
  1445. --setTimeout(load,0.01)
  1446. load()
  1447. end
  1448. local ab_name = "terrain_prefab_" .. model_name
  1449. local cache_list = self.model_cache_map[model_name]
  1450. if cache_list then
  1451. if #cache_list > 0 then
  1452. local length = #cache_list
  1453. local info = table.remove(cache_list,length)
  1454. if info and not IsNull(info.obj) then
  1455. load_call_back(info.obj,true)
  1456. return
  1457. end
  1458. end
  1459. end
  1460. lua_resM:loadPrefabs(self.load_prefab_temp_target,ab_name,model_name, load_call_back, true, ASSETS_LEVEL.NORMAL)
  1461. end
  1462. function MapView:CheckTerrainLoadFinish()
  1463. if self.regiest_model_finish and not self.timeout_enter_scene and self.load_effect_finish_func then
  1464. if self.load_model_count >= self.enter_scene_want_load_count then
  1465. --静态合批
  1466. if not self.regiest_model_new_mode and self.support_model_combine and not self.combine_model_state then
  1467. self:CombineModel()
  1468. end
  1469. self.combine_model_state = true
  1470. --模型水效果
  1471. local wave_info = Config.ConfigSceneWaveModel[self.curResId]
  1472. if wave_info then
  1473. for objname,data in pairs(wave_info) do
  1474. self:LoadScreenWaveObj(objname,data.material,data.effect,data.add)
  1475. end
  1476. end
  1477. --地图加载完成回调
  1478. if self.load_effect_finish_func then
  1479. self.load_effect_finish_func(1)
  1480. self.load_effect_finish_func = nil
  1481. end
  1482. SapManager.Instance:WaitLoadTerrainFinish(false)
  1483. else
  1484. local per = self.load_model_count/self.enter_scene_want_load_count
  1485. if self.load_effect_finish_func then
  1486. self.load_effect_finish_func(per)
  1487. end
  1488. if per >= 0.95 and not self.load_terrain_force_check_handle and self.load_effect_finish_func then
  1489. local cur_map = self.curResId
  1490. local force_check = function()
  1491. self.load_terrain_force_check_handle = nil
  1492. if self.load_effect_finish_func and cur_map == self.curResId then
  1493. self.load_effect_finish_func(1)
  1494. self.load_effect_finish_func = nil
  1495. SapManager.Instance:WaitLoadTerrainFinish(false)
  1496. end
  1497. end
  1498. self.load_terrain_force_check_handle = setTimeout(force_check,5)
  1499. end
  1500. end
  1501. end
  1502. end
  1503. function MapView:CombineModel()
  1504. for name,root in pairs(self.model_root_map) do
  1505. if self.combine_mini_model[name] then
  1506. if not IsNull(root) then
  1507. Util.StaticBatchingUtilityCombine(root)
  1508. -- print("------combine_mini_model--------",name)
  1509. else
  1510. -- print("------StaticBatchingUtilityCombine empty root --------",name)
  1511. end
  1512. else
  1513. -- print("------not combine_mini_model--------",name)
  1514. end
  1515. end
  1516. end
  1517. function MapView:LoadModelLight(model,data)
  1518. if model.gameObject then
  1519. local mesh = model.gameObject:GetComponentInChildren(typeof(UnityEngine.MeshRenderer)) or model.gameObject:GetComponentInChildren(typeof(UnityEngine.SkinnedMeshRenderer))
  1520. if tonumber(data[26]) == 1 then
  1521. mesh.lightmapIndex = tonumber(data[27])
  1522. if not mesh.isPartOfStaticBatch then
  1523. mesh.lightmapScaleOffset = Vector4(data[28],data[29],data[30],data[31])
  1524. end
  1525. self:ReplaceMaterial(mesh.sharedMaterial)
  1526. mesh.gameObject.isStatic = true
  1527. else
  1528. self:ReplaceMaterial(mesh.sharedMaterial)
  1529. mesh.gameObject.isStatic = false
  1530. end
  1531. -- local wave_info = Config.ConfigSceneWaveModel[self.curResId]
  1532. -- if wave_info then
  1533. -- local wave_data = wave_info[data[2]]
  1534. -- if wave_data then
  1535. -- self:LoadScreenWaveObj( data[2], wave_data.material,wave_data.effect,wave_data.add )
  1536. -- end
  1537. -- end
  1538. end
  1539. end
  1540. function MapView:ProcessSpecialModel()
  1541. local specObj = GameObject.Find("special")
  1542. if specObj == nil then
  1543. return
  1544. end
  1545. local childCount = specObj.transform.childCount
  1546. for i = 0, childCount - 1 do
  1547. local child = specObj.transform:GetChild(i)
  1548. local mesh = child.gameObject:GetComponentInChildren(typeof(UnityEngine.MeshRenderer))
  1549. if mesh ~= nil then
  1550. self:ReplaceMaterial(mesh.sharedMaterial)
  1551. end
  1552. end
  1553. end
  1554. function MapView:ProcessSkyModel()
  1555. local skyObj = GameObject.Find("Sky")
  1556. if skyObj == nil then
  1557. return
  1558. end
  1559. local childCount = skyObj.transform.childCount
  1560. for i = 0, childCount - 1 do
  1561. local child = skyObj.transform:GetChild(i)
  1562. local mesh = child.gameObject:GetComponentInChildren(typeof(UnityEngine.MeshRenderer))
  1563. if mesh ~= nil and mesh.sharedMaterial then
  1564. self:ReplaceMaterial(mesh.sharedMaterial)
  1565. --mesh.sharedMaterial.renderQueue = 2800
  1566. end
  1567. end
  1568. end
  1569. function MapView:ReplaceMaterial(mat)
  1570. if mat == nil or mat.shader == nil then
  1571. return
  1572. end
  1573. ShaderTools.ChangeMaterial(mat)
  1574. end
  1575. function MapView:DeleteModel(id)
  1576. if not id then
  1577. LogWarning("MapView DeleteModel ID is nil")
  1578. return
  1579. end
  1580. local model = self.model_list[id]
  1581. if self.have_combine_model[id] and not IsNull(model) then
  1582. model:SetActive(false)
  1583. return
  1584. end
  1585. if not IsNull(model) then
  1586. local model_res = self.model_id_res_map[id]
  1587. if model_res then
  1588. if self.open_model_cache_state then
  1589. if not self.model_cache_map[model_res] then
  1590. self.model_cache_map[model_res] = {}
  1591. end
  1592. local info = {obj = model, time = os.time()}
  1593. table.insert(self.model_cache_map[model_res],info)
  1594. model:SetActive(false)
  1595. else
  1596. self:DestoryModel(model,model_res)
  1597. end
  1598. end
  1599. end
  1600. self.model_list[id] = nil
  1601. end
  1602. function MapView:DestoryModel(model,name)
  1603. destroy(model)
  1604. if self.open_abres_immediately_delete_mode then
  1605. resMgr:UnloadAssetBundle("terrain_prefab_" .. name,true,1)
  1606. end
  1607. end
  1608. function MapView:UnRegiestModelList()
  1609. if self.mapLoaded then
  1610. local model_root = GameObject.Find("splitmodel")
  1611. local model_config = Config["model" .. self.curResId]
  1612. if model_root and model_config then
  1613. for id,obj in pairs(model_config) do
  1614. if not self.combine_mini_model[obj[1]] or self.open_dynamic_visible_model then
  1615. SapManager:getInstance():UnRegisterObj(SapManager.ObjType.Model,id)
  1616. end
  1617. end
  1618. end
  1619. end
  1620. end
  1621. function MapView:RegiestMoveEvent( )
  1622. local onMainRoleMove = function(posx,posy)
  1623. if not self.last_elevator_event_time or Time.time - self.last_elevator_event_time > 0.07 then
  1624. self.last_elevator_event_time = Time.time
  1625. self:UpdateElevatorModel(posx,posy)
  1626. end
  1627. if not self.last_move_event_time or Time.time - self.last_move_event_time > 0.3 then
  1628. self.last_move_event_time = Time.time
  1629. self:UpdateAlphaModel(posx,posy)
  1630. self:UpdateFullScreenEffect(posx,posy)
  1631. self:TriggerStory(posx,posy)
  1632. end
  1633. end
  1634. if not self.bind_mainrole_move_event then
  1635. self.bind_mainrole_move_event = GlobalEventSystem:Bind(ObjectEventType.MAINROLE_MOVE_EVENT_IMME,onMainRoleMove)
  1636. end
  1637. end
  1638. function MapView:RegisterElevatorModelList( )
  1639. local elevator_cfg = Config.ConfigSceneElevatorModel[self.curResId]
  1640. if elevator_cfg then
  1641. self:RegiestMoveEvent()
  1642. self.elevator_vo_list = elevator_cfg
  1643. --调试
  1644. self:OnDebugElevatorMolde()
  1645. end
  1646. end
  1647. function MapView:OnDebugElevatorMolde( )
  1648. -- for k,vo in pairs(self.elevator_vo_list) do
  1649. -- if vo.is_debug_show then
  1650. -- self:CreateDebugConfigObj(k, vo)
  1651. -- end
  1652. -- end
  1653. end
  1654. function MapView:CreateDebugConfigObj( k, vo )
  1655. local res = "mrsd_xuanzhong_001"
  1656. self.debug_obj_list = self.debug_obj_list or {}
  1657. local function load_call_back( objs, is_gameObject )
  1658. if not objs or not objs[0] then
  1659. return
  1660. end
  1661. local gameObject = is_gameObject and objs[0] or newObject(objs[0])
  1662. local key = k..vo.obj_name
  1663. gameObject.name = key
  1664. self.debug_obj_list[key] = gameObject
  1665. local scale = vo.range/140
  1666. SetLocalScale(gameObject.transform, scale)
  1667. gameObject.transform:SetParent(panelMgr:GetParent("SceneObjContainer").transform)
  1668. SetGlobalPosition3D(gameObject.transform,vo.start_pos.x/100,vo.start_pos.y/100,vo.ele_start_pos.y)
  1669. end
  1670. lua_resM:loadPrefab(self, res, res, load_call_back, nil, ASSETS_LEVEL.LOW)
  1671. end
  1672. function MapView:UnRegiestElevatorModelList()
  1673. self.elevator_vo_list = {}
  1674. if self.debug_obj_list then
  1675. for k,go in pairs(self.debug_obj_list) do
  1676. destroy(go)
  1677. go = nil
  1678. end
  1679. self.debug_obj_list = false
  1680. end
  1681. end
  1682. function MapView:UpdateElevatorModel( posx, posy )
  1683. if not self.elevator_vo_list or #self.elevator_vo_list == 0 then
  1684. return
  1685. end
  1686. local main_role = Scene.Instance.main_role
  1687. if not main_role then
  1688. return
  1689. end
  1690. if main_role:IsInState(PoseState.ELEVATOR) or main_role:IsGhostMode() then
  1691. return
  1692. end
  1693. local temp_elevator_vo = false
  1694. local x, y = posx, posy
  1695. for k,vo in pairs(self.elevator_vo_list) do
  1696. local range = vo.range * vo.range
  1697. if GameMath_GetDistance(x, y, vo.start_pos.x, vo.start_pos.y, false) <= range then
  1698. temp_elevator_vo = vo
  1699. break
  1700. end
  1701. end
  1702. if temp_elevator_vo then
  1703. main_role:DoElevator(temp_elevator_vo)
  1704. return true
  1705. end
  1706. end
  1707. function MapView:RegiestAlphaModelList()
  1708. local info = Config.ConfigSceneAlphaModel[self.curResId]
  1709. if info then
  1710. self.alpha_model_list = {}
  1711. for index,config in pairs(info) do
  1712. local data = {
  1713. task_list = config.task_list,
  1714. name = config.name,
  1715. minx = config.minx,
  1716. miny = config.miny,
  1717. maxx = config.maxx,
  1718. maxy = config.maxy,
  1719. alpha = config.alpha,
  1720. time = config.time,
  1721. obj = nil,
  1722. destory = false,
  1723. }
  1724. table.insert(self.alpha_model_list,data)
  1725. end
  1726. self:RegiestMoveEvent()
  1727. if RoleManager and RoleManager.Instance.mainRoleInfo then
  1728. self:UpdateAlphaModel(RoleManager.Instance.mainRoleInfo.pos_x,RoleManager.Instance.mainRoleInfo.pos_y)
  1729. end
  1730. end
  1731. end
  1732. function MapView:UnRegiestAlphaModelList()
  1733. for index,data in ipairs(self.alpha_model_list) do
  1734. if data.obj then
  1735. data.obj:DeleteMe()
  1736. data.destory = true
  1737. data.obj = nil
  1738. end
  1739. end
  1740. self.alpha_model_list = {}
  1741. end
  1742. function MapView:UpdateAlphaModel(posx,posy)
  1743. if #self.alpha_model_list > 0 then
  1744. for index,data in pairs(self.alpha_model_list) do
  1745. local is_task_math = true
  1746. if data.task_list then
  1747. is_task_math = TaskModel:getInstance():IsBetweenTaskListState(data.task_list)
  1748. end
  1749. if is_task_math then
  1750. if data.minx < posx and data.maxx > posx and data.miny < posy and data.maxy > posy then
  1751. if not data.obj then
  1752. data.obj = AlphaObj.New(data.name,data.alpha,data.time)
  1753. if data.obj.load_succeed then
  1754. data.destory = false
  1755. else
  1756. data.obj:DeleteMe()
  1757. data.obj = nil
  1758. end
  1759. end
  1760. else
  1761. if data.obj and not data.destory then
  1762. local callback = function()
  1763. if data.obj then
  1764. data.obj:DeleteMe()
  1765. data.obj = nil
  1766. end
  1767. end
  1768. data.obj:HideEffect( callback )
  1769. data.destory = true
  1770. end
  1771. end
  1772. end
  1773. end
  1774. end
  1775. end
  1776. function MapView:TriggerStory(posx, posy)
  1777. local scene_story_config = Config.Story[self.curMapId]
  1778. if scene_story_config then
  1779. local story_id = TaskModel:getInstance():GetTriggerStoryId()
  1780. local story_cfg = scene_story_config[story_id]
  1781. if story_cfg and story_cfg.trigger_range then
  1782. local main_role = Scene.Instance.main_role
  1783. if not main_role then
  1784. return
  1785. end
  1786. local range = story_cfg.trigger_range * story_cfg.trigger_range
  1787. if GameMath_GetDistance(posx, posy, story_cfg.trigger_pos.x, story_cfg.trigger_pos.y, false) <= range then
  1788. main_role:DoStory(story_cfg)
  1789. end
  1790. end
  1791. end
  1792. end
  1793. function MapView:LoadScreenWaveObj( objname, material, effect, add_mat )
  1794. -- if self.has_water_effect[objname] then
  1795. -- return
  1796. -- end
  1797. -- local obj = GameObject.Find("splitmodel/" .. objname) or GameObject.Find("special/" .. objname)
  1798. -- if not obj then
  1799. -- return
  1800. -- end
  1801. -- --组队副本不开水纹效果
  1802. -- if SceneManager.Instance:IsTeamDungeonScene() then
  1803. -- return
  1804. -- end
  1805. -- self.has_water_effect[objname] = true
  1806. -- local mesh_renderer = obj:GetComponentInChildren(typeof(UnityEngine.MeshRenderer)) or game_object:GetComponentInChildren(typeof(UnityEngine.SkinnedMeshRenderer))
  1807. -- if not add_mat then
  1808. -- local ori_mat = MapView.WaveList[material]
  1809. -- if not ori_mat then
  1810. -- print("material not load succeed:" .. material)
  1811. -- return
  1812. -- end
  1813. -- local mat = Material_New(ori_mat)
  1814. -- mat:SetFloat("_Noise_Power", effect or Config.ConfigSceneWaveModel.DefaultWave)
  1815. -- SetMaterialTexture(mat,GetMaterialTexture(mesh_renderer.material))
  1816. -- mesh_renderer.material = mat
  1817. -- mesh_renderer.material.renderQueue = 1999
  1818. -- table.insert(self.material_obj_list,mat)
  1819. -- else
  1820. -- local mats = mesh_renderer.sharedMaterials
  1821. -- local lua_mats = {}
  1822. -- local mats_len = mats.Length
  1823. -- local wave_index = nil
  1824. -- for i = 0, mats_len - 1 do
  1825. -- lua_mats[i + 1] = mats[i]
  1826. -- if IsNull(mats[i]) or string_find(mats[i].name, material, 1, true) then
  1827. -- wave_index = i + 1
  1828. -- end
  1829. -- end
  1830. -- if not wave_index then
  1831. -- wave_index = mats_len + 1
  1832. -- end
  1833. -- local wave_effect = lua_mats[wave_index]
  1834. -- if not wave_effect then
  1835. -- local ori_mat = MapView.WaveList[material]
  1836. -- if not ori_mat then
  1837. -- print("material not load succeed:" .. material)
  1838. -- return
  1839. -- end
  1840. -- wave_effect = Material_New(ori_mat)
  1841. -- wave_effect:SetFloat("_Noise_Power", effect or Config.ConfigSceneWaveModel.DefaultWave)
  1842. -- lua_mats[wave_index] = wave_effect
  1843. -- mesh_renderer.sharedMaterials = lua_mats
  1844. -- mesh_renderer.material.renderQueue = 1999
  1845. -- table.insert(self.material_obj_list,wave_effect)
  1846. -- end
  1847. -- end
  1848. end
  1849. function MapView:CheckOuttimeCacheMode()
  1850. if os.time() - self.last_cache_model_check_time < 10 or SystemMemoryLevel.Cur == SystemMemoryLevel.Low then
  1851. return
  1852. end
  1853. self.last_cache_model_check_time = os.time()
  1854. for res,cache_list in pairs(self.model_cache_map) do
  1855. for i = #cache_list,1,-1 do
  1856. if os.time() - cache_list[i].time > 60 then
  1857. local info = table.remove(cache_list,i)
  1858. self:DestoryModel(info.obj,res)
  1859. end
  1860. end
  1861. end
  1862. end
  1863. function MapView:ForceChangeMap( load_empty_map )
  1864. local clear_map = function()
  1865. self:ClearData()
  1866. self.curMapId = nil
  1867. self.curResId = nil
  1868. end
  1869. if load_empty_map and LoginModel.Instance.reconnect_on_game then
  1870. local res = "empty"
  1871. local load_call_back = function()
  1872. if self.wait_clear_map then
  1873. UnitySceneManager.LoadSceneAsync(res)
  1874. clear_map()
  1875. self.wait_clear_map = false
  1876. end
  1877. end
  1878. self.wait_clear_map = true
  1879. lua_resM:loadPrefabs(self.load_prefab_temp_target,"terrain_scene_" .. res,{}, load_call_back, true, ASSETS_LEVEL.HIGHT)
  1880. else
  1881. clear_map()
  1882. end
  1883. end
  1884. function MapView:LoadWaterMaterial()
  1885. --加载模型水纹材质
  1886. for material,value in pairs(MapView.WaveList) do
  1887. local ab_name = "terrain_material_" .. material
  1888. local function callback(objs)
  1889. if objs and objs[0] then
  1890. MapView.WaveList[material] = objs[0]
  1891. end
  1892. end
  1893. lua_resM:loadMateaial(self.load_prefab_temp_target,ab_name, material, callback, ASSETS_LEVEL.HIGHT)
  1894. end
  1895. end
  1896. function MapView:CheckCombineMiniModel()
  1897. if self.combine_model_state or not self.support_model_combine then
  1898. return
  1899. end
  1900. if not self.curResId then
  1901. return
  1902. end
  1903. local model_root = GameObject.Find("splitmodel")
  1904. local model_config = Config["model" .. self.curResId]
  1905. if model_root and model_config then
  1906. local res_count_map = {}
  1907. for index, data in pairs(model_config) do
  1908. local resname = data[1]
  1909. if not res_count_map[resname] then
  1910. res_count_map[resname] = 0
  1911. end
  1912. res_count_map[resname] = res_count_map[resname] + 1
  1913. end
  1914. self.combine_mini_model = {}
  1915. for resname,count in pairs(res_count_map) do
  1916. if count > self.min_combine_count then
  1917. self.combine_mini_model[resname] = true
  1918. end
  1919. end
  1920. end
  1921. end
  1922. function MapView:IsLocalFile( res )
  1923. --新手村地图全加载
  1924. if MapView.AllLoadScene[self.curResId] then
  1925. Scene.Instance.load_scene_timeout_max = true
  1926. return true
  1927. end
  1928. do return false end
  1929. if SystemRuntimePlatform.IsIphone() then
  1930. return false
  1931. end
  1932. if SceneManager.Instance:IsStarFightScene() then
  1933. Scene.Instance.load_scene_timeout_max = true
  1934. return true
  1935. end
  1936. --角色第一次进场景全加载
  1937. if Scene.Instance.is_first_enter_game or Scene.Instance.is_first_enter_scene then
  1938. -- return true
  1939. end
  1940. if not self.support_model_combine then
  1941. return false
  1942. end
  1943. if MapView.NoCombineModel[tonumber(self.curResId)] then
  1944. return false
  1945. end
  1946. --关闭全加载
  1947. if true then
  1948. return false
  1949. end
  1950. if not AppConst.UpdateMode then
  1951. return true
  1952. end
  1953. if tonumber(AppConst.EnglineVer) < 89 then
  1954. return false
  1955. end
  1956. if self.model_local_state[res] then
  1957. return true
  1958. elseif self.model_local_state[res] == false then
  1959. return false
  1960. end
  1961. local res_file = "rdata/terrain_prefab_" .. res
  1962. local dir_str = "/client/unitybundle/"
  1963. if SystemRuntimePlatform.IsIphone() then
  1964. dir_str = "/client/iosbundle/"
  1965. elseif SystemRuntimePlatform.IsAndroid() then
  1966. dir_str = "/client/androidbundle/"
  1967. end
  1968. res_file = dir_str .. Util.GetAssetsBundlePath(res_file)
  1969. if Util.FileNeedUpdate(res_file) then
  1970. self.model_local_state[res] = false
  1971. return false
  1972. end
  1973. return true
  1974. end
  1975. --设置屏蔽/非屏蔽特效
  1976. function MapView:SetHideRefreshEffect(state)
  1977. if not self.mapLoaded then
  1978. return
  1979. end
  1980. local scene_effect = Config.ConfigSceneEffect.EffectInfo[tonumber(self.curMapId)]
  1981. if not scene_effect then
  1982. return
  1983. end
  1984. for k,v in pairs(self.effect_list) do
  1985. local config = scene_effect[k] or MapView.FullScreenEffect
  1986. if config then
  1987. v:SetActive(not state)
  1988. end
  1989. end
  1990. end
  1991. function MapView:GetLoadSceneRes( res_id )
  1992. if MapView.LoadBigScene[tonumber(res_id)] then
  1993. self.open_big_scene_mode = true
  1994. return res_id .. "_all"
  1995. else
  1996. return res_id
  1997. end
  1998. end
  1999. -- --创建场景模型
  2000. -- function MapView:LoadSpiltModelList( )
  2001. -- local model_config = Config["model" .. self.curResId]
  2002. -- if model_config then
  2003. -- --场景基础资源包加载超时失败,改成挂在通用根节点
  2004. -- -- local model_root = GameObject.Find("splitmodel")
  2005. -- -- if not model_root then
  2006. -- -- model_root = GameObject.Find("root")
  2007. -- -- end
  2008. -- -- self.model_parent = model_root.transform
  2009. -- -- SetGlobalPosition3D(self.model_parent,0, 0, 0)
  2010. -- -- SetLocalScale(self.model_parent,1,1,1)
  2011. -- -- self.model_parent.localEulerAngles = Vector3(0, 0, 0)
  2012. -- self.load_model_count = 0
  2013. -- SapManager.Instance:WaitLoadTerrainFinish(true)
  2014. -- --排序
  2015. -- local temp_model_config = {}
  2016. -- local main_pos = MainCamera:getInstance():GetCameraPos()
  2017. -- if main_pos then
  2018. -- main_pos.x = main_pos.x/100
  2019. -- main_pos.y = main_pos.y/100
  2020. -- for k,v in pairs(model_config) do
  2021. -- v.key = k
  2022. -- -- table.insert(temp_model_config, v)
  2023. -- temp_model_config[#temp_model_config+1] = v
  2024. -- end
  2025. -- local sort_func = function(a,b)
  2026. -- local di = GameMath.GetDistance(main_pos.x, main_pos.y, a[3], a[5])
  2027. -- local dj = GameMath.GetDistance(main_pos.x, main_pos.y, b[3], b[5])
  2028. -- return di < dj
  2029. -- end
  2030. -- table.sort(temp_model_config, sort_func)
  2031. -- else
  2032. -- temp_model_config = model_config
  2033. -- end
  2034. -- local near_same_res_map = {}
  2035. -- local far_same_res_map = {}
  2036. -- local near_max_index = 15
  2037. -- local near_cur_index = 1
  2038. -- self.enter_scene_want_load_count = 0
  2039. -- for index, data in pairs(temp_model_config) do
  2040. -- if near_cur_index <= near_max_index then
  2041. -- if not near_same_res_map[data[1]] then
  2042. -- near_same_res_map[data[1]] = {}
  2043. -- self.enter_scene_want_load_count = self.enter_scene_want_load_count + 1
  2044. -- near_cur_index = near_cur_index + 1
  2045. -- end
  2046. -- table.insert(near_same_res_map[data[1]], data.key)
  2047. -- else
  2048. -- if not far_same_res_map[data[1]] then
  2049. -- far_same_res_map[data[1]] = {}
  2050. -- self.enter_scene_want_load_count = self.enter_scene_want_load_count + 1
  2051. -- end
  2052. -- table.insert(far_same_res_map[data[1]], data.key)
  2053. -- end
  2054. -- end
  2055. -- --创建近景
  2056. -- for res,list in pairs(near_same_res_map) do
  2057. -- self.combine_mini_model[res] = true
  2058. -- self:OnLoadSplitModel(res,list,model_config)
  2059. -- end
  2060. -- --创建远景
  2061. -- -- for res,list in pairs(far_same_res_map) do
  2062. -- -- self.combine_mini_model[res] = true
  2063. -- -- self:OnLoadSplitModel(res,list,model_config)
  2064. -- -- end
  2065. -- --分帧创建远景
  2066. -- local far_step_res_map = {}
  2067. -- for k,v in pairs(far_same_res_map) do
  2068. -- local vo ={res = k, list = v}
  2069. -- table.insert(far_step_res_map, vo)
  2070. -- end
  2071. -- self.far_model_index = 1
  2072. -- local function on_period( )
  2073. -- local vo = far_step_res_map[self.far_model_index]
  2074. -- if vo then
  2075. -- self.combine_mini_model[vo.res] = true
  2076. -- self:OnLoadSplitModel(vo.res,vo.list,model_config)
  2077. -- self.far_model_index = self.far_model_index + 1
  2078. -- else
  2079. -- self:CancelFarModelTimer()
  2080. -- end
  2081. -- end
  2082. -- self:CancelFarModelTimer()
  2083. -- self.on_far_model_timer = GlobalTimerQuest:AddPeriodQuest(on_period, 0.01)
  2084. -- end
  2085. -- self.regiest_model_finish = true
  2086. -- end
  2087. -- function MapView:CancelFarModelTimer( )
  2088. -- if self.on_far_model_timer then
  2089. -- GlobalTimerQuest:CancelQuest(self.on_far_model_timer)
  2090. -- self.on_far_model_timer = nil
  2091. -- end
  2092. -- end
  2093. -- function MapView:OnLoadSplitModel(res,list,model_config)
  2094. -- local cache_list = self.model_cache_map[res]
  2095. -- local map_res = self.curResId
  2096. -- local load_res = function( objs, cache )
  2097. -- if objs and ( cache or objs[0]) and self.mapLoaded then
  2098. -- if map_res ~= self.curResId then
  2099. -- if not cache and objs[0] then
  2100. -- destroy(objs[0])
  2101. -- end
  2102. -- return
  2103. -- end
  2104. -- local single_parent = self:GetSingleParent(res)
  2105. -- for k,index in pairs(list) do
  2106. -- local last_model = self.model_list[index]
  2107. -- if not last_model then
  2108. -- if cache then
  2109. -- if #cache_list > 1 then
  2110. -- local info = table.remove(cache_list,#cache_list)
  2111. -- if info and not IsNull(info.obj) then
  2112. -- info.obj:SetActive(true)
  2113. -- self:InitObj( info.obj,nil,model_config[index],single_parent,index, res )
  2114. -- end
  2115. -- else
  2116. -- if cache_list[1] and not IsNull(cache_list[1].obj) then
  2117. -- cache_list[1].time = os.time()
  2118. -- cache_list[1].obj:SetActive(true)
  2119. -- self:InitObj( nil, cache_list[1].obj,model_config[index],single_parent,index, res )
  2120. -- cache_list[1].obj:SetActive(false)
  2121. -- end
  2122. -- end
  2123. -- else
  2124. -- self:InitObj( nil,objs[0],model_config[index],single_parent,index, res )
  2125. -- end
  2126. -- end
  2127. -- end
  2128. -- else
  2129. -- print("------load res error--------",res)
  2130. -- end
  2131. -- self.load_model_count = (self.load_model_count or 0) + 1
  2132. -- if self.support_model_combine then
  2133. -- self:CombineModelList(res,list)
  2134. -- end
  2135. -- local next_frame = function()
  2136. -- self:OnSplitModelFinish()
  2137. -- end
  2138. -- if self.combine_model_state then
  2139. -- setTimeout(next_frame,0.01)
  2140. -- else
  2141. -- next_frame()
  2142. -- end
  2143. -- end
  2144. -- if cache_list then
  2145. -- if #cache_list > 0 then
  2146. -- load_res(true,true)
  2147. -- return
  2148. -- end
  2149. -- end
  2150. -- local ab_name = "terrain_prefab_" .. res
  2151. -- lua_resM:loadPrefab(self.load_prefab_temp_target,ab_name,res, load_res, false, ASSETS_LEVEL.NORMAL)
  2152. -- end
  2153. -- function MapView:OnSplitModelFinish( )
  2154. -- if self.load_model_count and self.enter_scene_want_load_count and self.load_model_count >= self.enter_scene_want_load_count then
  2155. -- --静态合批
  2156. -- if self.support_model_combine and not self.combine_model_state then
  2157. -- self:CombineModel()
  2158. -- end
  2159. -- self.combine_model_state = true
  2160. -- SapManager.Instance:WaitLoadTerrainFinish(false)
  2161. -- end
  2162. -- end
  2163. function MapView:ResetSceneActionObjHeight( )
  2164. -- local cfg = Config.ConfigSceneElevatorModel[self.curMapId]
  2165. -- if not cfg then
  2166. -- return
  2167. -- end
  2168. -- for index, vo in pairs(cfg) do
  2169. -- local obj = self:GetSceneActionObj(vo.obj_name)
  2170. -- if not IsNull(obj) then
  2171. -- SetGlobalPositionY(obj.transform, vo.obj_start_y)
  2172. -- if obj.activeSelf == false then
  2173. -- obj:SetActive(true)
  2174. -- end
  2175. -- end
  2176. -- end
  2177. end
  2178. function MapView:GetSceneActionObj( obj_name )
  2179. if not obj_name or obj_name == "" then
  2180. return
  2181. end
  2182. self.action_obj_list = self.action_obj_list or {}
  2183. if self.action_obj_list[obj_name] then
  2184. return self.action_obj_list[obj_name]
  2185. end
  2186. local obj = GameObject.Find(obj_name)
  2187. if not IsNull(obj) then
  2188. self.action_obj_list[obj_name] = obj
  2189. return obj
  2190. end
  2191. end
  2192. function MapView:ObjectPlayAction( obj_name, action_name )
  2193. local obj = self:GetSceneActionObj(obj_name)
  2194. if not IsNull(obj) then
  2195. local animator = obj:GetComponent(typeof(UnityEngine.Animator))
  2196. if animator then
  2197. animator:CrossFade(action_name,0)
  2198. end
  2199. end
  2200. end