require("game.scene.sceneobj.SceneEffect") require("game.scene.sceneobj.AlphaObj") MapView = MapView or BaseClass(BaseController) local MapView = MapView local lua_resM = lua_resM local string_find = string.find local Material_New = Material.New local math_floor = math.floor local GameMath_GetDistance = GameMath.GetDistance MapView.DefaultMapRes = 1001 MapView.NoAreaLoadEffect = { -- ["scene_tiaoyue"] = true, ["effect_gate_001"] = true, } MapView.NoLoadModel = { -- ["scene_tiaoyue"] = true, ["XSCCZ_TT03_05"] = true, } MapView.CustomEffect = { [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}, [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}, [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}, } MapView.CustomEffectBox = { -- ["scene_fountain01"] = 1000, -- ["xsc_shui_worldwaterdark"] = 900000, -- ["scene1004_worldwater"] = 900000, -- ["scene1004_poolwater"] = 900000, -- ["scene1002worldwater"] = 900000, -- ["shamo_shui_1_2"] = 900000, -- ["shamo_shui_1_1"] = 900000, } MapView.LoadBigScene = { --[1000] = true, --[1002] = true, --[1003] = true, --[1004] = true, --[1005] = true, --[1006] = true, --[5801] = true, } MapView.FullScreenEffect = { -- 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, } MapView.WaveList = { -- ["screenwave"] = false, -- ["screenwave3"] = false, -- ["haidi_g11_2"] = false, } MapView.MustAreaLoadEffect = { -- ["scene_zudangmen"] = true } --不使用模型合批的地图 MapView.NoCombineModel = { -- [5801] = true, } MapView.HideEffectScene = { -- [6610] = { -- ["shamo_shui_1_1"] = true, -- ["shamo_shui_1_2"] = true, -- ["scene_firebig01"] = true, -- ["scene_firebig01 (1)"] = true, -- ["scene_waterfall01"] = true, -- ["scene_sunshine04 (4)"] = true, -- }, -- [6611] = { -- ["shamo_shui_1_1"] = true, -- ["shamo_shui_1_2"] = true, -- ["scene_firebig01"] = true, -- ["scene_firebig01 (1)"] = true, -- ["scene_waterfall01"] = true, -- ["scene_sunshine04 (4)"] = true, -- }, -- [6612] = { -- ["shamo_shui_1_1"] = true, -- ["shamo_shui_1_2"] = true, -- ["scene_firebig01"] = true, -- ["scene_firebig01 (1)"] = true, -- ["scene_waterfall01"] = true, -- ["scene_sunshine04 (4)"] = true, -- }, -- [6613] = { -- ["shamo_shui_1_1"] = true, -- ["shamo_shui_1_2"] = true, -- ["scene_firebig01"] = true, -- ["scene_firebig01 (1)"] = true, -- ["scene_waterfall01"] = true, -- ["scene_sunshine04 (4)"] = true, -- }, } --全加载地图 MapView.AllLoadScene = { [1001] = true, } --不使用动态剔除的场景 MapView.NoDisibleLoadScene = { -- [1001] = true, } MapView.EnterSceneLoad = { -- [1001] = true, -- [1002] = true, -- [1006] = true, -- [1008] = true, -- [1009] = true, } MapView.FindWayVector2One = Vector2(0,0) MapView.FindWayVector2Second = Vector2(0,0) function MapView:__init() MapView.Instance = self self.mapLoaded = false self.curMapData = nil self.async_load_map_obj = nil self.effect_list = {} self.move_obj_list = {} self.specialModel_list = {} self.load_prefab_temp_target = {} self.preload_prefab_temp_target = {} self.preload_scene_id = nil self.model_list = {} self.area_load_mode = true self.load_model_count = nil self.enter_scene_want_load_count = 0 self.alpha_model_list = {} self.material_obj_list = {} self.material_ab_list = {} self.last_cache_model_check_time = 0 self.model_cache_map = {} self.model_id_res_map = {} self.open_model_cache_state = true self.open_abres_immediately_delete_mode = false self.combine_mini_model = {} self.model_root_map = {} self.model_local_state = {} self.combine_model_state = false self.min_combine_count = 5 self.timeout_enter_scene = false self.regiest_model_new_mode = true self.open_big_scene_mode = false self.have_combine_model = {} self.open_dynamic_visible_model = false self.cache_effect_obj = {} self.cache_effect_mode = false self.zone_height = {} self.zone_block = {} self.zone_type = {} self.area_type_cache = {} self.has_water_effect = {} if SystemRuntimePlatform.IsIphone() then self.open_model_cache_state = false self.open_abres_immediately_delete_mode = true end if tonumber(AppConst.EnglineVer) > 70 then mapMgr.logicWidth = SceneObj.LogicRealRatio.x mapMgr.logicHeight = SceneObj.LogicRealRatio.y end local account_change = function() self:ForceChangeMap(true) end local role_change = function() self:ForceChangeMap(false) end GlobalEventSystem:Bind(EventName.CHANGE_ACCOUNT, account_change) GlobalEventSystem:Bind(EventName.CHANGE_ROLE, role_change) local timeout_enter_scene = function() self.timeout_enter_scene = true SapManager.Instance:WaitLoadTerrainFinish(false) end GlobalEventSystem:Bind(EventName.TIMEOUT_ENTER_SCENE,timeout_enter_scene) local func = function() local data = {} local effect_count = 0 for k,v in pairs(self.effect_list) do effect_count = effect_count + 1 end local model_count = 0 for k,v in pairs(self.model_list) do model_count = model_count + 1 end local model_cache_map_count = 0 for k,v in pairs(self.model_cache_map) do model_cache_map_count = model_cache_map_count + 1 end data.effect_count = effect_count data.model_count = model_count data.model_cache_map_count = model_cache_map_count GlobalEventSystem:Fire(EventName.SENT_MODULE_DEBUG_DATA,"mapview", data) end GlobalEventSystem:Bind(EventName.CHECK_MODULE_DEBUG_DATA,func) local callfunc = function(module_name,func) self.set_root_visible_data_tab = self.set_root_visible_data_tab or { ["mapview@showbuhongpei"] = {node_name = "buhongpei", bool = true}, ["mapview@hidebuhongpei"] = {node_name = "buhongpei", bool = false}, ["mapview@showmodelcom"] = {node_name = "model_com_root", bool = true}, ["mapview@hidemodelcom"] = {node_name = "model_com_root", bool = false}, ["mapview@showsplitmodel"] = {node_name = "splitmodel", bool = true}, ["mapview@hidesplitmodel"] = {node_name = "splitmodel", bool = false}, ["mapview@showdongzuo"] = {node_name = "dongzuo", bool = true}, ["mapview@hidedongzuo"] = {node_name = "dongzuo", bool = false}, ["mapview@showway"] = {node_name = "xunlu", bool = true}, ["mapview@hideway"] = {node_name = "xunlu", bool = false}, ["mapview@showterrain"] = {node_name = "special", bool = true}, ["mapview@hideterrain"] = {node_name = "special", bool = false}, ["mapview@showshui"] = {node_name = "shui", bool = true}, ["mapview@hideshui"] = {node_name = "shui", bool = false}, ["mapview@showfog"] = {node_name = "fog", bool = true}, ["mapview@hidefog"] = {node_name = "fog", bool = false}, ["mapview@showaction"] = {node_name = "action", bool = true}, ["mapview@hideaction"] = {node_name = "action", bool = false}, ["mapview@showwater"] = {node_name = "water", bool = true}, ["mapview@hidewater"] = {node_name = "water", bool = false}, ["mapview@showspecial"] = {node_name = "special", bool = true}, ["mapview@hidespecial"] = {node_name = "special", bool = false}, } if module_name and func and self.set_root_visible_data_tab[module_name.."@"..func] then --简单的节点修改就直接在上面添加走这里,免得看起来太累赘 local temp = self.set_root_visible_data_tab[module_name.."@"..func] self.set_root_show_call(GameObject.Find(temp.node_name) or self[temp.node_name],temp.bool) elseif module_name == "mapview" and func == "clear" then self:ClearData() elseif module_name == "mapview" and func == "combine" then self:CombineModel() elseif module_name == "mapview" and func == "hidescene" then self.model_root = GameObject.Find("model") self.set_root_show_call(self.model_root,false) if self.model_parent and self.model_parent ~= GameObject.Find("root").transform then self.set_root_show_call(self.model_parent,false) end elseif module_name == "mapview" and func == "showscene" then self.set_root_show_call(self.model_root,true) if self.model_parent and self.model_parent ~= GameObject.Find("root").transform then self.set_root_show_call(self.model_parent,true) end elseif module_name == "mapview" and func == "hidesky" then self.sky_root = GameObject.Find("Sky") self.sky_root_2 = GameObject.Find("sky") self.set_root_show_call(self.sky_root,false) self.set_root_show_call(self.sky_root_2,false) elseif module_name == "mapview" and func == "showsky" then self.set_root_show_call(self.sky_root,true) self.set_root_show_call(self.sky_root_2,true) elseif module_name == "mapview" and func == "hiderootall" then self:SetAllRootShow(false) elseif module_name == "mapview" and func == "showrootall" then self:SetAllRootShow(true) end end self.rootshowcall = callfunc self.set_root_show_call = function( root,bool ) if not IsNull(root) and not IsNull(root.gameObject) then root.gameObject:SetActive(bool) end end GlobalEventSystem:Bind(EventName.DO_MODULE_DEBUG_FUNC,callfunc) end function MapView:SetAllRootShow( bool ) if not self.rootshowcall or not self.set_root_show_call then return end if bool then if SceneManager.Instance:GetSceneId() ~= 1001 then self.rootshowcall("mapview","showscene") end self.rootshowcall("mapview","showsky") else if SceneManager.Instance:GetSceneId() ~= 1001 then self.rootshowcall("mapview","hidescene") end self.rootshowcall("mapview","hidesky") end ------------------------- if self.set_root_visible_data_tab then for k,v in pairs(self.set_root_visible_data_tab) do if string.find(k, bool and "show" or "hide") then local obj = self[v.node_name] if IsNull(obj) then obj = GameObject.Find(v.node_name) if not IsNull(obj) then self[v.node_name] = obj end end self.set_root_show_call(obj , bool) end end end end function MapView:CheckCombineModel() self.support_model_combine = false if tonumber(AppConst.EnglineVer) >= 74 and self:CheckIOSCombine() then if self.curResId then local no_combine = MapView.NoCombineModel[tonumber(self.curResId)] if not no_combine then self.support_model_combine = true end else self.support_model_combine = true end end if not self.regiest_model_new_mode then self.support_model_combine = false end end function MapView:CheckIOSCombine() if SystemRuntimePlatform.IsIphone() then if RoleManager.Instance.mainRoleInfo.level == 1 and SystemMemoryLevel.Cur == SystemMemoryLevel.Hight then return true else return false end else return true end end function MapView:getInstance() if MapView.Instance == nil then MapView.New() end return MapView.Instance end function MapView:GetResID( is_minimap ) if is_minimap then return Config.ConfigMiniMap[tonumber(self.curMapId)] or self.curResId end return self.curResId end function MapView:GetResIDByScene( scene, func ) local scene_id = tonumber(scene) local res_id = Config.ConfigMiniMap[scene_id] if res_id then func(res_id) return end local load_call_back = function(objs) if objs and objs[0] then local txt = objs[0] mapMgr:LoadOtherMap(scene_id,txt) local mapdata = mapMgr:MapByScene(scene_id) func(mapdata.resId) if scene_id ~= self.curMapId then mapMgr:ClearMap(scene_id) end end end lua_resM:loadTextAsset(self.load_prefab_temp_target,"mapdata" .. scene_id,tonumber(scene_id),load_call_back,ASSETS_LEVEL.HIGHT) end function MapView:GetMapSize() if self.curMapData then return co.TableXY(self.curMapData.mapWidth,self.curMapData.mapHeight) else return co.TableXY(0,0) end end function MapView:Update( cam_pos ) --print("-------Update-------") for index,obj in pairs(self.move_obj_list) do obj:Update() end self:CheckOuttimeCacheMode() end function MapView:Load( mapId, load_map_func, load_effect_finish ) print("tanar: [MapView 420]=> Load: ",mapId) self.wait_clear_map = false local call_out_succeed = false local load_terrain_succeed = function() if call_out_succeed then return end self:DeletePreLoadMap() self.mapLoaded = true call_out_succeed = true load_map_func() self:ProcessSpecialModel() self:ProcessSkyModel() if not self.curResId then return end self.area_load_mode = true -- if MapView.NoDisibleLoadScene[tonumber(self.curResId)] then -- self.open_dynamic_visible_model = false -- else -- self.open_dynamic_visible_model = true -- end -- if SceneManager.Instance:IsStarFightScene() then -- self.open_dynamic_visible_model = false -- end if not SystemRuntimePlatform.IsIphone() then --使用全加载模式 self.open_dynamic_visible_model = false end ShaderTools.ClearMaterialData() self:CheckCombineMiniModel() self:RegiestEffectList() --模型创建方式 -- if not MapView.EnterSceneLoad[tonumber(self.curResId)] then -- if self.regiest_model_new_mode then -- self:RegiestModelListNew() -- else -- self:RegiestModelList() -- end -- end self:RegiestMoveObjList() self:RegiestAlphaModelList() self:RegisterElevatorModelList() load_effect_finish(1) --[[ if not self.load_model_count or self.enter_scene_want_load_count == 0 then load_effect_finish(1) else self.load_effect_finish_func = load_effect_finish local timeout_finfish = function() if self.load_effect_finish_func then self.load_effect_finish_func(1) self.load_effect_finish_func = nil self.timeout_enter_scene = true SapManager.Instance:WaitLoadTerrainFinish(false) end end self.check_load_model_event = setTimeout(timeout_finfish,25) end ]] -- if not G_DEBUG_MODE then -- self:LoadSpiltModelList() --全加载 self:RegiestModelListNew() --SAP -- end SapManager:getInstance():ForceCheckFarModelLoad() --新手场景特殊处理 if self.curResId and self.curResId == 1001 then Shader.SetGlobalFloat("_GlobalSceneAlpha", 1.0) end end local load_finish = function( same_scene ) -- if G_DEBUG_MODE then -- load_terrain_succeed() -- return -- end -- if Config.ConfigSceneWaveModel[self.curResId] then -- self:LoadWaterMaterial() -- end local load_scene_call_back load_scene_call_back = function(objs) if mapId ~= self.curMapId then return end if objs then self.async_load_map_obj = UnitySceneManager.LoadSceneAsync(self:GetLoadSceneRes(tostring(self.curResId))) self.async_load_map_obj.allowSceneActivation = true local load_into = function() if self.check_load_event then GlobalTimerQuest:CancelQuest(self.check_load_event) self.check_load_event = nil end if self.async_load_map_obj then self.async_load_map_obj = nil end load_terrain_succeed() end local try_load_time = 0 local check_load = function() if self.async_load_map_obj then local progress = self.async_load_map_obj.progress --尝试加载资源去触发场景加载回调,别问 if progress > 0.88 and Time.time - try_load_time > 1 then try_load_time = Time.time GlobalEventSystem:Fire(EventName.OPEN_WORLD_LEVEL_VIEW) GlobalEventSystem:Fire(EventName.CLOSE_WORLD_LEVEL_VIEW) end local max_progress = SystemRuntimePlatform.IsWindowsEditor() and 0.89 or 1 if progress >= max_progress then load_into() elseif self.open_big_scene_mode then load_effect_finish(progress) end end end if self.check_load_event then GlobalTimerQuest:CancelQuest(self.check_load_event) end self.check_load_event = GlobalTimerQuest:AddPeriodQuest(check_load, 0.05, -1) local time_out = function() self.init_terrain_timeout_handle = nil if not call_out_succeed then self.load_terrain_timeout = true end print("tanar: MapView [525] =========== ") load_into() end self.init_terrain_timeout_handle = setTimeout(time_out,15) else local load_again = function() lua_resM:loadPrefabs(self.load_prefab_temp_target,"terrain_scene_" .. self:GetLoadSceneRes(self.curResId),{}, load_scene_call_back, false, ASSETS_LEVEL.HIGHT) end setTimeout(load_again,0.3) end end if not same_scene then lua_resM:loadPrefabs(self.load_prefab_temp_target,"terrain_scene_" .. self:GetLoadSceneRes(self.curResId),{}, load_scene_call_back, false, ASSETS_LEVEL.HIGHT) else setTimeout(load_terrain_succeed,0.1) end local time_out = function() self.load_terrain_timeout_handle = nil if not call_out_succeed then self.load_terrain_timeout = true end load_terrain_succeed() end self.load_terrain_timeout_handle = setTimeout(time_out,25) end self:LoadMapData(mapId, load_finish) end function MapView:LoadMapData( mapId, load_finish) self.curMapData = nil local load_call_back load_call_back = function(objs) if objs and objs[0] then local txt = objs[0] mapMgr:LoadMap(mapId,txt) local same_scene = false local newCurMapData = mapMgr:CurMap() if self.curResId == newCurMapData.resId then same_scene = true end if self.curResId then self:ClearData(same_scene) end self.curResId = newCurMapData.resId self.curMapData = newCurMapData self.curMapId = mapId self:CheckCombineModel() if self.scene_effect_container == nil then self.scene_effect_container = UiFactory.createChild(panelMgr:GetParent("SceneContainer"), UIType.EmptyObject, "effect_container") end if load_finish then load_finish(same_scene) load_finish = nil end else local loadagain = function() lua_resM:loadTextAsset(self.load_prefab_temp_target,"mapdata" .. mapId,tonumber(mapId),load_call_back,ASSETS_LEVEL.HIGHT) end setTimeout(loadagain,1) end end lua_resM:loadTextAsset(self.load_prefab_temp_target,"mapdata" .. mapId,tonumber(mapId),load_call_back,ASSETS_LEVEL.HIGHT) local check_load_finish = function() if load_finish then GameError.Instance:SendErrorToPHP("load map data error when want to change scene " .. mapId) end end self.load_mapdata_handle = setTimeout(check_load_finish,15) end --- area_type:AreaDataIndex function MapView:SetDynamicArea(area_id,area_type) if self.curMapData then --动态区域改变清理缓存 self.zone_block = {} self.zone_type = {} self.curMapData:SetDynamicArea(area_id,area_type) end end function MapView:GetSceneCenterPos() if not self.curMapData then Debugger.LogWarning("GetSceneCenterPos when map not load") return Vector3(0,0,0) end return Vector3(self.curMapData.mapWidth/MainCamera.PixelsToUnits/2, self.curMapData.mapHeight/MainCamera.PixelsToUnits/2, 0) end function MapView:DetectFirstUnblockPoint(pos,dir,max_dist) if not self.curMapData then print(debug.traceback()) Debugger.LogWarning("DetectFirstUnblockPoint when map not load") return nil end dir.y = -dir.y local p = self.curMapData:DetectFirstUnblockPoint(pos,dir,max_dist) return p end function MapView:FindWay(pos1,pos2,range) if not self.curMapData then print(debug.traceback()) Debugger.LogWarning("FindWay when map not load") return nil end MapView.FindWayVector2One.x = pos1.x MapView.FindWayVector2One.y = pos1.y MapView.FindWayVector2Second.x = pos2.x MapView.FindWayVector2Second.y = pos2.y local objs = self.curMapData:FindWay(MapView.FindWayVector2One,MapView.FindWayVector2Second,range) if objs then local ret = {} for i=1,objs.Length do local ret_obj = co.TableXY(objs[objs.Length-i].x,objs[objs.Length-i].y) table.insert(ret,ret_obj) end return ret end return objs end function MapView:IsStraightLine(pos1,pos2) if not self.curMapData then print(debug.traceback()) -- Debugger.LogWarning("IsStraightLine when map not load") return false end return self.curMapData:IsStraightLine(pos1,pos2) end function MapView:DetectLastUnblockPoint(pos,dir,dist,jump_state) if not self.curMapData then print(debug.traceback()) -- Debugger.LogWarning("DetectLastUnblockPoint when map not load") return pos end --dir.y = -dir.y jump_state = false local point = nil point = self.curMapData:DetectLastUnblockPoint(pos,dir,dist,jump_state) return point end function MapView:GetZoneHeight(x, y) if not self.curMapData then return -1 end x = math_floor(x) y = math_floor(y) local index = x .. "-" .. y local cache = self.zone_height[index] if cache then return cache end local height = self.curMapData:GetZoneHeight(x+1,y+1)/100 self.zone_height[index] = height return height end function MapView:IsBlockXY(x, y) if not self.curMapData then return nil end x = math_floor(x) y = math_floor(y) local index = x .. "-" .. y local cache = self.zone_block[index] if cache ~= nil then return cache end local block = self.curMapData:IsBlock(x,y,false) self.zone_block[index] = block return block end -- AreaDataIndex:area_type function MapView:IsAreaType(x, y, area_type) if not self.curMapData then return false end -- if area_type == AreaDataIndex.JumpType then -- return false -- end x = math_floor(x) y = math_floor(y) local index = x .. "-" .. y .. "-" .. area_type local cache = self.zone_type[index] if cache ~= nil then return cache end local result = false local cur_type = self.curMapData:GetAreaType(x,y) if bit.band(cur_type,area_type) ~= 0 then result = true end self.zone_type[index] = result return result end function MapView:GetAreaType(x, y) if not self.curMapData then return end x = math_floor(x) y = math_floor(y) local index = x .. "-" .. y local _type = self.area_type_cache[index] if _type == nil then _type = self.curMapData:GetAreaType(x,y) self.area_type_cache[index] = _type end return _type end function MapView:PreLoadMapRes( scene_id, callback ) if not scene_id then return end local func = function(res_id) if tonumber(res_id) == tonumber(self.curResId) then --前后场景地图资源一样不需走预加载 if callback then callback() end return end self.preload_scene_id = res_id lua_resM:loadPrefabs(self.preload_prefab_temp_target,"terrain_scene_" .. self:GetLoadSceneRes(res_id),{}, callback, false, ASSETS_LEVEL.HIGHT) end self:GetResIDByScene( scene_id, func ) end function MapView:DeletePreLoadMap() if self.preload_scene_id then lua_resM:clearReference(self.preload_prefab_temp_target) self.preload_scene_id = nil end end function MapView:ClearData(same_scene) self.action_obj_list = {} -- self:CancelFarModelTimer() self:UnRegiestEffectList() self:UnRegiestSpecialModelList() self:UnRegiestModelList() self:UnRegiestMoveObjList() self:UnRegiestAlphaModelList() self:UnRegiestElevatorModelList() self.mapLoaded = false for k,effect in pairs(self.effect_list) do effect:DeleteMe() end for k,v in pairs(self.specialModel_list) do v:DeleteMe() end for k,obj in pairs(self.move_obj_list) do obj:DeleteMe() end for k,v in pairs(MapView.WaveList) do MapView.WaveList[k] = false end self.effect_last_show_state = nil MainCamera.Instance:DestoryScreenEffectCamere() if not same_scene then lua_resM:clearReference(self.load_prefab_temp_target) self.material_ab_list = {} for k,cache_list in ipairs(self.model_cache_map) do for index,info in ipairs(cache_list) do destroy(info.obj) end end self.model_cache_map = {} for index,obj in ipairs(self.material_obj_list) do destroy(obj) end self.material_obj_list = {} for index,abname in ipairs(self.material_ab_list) do resMgr:UnloadAssetBundle(abname,true,1) end for index,obj in pairs(self.model_list) do destroy(obj) end for index,obj in pairs(self.model_root_map) do destroy(obj) end self.model_list = {} self.model_root_map = {} self.combine_mini_model = {} self.combine_model_state = false self.open_big_scene_mode = false self.model_parent = nil self.have_combine_model = {} if self.model_com_root then destroy(self.model_com_root) self.model_com_root = nil end local node = GameObject.Find("dongzuo") if node then node:SetActive(false) end end if self.curMapId then mapMgr:ClearMap(self.curMapId) end if self.load_mapdata_handle then GlobalTimerQuest:CancelQuest(self.load_mapdata_handle) self.load_mapdata_handle = nil end if self.check_load_model_event then GlobalTimerQuest:CancelQuest(self.check_load_model_event) self.check_load_model_event = nil end if self.bind_mainrole_move_event then GlobalTimerQuest:CancelQuest(self.bind_mainrole_move_event) self.bind_mainrole_move_event = nil end self.zone_block = {} self.zone_height = {} self.zone_type = {} self.area_type_cache = {} self.effect_list = {} self.specialModel_list = {} self.move_obj_list = {} self.model_id_res_map = {} self.has_water_effect = {} self.load_model_count = nil self.enter_scene_want_load_count = 0 self.timeout_enter_scene = false self.load_terrain_timeout = false if self.load_terrain_timeout_handle then GlobalTimerQuest:CancelQuest(self.load_terrain_timeout_handle) self.load_terrain_timeout_handle = nil end if self.init_terrain_timeout_handle then GlobalTimerQuest:CancelQuest(self.init_terrain_timeout_handle) self.init_terrain_timeout_handle = nil end self.cache_effect_obj = {} if self.scene_effect_container then destroy(self.scene_effect_container) self.scene_effect_container = nil end if self.load_terrain_force_check_handle then TimerQuest.CancelQuest(GlobalTimerQuest, self.load_terrain_force_check_handle) self.load_terrain_force_check_handle = nil end self.regiest_model_finish = false end --全屏特效显示隐藏 function MapView:UpdateFullScreenEffect( posx, posy ) if IsTableEmpty(self.effect_list) then return end local cur_map_id = tonumber(self.curResId) --目前只有1001需要 if cur_map_id and cur_map_id == 1001 then local hide_max_x, hide_max_y = 0, 29170 --超过这个边界需要隐藏 local cur_show_state = true 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 cur_show_state = false end if self.effect_last_show_state ~= nil and self.effect_last_show_state == cur_show_state then return end self.effect_last_show_state = cur_show_state for k,v in pairs(self.effect_list) do if v.fullScreen or v.customEffect then v:SetActive(cur_show_state) end end end end function MapView:RegiestEffectList() local scene_effect = Config.ConfigSceneEffect.EffectInfo[tonumber(self.curMapId)] local area_load = true if scene_effect then -- if SystemRuntimePlatform.IsIphone() then -- area_load = true -- end for effect_id,effect in pairs(scene_effect) do if area_load and not MapView.NoAreaLoadEffect[effect.name] then if not effect.disabled then if effect.fullScreen then self.effect_list[effect_id] = SceneEffect.New(effect,MainCamera:getInstance().camera_gameObject,tonumber(self.curMapId)) self:RegiestMoveEvent() else effect.id = effect_id local obj = { id = effect_id, type = SapManager.ObjType.Effect, pos = co.TableXYZ(effect.x,effect.z,effect.y), 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), size = co.TableXY(effect.bound.size_x * effect.effectScale_x,effect.bound.size_z * effect.effectScale_z,effect.bound.size_y * effect.effectScale_y), data = {id = effect_id,obj = effect}, } local custom_size = MapView.CustomEffectBox[effect.name] if custom_size then obj.size = co.TableXY(custom_size,custom_size,custom_size) end if self.area_load_mode then SapManager:getInstance():RegisterObj(obj) else self:CreateEffect(obj.data) end end end end end end local loadback = function(transform) local hide_effect = MapView.HideEffectScene[self.curMapId] if hide_effect then for effect_name,state in pairs(hide_effect) do local effect = transform:Find(effect_name) if effect then effect.gameObject:SetActive(false) end end end if not self.cache_effect_mode then SapManager.Instance:WaitLoadParticleFinish(false) return end if MapView.NoDisibleLoadScene[tonumber(self.curResId)] then SapManager.Instance:WaitLoadParticleFinish(false) return end if scene_effect and not IsNull(transform) then for effect_id,effect in pairs(scene_effect) do if not effect.obj_name then --旧版配置不支持 SapManager.Instance:WaitLoadParticleFinish(false) return end effect.id = effect_id local obj = { id = effect_id, type = SapManager.ObjType.CacheEffect, pos = co.TableXYZ(effect.x,effect.z,effect.y), 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), size = co.TableXY(effect.bound.size_x * effect.effectScale_x,effect.bound.size_z * effect.effectScale_z,effect.bound.size_y * effect.effectScale_y), data = {id = effect_id,obj = effect}, } local custom_size = MapView.CustomEffectBox[effect.name] if custom_size then obj.size = co.TableXY(custom_size,custom_size,custom_size) end SapManager:getInstance():RegisterObj(obj) end local length = transform.childCount if length > 0 then for i = 0,length -1 do local trans = transform:GetChild(i) if trans and trans.gameObject then trans.gameObject:SetActive(false) self.cache_effect_obj[trans.name] = trans.gameObject end end end end local next_frame = function() SapManager.Instance:WaitLoadParticleFinish(false) end setTimeout(next_frame,0.01) end if MapView.CustomEffect[tonumber(self.curResId)] then local effect_data = MapView.CustomEffect[tonumber(self.curResId)] local data = { id = self.curMapId, obj = effect_data, } if self.cache_effect_mode then SapManager.Instance:WaitLoadParticleFinish(true) end self.effect_list[data.id] = SceneEffect.New(data.obj,self.scene_effect_container,tonumber(self.curMapId),loadback) self.effect_last_show_state = nil end end function MapView:CreateCacheEffect( data ) if data and data.obj then local name = data.obj.obj_name local game_object = self.cache_effect_obj[name] if game_object then game_object:SetActive(true) end end end function MapView:DeleteCacheEffect( name ) if name then local game_object = self.cache_effect_obj[name] if game_object then game_object:SetActive(false) end end end function MapView:UnRegiestEffectList() if SystemMemoryLevel.Cur == SystemMemoryLevel.Low then -- return end if self.mapLoaded and self.area_load_mode then local scene_effect = Config.ConfigSceneEffect.EffectInfo[tonumber(self.curMapId)] if scene_effect then for effect_id,effect in pairs(scene_effect) do SapManager:getInstance():UnRegisterObj(SapManager.ObjType.Effect,effect_id) end end end end function MapView:CreateEffect( data ) if not self.mapLoaded then LogError("want to create effect but map not load finfish, id = " .. data.id ) return end if self.scene_effect_container then self.effect_list[data.id] = SceneEffect.New(data.obj,self.scene_effect_container,tonumber(self.curMapId)) end end function MapView:RefreshEffect() if not self.mapLoaded then --特效设置为true就不走画质和帧率的再次刷新 return end local scene_effect = Config.ConfigSceneEffect.EffectInfo[tonumber(self.curMapId)] if not scene_effect then return end local settingLv = lua_settingM:GetEffectLevel() for k,v in pairs(self.effect_list) do local config = scene_effect[k] or MapView.FullScreenEffect if config then if config.level <= settingLv then v:SetActive(true) else v:SetActive(false) end end end end function MapView:DeleteEffect( obj_id ) local effect = self.effect_list[obj_id] if effect then effect:DeleteMe() self.effect_list[obj_id] = nil end end function MapView:RegiestSpecialModelList() if SystemMemoryLevel.Cur == SystemMemoryLevel.Low then return end local scene_effect = Config.ConfigSceneSpecialModel.SpecialModelInfo[tonumber(self.curMapId)] if scene_effect then for effect_id,effect in pairs(scene_effect) do effect.id = effect_id local obj = { id = effect_id, type = SapManager.ObjType.SpecialModel, pos = co.TableXYZ(effect.x,effect.z,effect.y), 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), size = co.TableXY(effect.bound.size_x * effect.effectScale_x,effect.bound.size_z * effect.effectScale_z,effect.bound.size_y * effect.effectScale_y), data = {id = effect_id,obj = effect}, } local custom_size = MapView.CustomEffectBox[effect.name] if custom_size then obj.size = co.TableXY(custom_size,custom_size,custom_size) end if self.area_load_mode then SapManager:getInstance():RegisterObj(obj) else self:CreateEffect(obj.data) end end end end function MapView:UnRegiestSpecialModelList() if SystemMemoryLevel.Cur == SystemMemoryLevel.Low then return end if self.mapLoaded and self.area_load_mode then local scene_effect = Config.ConfigSceneSpecialModel.SpecialModelInfo[tonumber(self.curMapId)] if scene_effect then for effect_id,effect in pairs(scene_effect) do SapManager:getInstance():UnRegisterObj(SapManager.ObjType.SpecialModel,effect_id) end end end end function MapView:CreateSpecialModel( data ) if not self.mapLoaded then LogError("want to create effect but map not load finfish, id = " .. data.id ) return end if self.scene_effect_container then self.specialModel_list[data.id] = SceneEffect.New(data.obj,self.scene_effect_container,tonumber(self.curMapId)) end end function MapView:DeleteSpecialModel( obj_id ) local effect = self.specialModel_list[obj_id] if effect then effect:DeleteMe() self.specialModel_list[obj_id] = nil end end function MapView:RegiestMoveObjList() local obj_config = Config.ConfigSceneMoveObj[self.curResId] if obj_config then for index, data in ipairs(obj_config) do local pos = data.active_info.pos local osize = data.active_info.size local offset = data.active_info.offset local modelobj = { id = index, type = SapManager.ObjType.MoveObj, pos = co.TableXYZ(pos.x* MainCamera.PixelsToUnits, pos.y* MainCamera.PixelsToUnits, pos.z* MainCamera.PixelsToUnits), bound_offset = co.TableXYZ(offset.x* MainCamera.PixelsToUnits,offset.y* MainCamera.PixelsToUnits), size = co.TableXY(osize.x * MainCamera.PixelsToUnits,osize.y * MainCamera.PixelsToUnits), data = {id = index,obj = data}, } SapManager:getInstance():RegisterObj(modelobj) end end end function MapView:UnRegiestMoveObjList() local obj_config = Config.ConfigSceneMoveObj[self.curResId] if obj_config then for index, data in ipairs(obj_config) do SapManager:getInstance():UnRegisterObj(SapManager.ObjType.MoveObj,index) end end end function MapView:CreateMoveObj( data ) local obj = MoveObj.New( data,self.curMapId,self.scene_effect_container ) obj:CreateModel() if not self.move_obj_list[data.id] then self.move_obj_list[data.id] = obj else LogError("want to create same moveobj id = " .. data.id ) end end function MapView:DeleteMoveObj( index ) local obj = self.move_obj_list[index] if obj then obj:DeleteMe() obj = nil end self.move_obj_list[index] = nil end function MapView:RegiestModelList() local model_root = GameObject.Find("splitmodel") local model_config = Config["model" .. self.curResId] if model_root and model_config then self.model_parent = model_root.transform SetGlobalPosition3D(self.model_parent,0, 0, 0) SetLocalScale(self.model_parent,1,1,1) self.model_parent.localEulerAngles = Vector3(0, 0, 0) self.load_model_count = 0 for index, data in pairs(model_config) do local info = { id = index, obj = data, } if not self.area_load_mode or self.combine_mini_model[data[1]] then if not self.combine_model_state then self:CreateModel(info,self.model_parent) end elseif self:IsLocalFile(data[1]) then self:CreateModel(info,self.model_parent) else self:RegiestModel(info) end end end self.regiest_model_finish = true end function MapView:RegiestModel(info) local data = info.obj local index = info.id local is_far = false local pos_x = (data[3]) * MainCamera.PixelsToUnits local pos_y = (data[5]) * MainCamera.PixelsToUnits local pos_z = (data[4]) * MainCamera.PixelsToUnits local max_size = math.max(math.max(data[15],data[17]),data[16]) * MainCamera.PixelsToUnits * 3 local bound_offset = co.TableXYZ(data[12]* MainCamera.PixelsToUnits,data[14]* MainCamera.PixelsToUnits, data[13]* MainCamera.PixelsToUnits) --远景包围盒适配 local is_check_detail = false local check_type = false local offset = 0 if data[4] < -1 and max_size < 2000 then is_check_detail = true else if Config.ConfigDetailMapViewCheckModel[self.curResId] then if Config.ConfigDetailMapViewCheckModel[self.curResId][data[2]] then is_check_detail = true check_type = Config.ConfigDetailMapViewCheckModel[self.curResId][data[2]].type end end end if is_check_detail then if check_type == 1 then if SystemMemoryLevel.Cur == SystemMemoryLevel.Hight then --高端机采用更精确算法 pos_x = (data[3]) * MainCamera.PixelsToUnits pos_y = (data[4]) * MainCamera.PixelsToUnits pos_z = (data[5]) * MainCamera.PixelsToUnits is_far = true bound_offset = co.TableXYZ(data[12]* MainCamera.PixelsToUnits,data[13]* MainCamera.PixelsToUnits, data[14]* MainCamera.PixelsToUnits) else is_far = false max_size = max_size * 3 bound_offset = co.TableXYZ(data[12]* MainCamera.PixelsToUnits,data[13]* MainCamera.PixelsToUnits, data[14]* MainCamera.PixelsToUnits + 2000) end elseif check_type == 2 then is_far = false max_size = max_size * 3 bound_offset = co.TableXYZ(data[12]* MainCamera.PixelsToUnits,data[13]* MainCamera.PixelsToUnits, data[14]* MainCamera.PixelsToUnits + 2000) end end local modelobj = { id = index, type = SapManager.ObjType.Model, pos = co.TableXYZ(pos_x, pos_y, pos_z), -- rot = Quaternion.Euler(data[6], data[7], data[8]), --这是一个四元数 bound_offset = bound_offset, size = co.TableXYZ(max_size,max_size,max_size), data = {id = index,obj = data}, is_far = is_far } SapManager:getInstance():RegisterObj(modelobj) end function MapView:RegiestModelListNew() local model_root = GameObject.Find("splitmodel") local model_config = Config["model" .. self.curResId] if model_config then --场景基础资源包加载超时失败,改成挂在通用根节点 if not model_root then model_root = GameObject.Find("root") end self.model_parent = model_root.transform SetGlobalPosition3D(self.model_parent,0, 0, 0) SetLocalScale(self.model_parent,1,1,1) self.model_parent.localEulerAngles = Vector3(0, 0, 0) self.load_model_count = 0 SapManager.Instance:WaitLoadTerrainFinish(true) local same_res_map = {} for index, data in pairs(model_config) do if not MapView.NoLoadModel[data[1]] then local res = data[1] if not same_res_map[res] then same_res_map[res] = {} end table.insert(same_res_map[res],index) end end for res,list in pairs(same_res_map) do if not self.area_load_mode or self.combine_mini_model[res] then if not self.combine_model_state or (self.combine_mini_model[res] and self.open_dynamic_visible_model) then self:CreateModelList(res,list,model_config) end elseif self:IsLocalFile(res) then self.combine_mini_model[res] = true self:CreateModelList(res,list,model_config) else for key,index in pairs(list) do local info = { id = index, obj = model_config[index], } self:RegiestModel(info) end end end end self.regiest_model_finish = true end function MapView:CreateModelList(res,list,model_config) self.enter_scene_want_load_count = self.enter_scene_want_load_count + 1 local cache_list = self.model_cache_map[res] local map_res = self.curResId local load_res = function( objs, cache ) if objs and ( cache or objs[0]) and self.mapLoaded then if map_res ~= self.curResId then if not cache and objs[0] then destroy(objs[0]) end return end for k,index in pairs(list) do local last_model = self.model_list[index] if not last_model then if cache then if #cache_list > 1 then local info = table.remove(cache_list,#cache_list) if info and not IsNull(info.obj) then info.obj:SetActive(true) self:InitObj( info.obj,nil,model_config[index],single_parent,index, res ) end else if cache_list[1] and not IsNull(cache_list[1].obj) then cache_list[1].time = os.time() cache_list[1].obj:SetActive(true) self:InitObj( nil, cache_list[1].obj,model_config[index],single_parent,index, res ) cache_list[1].obj:SetActive(false) end end else self:InitObj( nil,objs[0],model_config[index],single_parent,index, res ) end end if self.open_dynamic_visible_model then local info = { id = index, obj = model_config[index], } self:RegiestModel(info) end end else print("------load res error--------",res) end self.load_model_count = (self.load_model_count or 0) + 1 if self.support_model_combine then self:CombineModelList(res,list) end local next_frame = function() self:CheckTerrainLoadFinish() end if self.combine_model_state then setTimeout(next_frame,0.01) else next_frame() end end if cache_list then if #cache_list > 0 then load_res(true,true) return end end local ab_name = "terrain_prefab_" .. res lua_resM:loadPrefabs(self.load_prefab_temp_target,ab_name,res, load_res, true, ASSETS_LEVEL.NORMAL) end function MapView:InitObj( cache_model,obj,data,parent,id,model_name ) local model = cache_model or newObject(obj) model.name = data[2] if parent then model.transform:SetParent(parent) end SetLocalScale(model.transform, data[9], data[10], data[11]) model.transform.localEulerAngles = Vector3(data[6], data[7], data[8]) SetGlobalPosition3D(model.transform,data[3], data[5], data[4]) self:LoadModelLight(model,data) self.model_list[id] = model self.model_id_res_map[id] = model_name self.model_local_state[data[1]] = true end function MapView:CombineModelList(res,list) local single_parent = self:GetSingleParent(res) for k,v in pairs(list) do if not IsNull(self.model_list[v]) then self.model_list[v].transform:SetParent(single_parent) else logWarn("CombineModelList Error:" .. res) end end if self.combine_mini_model[res] and not self.combine_model_state and self.support_model_combine then local root = self.model_root_map[res] if not IsNull(root) then Util.StaticBatchingUtilityCombine(root) --GameError.Instance:SendErrorMsg("---CombineModelList---" .. res) -- GameError.Instance:SendErrorMsg("---CombineModelList---" .. res) end end if self.open_dynamic_visible_model then for k,index in pairs(list) do local model = self.model_list[index] if not IsNull(model) then model:SetActive(false) self.have_combine_model[index] = true else print("model is null:" .. res .. "-" .. index) end end end end function MapView:GetSingleParent(model_name) if not self.support_model_combine then return self.model_parent end local single_parent = self.model_root_map[model_name] or GameObject.Find("splitmodel/" .. model_name .. "_com") if self.load_terrain_timeout and not single_parent then single_parent = GameObject.Find("root/" .. model_name .. "_com") end if not single_parent then if IsNull(self.model_parent) then self.model_parent = GameObject.Find("root").transform end if IsNull(self.model_com_root) then self.model_com_root = UiFactory.createChild(self.model_parent, UIType.EmptyObject, "scene_model_root") end self.model_com_root.layer = LayerMask.NameToLayer("Default") local model_root = UiFactory.createChild(self.model_com_root.transform, UIType.EmptyObject, model_name .. "_com") model_root.layer = LayerMask.NameToLayer("Default") single_parent = model_root.transform SetGlobalPosition3D(single_parent,0, 0, 0) SetLocalScale(single_parent,1,1,1) single_parent.localEulerAngles = Vector3(0, 0, 0) if self.support_model_combine then self.model_root_map[model_name] = model_root end else if IsNull(single_parent) then single_parent = self.model_parent self.timeout_enter_scene = true else single_parent = single_parent.transform end end return single_parent end function MapView:CreateModel(info,parent) parent = parent or self.model_parent if not info or not parent then return end local visible_model = self.model_list[info.id] if not IsNull(visible_model) then visible_model:SetActive(true) return end self.enter_scene_want_load_count = self.enter_scene_want_load_count + 1 local data = info.obj local model_name = data[1] local single_parent = self:GetSingleParent(model_name) local map_res = self.curResId local load_res = function( objs, cache ) if objs and ( cache or objs[0]) and self.mapLoaded then if map_res ~= self.curResId then if cache then destory(objs) end return end if cache then objs:SetActive(true) self:InitObj(objs,nil,data,single_parent,info.id,model_name) else self:InitObj(nil,objs[0],data,single_parent,info.id,model_name) end else print("------load res error--------",model_name) end self.load_model_count = (self.load_model_count or 0) + 1 local next_frame = function() self:CheckTerrainLoadFinish() end if self.combine_model_state then setTimeout(next_frame,0.01) else next_frame() end end local function load_call_back(objs, cache) local load = function() load_res(objs, cache) end --避免模型在缓存中时直接返回打乱模型注册流程,延迟一帧加载 --setTimeout(load,0.01) load() end local ab_name = "terrain_prefab_" .. model_name local cache_list = self.model_cache_map[model_name] if cache_list then if #cache_list > 0 then local length = #cache_list local info = table.remove(cache_list,length) if info and not IsNull(info.obj) then load_call_back(info.obj,true) return end end end lua_resM:loadPrefabs(self.load_prefab_temp_target,ab_name,model_name, load_call_back, true, ASSETS_LEVEL.NORMAL) end function MapView:CheckTerrainLoadFinish() if self.regiest_model_finish and not self.timeout_enter_scene and self.load_effect_finish_func then if self.load_model_count >= self.enter_scene_want_load_count then --静态合批 if not self.regiest_model_new_mode and self.support_model_combine and not self.combine_model_state then self:CombineModel() end self.combine_model_state = true --模型水效果 local wave_info = Config.ConfigSceneWaveModel[self.curResId] if wave_info then for objname,data in pairs(wave_info) do self:LoadScreenWaveObj(objname,data.material,data.effect,data.add) end end --地图加载完成回调 if self.load_effect_finish_func then self.load_effect_finish_func(1) self.load_effect_finish_func = nil end SapManager.Instance:WaitLoadTerrainFinish(false) else local per = self.load_model_count/self.enter_scene_want_load_count if self.load_effect_finish_func then self.load_effect_finish_func(per) end if per >= 0.95 and not self.load_terrain_force_check_handle and self.load_effect_finish_func then local cur_map = self.curResId local force_check = function() self.load_terrain_force_check_handle = nil if self.load_effect_finish_func and cur_map == self.curResId then self.load_effect_finish_func(1) self.load_effect_finish_func = nil SapManager.Instance:WaitLoadTerrainFinish(false) end end self.load_terrain_force_check_handle = setTimeout(force_check,5) end end end end function MapView:CombineModel() for name,root in pairs(self.model_root_map) do if self.combine_mini_model[name] then if not IsNull(root) then Util.StaticBatchingUtilityCombine(root) -- print("------combine_mini_model--------",name) else -- print("------StaticBatchingUtilityCombine empty root --------",name) end else -- print("------not combine_mini_model--------",name) end end end function MapView:LoadModelLight(model,data) if model.gameObject then local mesh = model.gameObject:GetComponentInChildren(typeof(UnityEngine.MeshRenderer)) or model.gameObject:GetComponentInChildren(typeof(UnityEngine.SkinnedMeshRenderer)) if tonumber(data[26]) == 1 then mesh.lightmapIndex = tonumber(data[27]) if not mesh.isPartOfStaticBatch then mesh.lightmapScaleOffset = Vector4(data[28],data[29],data[30],data[31]) end self:ReplaceMaterial(mesh.sharedMaterial) mesh.gameObject.isStatic = true else self:ReplaceMaterial(mesh.sharedMaterial) mesh.gameObject.isStatic = false end -- local wave_info = Config.ConfigSceneWaveModel[self.curResId] -- if wave_info then -- local wave_data = wave_info[data[2]] -- if wave_data then -- self:LoadScreenWaveObj( data[2], wave_data.material,wave_data.effect,wave_data.add ) -- end -- end end end function MapView:ProcessSpecialModel() local specObj = GameObject.Find("special") if specObj == nil then return end local childCount = specObj.transform.childCount for i = 0, childCount - 1 do local child = specObj.transform:GetChild(i) local mesh = child.gameObject:GetComponentInChildren(typeof(UnityEngine.MeshRenderer)) if mesh ~= nil then self:ReplaceMaterial(mesh.sharedMaterial) end end end function MapView:ProcessSkyModel() local skyObj = GameObject.Find("Sky") if skyObj == nil then return end local childCount = skyObj.transform.childCount for i = 0, childCount - 1 do local child = skyObj.transform:GetChild(i) local mesh = child.gameObject:GetComponentInChildren(typeof(UnityEngine.MeshRenderer)) if mesh ~= nil and mesh.sharedMaterial then self:ReplaceMaterial(mesh.sharedMaterial) --mesh.sharedMaterial.renderQueue = 2800 end end end function MapView:ReplaceMaterial(mat) if mat == nil or mat.shader == nil then return end ShaderTools.ChangeMaterial(mat) end function MapView:DeleteModel(id) if not id then LogWarning("MapView DeleteModel ID is nil") return end local model = self.model_list[id] if self.have_combine_model[id] and not IsNull(model) then model:SetActive(false) return end if not IsNull(model) then local model_res = self.model_id_res_map[id] if model_res then if self.open_model_cache_state then if not self.model_cache_map[model_res] then self.model_cache_map[model_res] = {} end local info = {obj = model, time = os.time()} table.insert(self.model_cache_map[model_res],info) model:SetActive(false) else self:DestoryModel(model,model_res) end end end self.model_list[id] = nil end function MapView:DestoryModel(model,name) destroy(model) if self.open_abres_immediately_delete_mode then resMgr:UnloadAssetBundle("terrain_prefab_" .. name,true,1) end end function MapView:UnRegiestModelList() if self.mapLoaded then local model_root = GameObject.Find("splitmodel") local model_config = Config["model" .. self.curResId] if model_root and model_config then for id,obj in pairs(model_config) do if not self.combine_mini_model[obj[1]] or self.open_dynamic_visible_model then SapManager:getInstance():UnRegisterObj(SapManager.ObjType.Model,id) end end end end end function MapView:RegiestMoveEvent( ) local onMainRoleMove = function(posx,posy) if not self.last_elevator_event_time or Time.time - self.last_elevator_event_time > 0.07 then self.last_elevator_event_time = Time.time self:UpdateElevatorModel(posx,posy) end if not self.last_move_event_time or Time.time - self.last_move_event_time > 0.3 then self.last_move_event_time = Time.time self:UpdateAlphaModel(posx,posy) self:UpdateFullScreenEffect(posx,posy) self:TriggerStory(posx,posy) end end if not self.bind_mainrole_move_event then self.bind_mainrole_move_event = GlobalEventSystem:Bind(ObjectEventType.MAINROLE_MOVE_EVENT_IMME,onMainRoleMove) end end function MapView:RegisterElevatorModelList( ) local elevator_cfg = Config.ConfigSceneElevatorModel[self.curResId] if elevator_cfg then self:RegiestMoveEvent() self.elevator_vo_list = elevator_cfg --调试 self:OnDebugElevatorMolde() end end function MapView:OnDebugElevatorMolde( ) -- for k,vo in pairs(self.elevator_vo_list) do -- if vo.is_debug_show then -- self:CreateDebugConfigObj(k, vo) -- end -- end end function MapView:CreateDebugConfigObj( k, vo ) local res = "mrsd_xuanzhong_001" self.debug_obj_list = self.debug_obj_list or {} local function load_call_back( objs, is_gameObject ) if not objs or not objs[0] then return end local gameObject = is_gameObject and objs[0] or newObject(objs[0]) local key = k..vo.obj_name gameObject.name = key self.debug_obj_list[key] = gameObject local scale = vo.range/140 SetLocalScale(gameObject.transform, scale) gameObject.transform:SetParent(panelMgr:GetParent("SceneObjContainer").transform) SetGlobalPosition3D(gameObject.transform,vo.start_pos.x/100,vo.start_pos.y/100,vo.ele_start_pos.y) end lua_resM:loadPrefab(self, res, res, load_call_back, nil, ASSETS_LEVEL.LOW) end function MapView:UnRegiestElevatorModelList() self.elevator_vo_list = {} if self.debug_obj_list then for k,go in pairs(self.debug_obj_list) do destroy(go) go = nil end self.debug_obj_list = false end end function MapView:UpdateElevatorModel( posx, posy ) if not self.elevator_vo_list or #self.elevator_vo_list == 0 then return end local main_role = Scene.Instance.main_role if not main_role then return end if main_role:IsInState(PoseState.ELEVATOR) or main_role:IsGhostMode() then return end local temp_elevator_vo = false local x, y = posx, posy for k,vo in pairs(self.elevator_vo_list) do local range = vo.range * vo.range if GameMath_GetDistance(x, y, vo.start_pos.x, vo.start_pos.y, false) <= range then temp_elevator_vo = vo break end end if temp_elevator_vo then main_role:DoElevator(temp_elevator_vo) return true end end function MapView:RegiestAlphaModelList() local info = Config.ConfigSceneAlphaModel[self.curResId] if info then self.alpha_model_list = {} for index,config in pairs(info) do local data = { task_list = config.task_list, name = config.name, minx = config.minx, miny = config.miny, maxx = config.maxx, maxy = config.maxy, alpha = config.alpha, time = config.time, obj = nil, destory = false, } table.insert(self.alpha_model_list,data) end self:RegiestMoveEvent() if RoleManager and RoleManager.Instance.mainRoleInfo then self:UpdateAlphaModel(RoleManager.Instance.mainRoleInfo.pos_x,RoleManager.Instance.mainRoleInfo.pos_y) end end end function MapView:UnRegiestAlphaModelList() for index,data in ipairs(self.alpha_model_list) do if data.obj then data.obj:DeleteMe() data.destory = true data.obj = nil end end self.alpha_model_list = {} end function MapView:UpdateAlphaModel(posx,posy) if #self.alpha_model_list > 0 then for index,data in pairs(self.alpha_model_list) do local is_task_math = true if data.task_list then is_task_math = TaskModel:getInstance():IsBetweenTaskListState(data.task_list) end if is_task_math then if data.minx < posx and data.maxx > posx and data.miny < posy and data.maxy > posy then if not data.obj then data.obj = AlphaObj.New(data.name,data.alpha,data.time) if data.obj.load_succeed then data.destory = false else data.obj:DeleteMe() data.obj = nil end end else if data.obj and not data.destory then local callback = function() if data.obj then data.obj:DeleteMe() data.obj = nil end end data.obj:HideEffect( callback ) data.destory = true end end end end end end function MapView:TriggerStory(posx, posy) local scene_story_config = Config.Story[self.curMapId] if scene_story_config then local story_id = TaskModel:getInstance():GetTriggerStoryId() local story_cfg = scene_story_config[story_id] if story_cfg and story_cfg.trigger_range then local main_role = Scene.Instance.main_role if not main_role then return end local range = story_cfg.trigger_range * story_cfg.trigger_range if GameMath_GetDistance(posx, posy, story_cfg.trigger_pos.x, story_cfg.trigger_pos.y, false) <= range then main_role:DoStory(story_cfg) end end end end function MapView:LoadScreenWaveObj( objname, material, effect, add_mat ) -- if self.has_water_effect[objname] then -- return -- end -- local obj = GameObject.Find("splitmodel/" .. objname) or GameObject.Find("special/" .. objname) -- if not obj then -- return -- end -- --组队副本不开水纹效果 -- if SceneManager.Instance:IsTeamDungeonScene() then -- return -- end -- self.has_water_effect[objname] = true -- local mesh_renderer = obj:GetComponentInChildren(typeof(UnityEngine.MeshRenderer)) or game_object:GetComponentInChildren(typeof(UnityEngine.SkinnedMeshRenderer)) -- if not add_mat then -- local ori_mat = MapView.WaveList[material] -- if not ori_mat then -- print("material not load succeed:" .. material) -- return -- end -- local mat = Material_New(ori_mat) -- mat:SetFloat("_Noise_Power", effect or Config.ConfigSceneWaveModel.DefaultWave) -- SetMaterialTexture(mat,GetMaterialTexture(mesh_renderer.material)) -- mesh_renderer.material = mat -- mesh_renderer.material.renderQueue = 1999 -- table.insert(self.material_obj_list,mat) -- else -- local mats = mesh_renderer.sharedMaterials -- local lua_mats = {} -- local mats_len = mats.Length -- local wave_index = nil -- for i = 0, mats_len - 1 do -- lua_mats[i + 1] = mats[i] -- if IsNull(mats[i]) or string_find(mats[i].name, material, 1, true) then -- wave_index = i + 1 -- end -- end -- if not wave_index then -- wave_index = mats_len + 1 -- end -- local wave_effect = lua_mats[wave_index] -- if not wave_effect then -- local ori_mat = MapView.WaveList[material] -- if not ori_mat then -- print("material not load succeed:" .. material) -- return -- end -- wave_effect = Material_New(ori_mat) -- wave_effect:SetFloat("_Noise_Power", effect or Config.ConfigSceneWaveModel.DefaultWave) -- lua_mats[wave_index] = wave_effect -- mesh_renderer.sharedMaterials = lua_mats -- mesh_renderer.material.renderQueue = 1999 -- table.insert(self.material_obj_list,wave_effect) -- end -- end end function MapView:CheckOuttimeCacheMode() if os.time() - self.last_cache_model_check_time < 10 or SystemMemoryLevel.Cur == SystemMemoryLevel.Low then return end self.last_cache_model_check_time = os.time() for res,cache_list in pairs(self.model_cache_map) do for i = #cache_list,1,-1 do if os.time() - cache_list[i].time > 60 then local info = table.remove(cache_list,i) self:DestoryModel(info.obj,res) end end end end function MapView:ForceChangeMap( load_empty_map ) local clear_map = function() self:ClearData() self.curMapId = nil self.curResId = nil end if load_empty_map and LoginModel.Instance.reconnect_on_game then local res = "empty" local load_call_back = function() if self.wait_clear_map then UnitySceneManager.LoadSceneAsync(res) clear_map() self.wait_clear_map = false end end self.wait_clear_map = true lua_resM:loadPrefabs(self.load_prefab_temp_target,"terrain_scene_" .. res,{}, load_call_back, true, ASSETS_LEVEL.HIGHT) else clear_map() end end function MapView:LoadWaterMaterial() --加载模型水纹材质 for material,value in pairs(MapView.WaveList) do local ab_name = "terrain_material_" .. material local function callback(objs) if objs and objs[0] then MapView.WaveList[material] = objs[0] end end lua_resM:loadMateaial(self.load_prefab_temp_target,ab_name, material, callback, ASSETS_LEVEL.HIGHT) end end function MapView:CheckCombineMiniModel() if self.combine_model_state or not self.support_model_combine then return end if not self.curResId then return end local model_root = GameObject.Find("splitmodel") local model_config = Config["model" .. self.curResId] if model_root and model_config then local res_count_map = {} for index, data in pairs(model_config) do local resname = data[1] if not res_count_map[resname] then res_count_map[resname] = 0 end res_count_map[resname] = res_count_map[resname] + 1 end self.combine_mini_model = {} for resname,count in pairs(res_count_map) do if count > self.min_combine_count then self.combine_mini_model[resname] = true end end end end function MapView:IsLocalFile( res ) --新手村地图全加载 if MapView.AllLoadScene[self.curResId] then Scene.Instance.load_scene_timeout_max = true return true end do return false end if SystemRuntimePlatform.IsIphone() then return false end if SceneManager.Instance:IsStarFightScene() then Scene.Instance.load_scene_timeout_max = true return true end --角色第一次进场景全加载 if Scene.Instance.is_first_enter_game or Scene.Instance.is_first_enter_scene then -- return true end if not self.support_model_combine then return false end if MapView.NoCombineModel[tonumber(self.curResId)] then return false end --关闭全加载 if true then return false end if not AppConst.UpdateMode then return true end if tonumber(AppConst.EnglineVer) < 89 then return false end if self.model_local_state[res] then return true elseif self.model_local_state[res] == false then return false end local res_file = "rdata/terrain_prefab_" .. res local dir_str = "/client/unitybundle/" if SystemRuntimePlatform.IsIphone() then dir_str = "/client/iosbundle/" elseif SystemRuntimePlatform.IsAndroid() then dir_str = "/client/androidbundle/" end res_file = dir_str .. Util.GetAssetsBundlePath(res_file) if Util.FileNeedUpdate(res_file) then self.model_local_state[res] = false return false end return true end --设置屏蔽/非屏蔽特效 function MapView:SetHideRefreshEffect(state) if not self.mapLoaded then return end local scene_effect = Config.ConfigSceneEffect.EffectInfo[tonumber(self.curMapId)] if not scene_effect then return end for k,v in pairs(self.effect_list) do local config = scene_effect[k] or MapView.FullScreenEffect if config then v:SetActive(not state) end end end function MapView:GetLoadSceneRes( res_id ) if MapView.LoadBigScene[tonumber(res_id)] then self.open_big_scene_mode = true return res_id .. "_all" else return res_id end end -- --创建场景模型 -- function MapView:LoadSpiltModelList( ) -- local model_config = Config["model" .. self.curResId] -- if model_config then -- --场景基础资源包加载超时失败,改成挂在通用根节点 -- -- local model_root = GameObject.Find("splitmodel") -- -- if not model_root then -- -- model_root = GameObject.Find("root") -- -- end -- -- self.model_parent = model_root.transform -- -- SetGlobalPosition3D(self.model_parent,0, 0, 0) -- -- SetLocalScale(self.model_parent,1,1,1) -- -- self.model_parent.localEulerAngles = Vector3(0, 0, 0) -- self.load_model_count = 0 -- SapManager.Instance:WaitLoadTerrainFinish(true) -- --排序 -- local temp_model_config = {} -- local main_pos = MainCamera:getInstance():GetCameraPos() -- if main_pos then -- main_pos.x = main_pos.x/100 -- main_pos.y = main_pos.y/100 -- for k,v in pairs(model_config) do -- v.key = k -- -- table.insert(temp_model_config, v) -- temp_model_config[#temp_model_config+1] = v -- end -- local sort_func = function(a,b) -- local di = GameMath.GetDistance(main_pos.x, main_pos.y, a[3], a[5]) -- local dj = GameMath.GetDistance(main_pos.x, main_pos.y, b[3], b[5]) -- return di < dj -- end -- table.sort(temp_model_config, sort_func) -- else -- temp_model_config = model_config -- end -- local near_same_res_map = {} -- local far_same_res_map = {} -- local near_max_index = 15 -- local near_cur_index = 1 -- self.enter_scene_want_load_count = 0 -- for index, data in pairs(temp_model_config) do -- if near_cur_index <= near_max_index then -- if not near_same_res_map[data[1]] then -- near_same_res_map[data[1]] = {} -- self.enter_scene_want_load_count = self.enter_scene_want_load_count + 1 -- near_cur_index = near_cur_index + 1 -- end -- table.insert(near_same_res_map[data[1]], data.key) -- else -- if not far_same_res_map[data[1]] then -- far_same_res_map[data[1]] = {} -- self.enter_scene_want_load_count = self.enter_scene_want_load_count + 1 -- end -- table.insert(far_same_res_map[data[1]], data.key) -- end -- end -- --创建近景 -- for res,list in pairs(near_same_res_map) do -- self.combine_mini_model[res] = true -- self:OnLoadSplitModel(res,list,model_config) -- end -- --创建远景 -- -- for res,list in pairs(far_same_res_map) do -- -- self.combine_mini_model[res] = true -- -- self:OnLoadSplitModel(res,list,model_config) -- -- end -- --分帧创建远景 -- local far_step_res_map = {} -- for k,v in pairs(far_same_res_map) do -- local vo ={res = k, list = v} -- table.insert(far_step_res_map, vo) -- end -- self.far_model_index = 1 -- local function on_period( ) -- local vo = far_step_res_map[self.far_model_index] -- if vo then -- self.combine_mini_model[vo.res] = true -- self:OnLoadSplitModel(vo.res,vo.list,model_config) -- self.far_model_index = self.far_model_index + 1 -- else -- self:CancelFarModelTimer() -- end -- end -- self:CancelFarModelTimer() -- self.on_far_model_timer = GlobalTimerQuest:AddPeriodQuest(on_period, 0.01) -- end -- self.regiest_model_finish = true -- end -- function MapView:CancelFarModelTimer( ) -- if self.on_far_model_timer then -- GlobalTimerQuest:CancelQuest(self.on_far_model_timer) -- self.on_far_model_timer = nil -- end -- end -- function MapView:OnLoadSplitModel(res,list,model_config) -- local cache_list = self.model_cache_map[res] -- local map_res = self.curResId -- local load_res = function( objs, cache ) -- if objs and ( cache or objs[0]) and self.mapLoaded then -- if map_res ~= self.curResId then -- if not cache and objs[0] then -- destroy(objs[0]) -- end -- return -- end -- local single_parent = self:GetSingleParent(res) -- for k,index in pairs(list) do -- local last_model = self.model_list[index] -- if not last_model then -- if cache then -- if #cache_list > 1 then -- local info = table.remove(cache_list,#cache_list) -- if info and not IsNull(info.obj) then -- info.obj:SetActive(true) -- self:InitObj( info.obj,nil,model_config[index],single_parent,index, res ) -- end -- else -- if cache_list[1] and not IsNull(cache_list[1].obj) then -- cache_list[1].time = os.time() -- cache_list[1].obj:SetActive(true) -- self:InitObj( nil, cache_list[1].obj,model_config[index],single_parent,index, res ) -- cache_list[1].obj:SetActive(false) -- end -- end -- else -- self:InitObj( nil,objs[0],model_config[index],single_parent,index, res ) -- end -- end -- end -- else -- print("------load res error--------",res) -- end -- self.load_model_count = (self.load_model_count or 0) + 1 -- if self.support_model_combine then -- self:CombineModelList(res,list) -- end -- local next_frame = function() -- self:OnSplitModelFinish() -- end -- if self.combine_model_state then -- setTimeout(next_frame,0.01) -- else -- next_frame() -- end -- end -- if cache_list then -- if #cache_list > 0 then -- load_res(true,true) -- return -- end -- end -- local ab_name = "terrain_prefab_" .. res -- lua_resM:loadPrefab(self.load_prefab_temp_target,ab_name,res, load_res, false, ASSETS_LEVEL.NORMAL) -- end -- function MapView:OnSplitModelFinish( ) -- if self.load_model_count and self.enter_scene_want_load_count and self.load_model_count >= self.enter_scene_want_load_count then -- --静态合批 -- if self.support_model_combine and not self.combine_model_state then -- self:CombineModel() -- end -- self.combine_model_state = true -- SapManager.Instance:WaitLoadTerrainFinish(false) -- end -- end function MapView:ResetSceneActionObjHeight( ) -- local cfg = Config.ConfigSceneElevatorModel[self.curMapId] -- if not cfg then -- return -- end -- for index, vo in pairs(cfg) do -- local obj = self:GetSceneActionObj(vo.obj_name) -- if not IsNull(obj) then -- SetGlobalPositionY(obj.transform, vo.obj_start_y) -- if obj.activeSelf == false then -- obj:SetActive(true) -- end -- end -- end end function MapView:GetSceneActionObj( obj_name ) if not obj_name or obj_name == "" then return end self.action_obj_list = self.action_obj_list or {} if self.action_obj_list[obj_name] then return self.action_obj_list[obj_name] end local obj = GameObject.Find(obj_name) if not IsNull(obj) then self.action_obj_list[obj_name] = obj return obj end end function MapView:ObjectPlayAction( obj_name, action_name ) local obj = self:GetSceneActionObj(obj_name) if not IsNull(obj) then local animator = obj:GetComponent(typeof(UnityEngine.Animator)) if animator then animator:CrossFade(action_name,0) end end end