local ViewAssets_Controller = {} local private = {} local ExpEntity = require "Battle/Expression/ExpEntity/ExpEntity" local LuaUpdater = require "Main/LuaUpdater" local PSEffectPath = ConstAssetPathConfig.PsGroupPath ViewAssets_Controller.CameraMode = { Town = 1, PVP = 2, UIDisplay = 3, Free = 4, } function ViewAssets_Controller.OnStartup() private.curRenderEntity = nil private.curEntity = nil private.renderEntity = nil private.startRenderEntity = nil private.targetRenderEntity = nil private.hookEffectPlayID = nil private.missileMap = {} end function ViewAssets_Controller.Init() local entities = LevelPlayerManager.GetPlayerEntitysByPlayerIDInRoom(1) local entity = entities[1] private.curEntity = entity private.curRenderEntity = entity.ExpEntity.RenderEntity private.renderEntity = AuxUtil.LoadRenderEntity(true, 1, 0, -1, -1, false, LuaConst.EntityCullingMode.NoCulling) local ctrlPathId=UTL.String.GetIdByString("Assets/Prefab/Actor/Gizmo/Gizmo_Empty/Gizmo_Empty.controller") local pathId = UTL.String.GetIdByString("Assets/Prefab/Actor/Gizmo/Gizmo_Empty/Gizmo_Empty.prefab") private.renderEntity:SetModel(0, pathId, 0, 1, ctrlPathId, 0, -1, 0, 0, 0) private.startRenderEntity = AuxUtil.LoadRenderEntity(true, 1, 0, -1, -1, false, LuaConst.EntityCullingMode.NoCulling) private.targetRenderEntity = AuxUtil.LoadRenderEntity(true, 1, 0, -1, -1, false, LuaConst.EntityCullingMode.NoCulling) local pathId = UTL.String.GetIdByString("Assets/Actor/Hero/Hero_ZhaoYun/Hero_ZhaoYun.prefab") local ctrlPathId = UTL.String.GetIdByString("Assets/Actor/Hero/Hero_ZhaoYun/Hero_ZhaoYun.controller") private.startRenderEntity:SetModel(1, pathId, 0, 1, ctrlPathId, 0, -1, 1, 1, 1) private.targetRenderEntity:SetModel(1, pathId, 0, 1, ctrlPathId, 0, -1, 1, 1, 1) end function ViewAssets_Controller.Exit() private.curEntity = nil private.curRenderEntity = nil if private.renderEntity then private.renderEntity:Dispose(false) private.renderEntity = nil end ViewAssets_Controller.DestroyHook() if private.startRenderEntity then private.startRenderEntity:Dispose(false) private.startRenderEntity = nil end if private.targetRenderEntity then private.targetRenderEntity:Dispose(false) private.targetRenderEntity = nil end for id, v in pairs(private.missileMap) do private.DestroyMissile(id) end LuaUpdater.StopUpdate(private.OnUpdateMissile) end function ViewAssets_Controller.SetModel(id, isPVP) local modelData = DataSheetManager.MonsterModelData:GetDataByID (id) local modelPath = modelData.Path if isPVP then modelPath = ViewAssets_Controller:GetPVPModelPath(modelPath) end local ctrlPath = ExpEntity.GetCtrlPath(modelData, ExpEntity.ModelCtrlType_InBattle) local modePathId = UTL.String.GetIdByString(modelPath) local ctrlPathId = UTL.String.GetIdByString(ctrlPath) private.curRenderEntity:ChangeModel(id, modePathId, 0, 1, ctrlPathId, 0, -1, 1, 1) end function ViewAssets_Controller.PlayAnimation(anim) if private.curRenderEntity then local animIntKey= UTL.String.GetIdByString(anim) private.curRenderEntity:PlayAnimation(animIntKey, false, true) end end function ViewAssets_Controller.PlayEffect(effectPath) if private.curRenderEntity then local effectPathId = UTL.String.GetIdByString(effectPath) private.curRenderEntity:PlayEffect(effectPathId, -1, true, 0, 13, 1) end end function ViewAssets_Controller.StopEffect() private.curRenderEntity:BreakEffect() end function ViewAssets_Controller.SetCameraMode(cameraMode) if cameraMode == ViewAssets_Controller.CameraMode.Town then CameraController.Instance:EnterLevel(2, 2) elseif cameraMode == ViewAssets_Controller.CameraMode.PVP then CameraController.Instance:EnterLevel(4, 4) elseif cameraMode == ViewAssets_Controller.CameraMode.UIDisplay then UIModelUtils.SetVirtualCamera(3, private.curRenderEntity.Transform) end end function ViewAssets_Controller.LoadScene(levelId) private.ExitLevel() private.EnterLevel(levelId) end function private.ExitLevel() LuaShoveManager.ExitLevel() LevelItemManager.ExitLevel() end function private.EnterLevel(levelId) local levelInfoData = DataSheetManager.LevelInfoData:GetDataByLevelID(levelId) AppLoadingProxy.LoadScene(levelInfoData.ScenePath) local walkPlane = levelInfoData.WalkPlane~="" and levelInfoData.WalkPlane or levelInfoData.ScenePath BattleExt.SetLevelMapInfo(levelInfoData.LevelID, walkPlane) --地图的格子信息 ;设置寻路数据 LuaShoveManager.InitLevel() LuaShoveManager.CheatFlattenTerrain() LevelItemManager.BeforeInitLevel() LevelItemManager.AfterInitLevel(levelId) local bornItem = LevelItemManager.GetBornItem(LuaConst.PlayerDefaultBornIndex) local bornPos = bornItem.ItemData.ItemPos local bornDir = bornItem.ItemData.ItemDir private.curEntity:SetLogicPos(bornPos) private.curEntity:SetLogicRotateDir(bornDir) end --pvp模型 function ViewAssets_Controller:GetPVPModelPath(modelPath) local dir, actorDir,prefab = string.match(modelPath, "(%S*)/(%S*)/(%S*)") local newPrefab = string.gsub(prefab, actorDir ,actorDir.."_PVP") return string.gsub(modelPath, prefab ,newPrefab) end --主城和战斗模型 function ViewAssets_Controller.GetHeroModelListByHeroID(heroID) local list = {} local heroData = DataSheetManager.HeroData:GetDataByID(heroID) --原皮 + pvp table.insert(list, {name = "原皮", modelID = heroData.ModelID}) table.insert(list, {name = "原皮PVP", modelID = heroData.ModelID, isPVP = true}) local appearanceList = {} --外观 + pvp for _, v in DataSheetManager.HeroAppearance:GetEnumerator() do if heroID == v.HeroID then local data = {name = UIUtils.GetLocalizedTxt(Const_IDS[v.AppearanceName]), modelID = v.BattleModel} table.insert(appearanceList, data) table.insert(list, data) end end for _, v in ipairs(appearanceList) do table.insert(list, {name = v.name .. "PVP", modelID = v.modelID, isPVP = true}) end return list end function ViewAssets_Controller.PlayMissileEffect(psResource, isHook) if isHook then local psResourceCombined = string.format(PSEffectPath, psResource) local pos, rotate local pos, rotate = private.curEntity.ExpEntity.RenderEntity.Transform:GetPositionAndRotation(pos, rotate) private.startRenderEntity.Transform:SetPositionAndRotation(pos, rotate) private.startRenderEntity:SetVisible(true) private.targetRenderEntity.Transform:SetPositionAndRotation(Vector3.New(pos.x + 15, pos.y, pos.z + 15), rotate) private.targetRenderEntity:SetVisible(true) private.hookEffectPlayID = AuxUtil.PlayPsEffect(psResourceCombined, private.startRenderEntity, LuaConst.Layer.Hero_Self, true, false) AuxUtil.PsHandleEntityRelated(private.hookEffectPlayID, private.targetRenderEntity) else local missile = private.CreateMissile(private.curEntity) local effectPlayID = AuxUtil.PlayMissileFollowEffect(private.renderEntity, missile.Trans, psResource, true, LuaConst.CharacterType.Hero, LuaConst.Layer.Hero_Self, 10000, 1, false) private.missileMap[effectPlayID] = missile LuaUpdater.StartUpdate(private.OnUpdateMissile) end end function private.OnUpdateMissile(deltaTime, timeSinceUpdate) if not next(private.missileMap) then LuaUpdater.StopUpdate(private.OnUpdateMissile) return end for id, missile in pairs(private.missileMap) do local moveX, moveZ = missile.Trans.forward.x * 3 * deltaTime, missile.Trans.forward.z * 3 * deltaTime local posX, posY, poxZ = missile.Trans:GetPosition() missile.Trans:SetPosition(posX + moveX, posY, poxZ + moveZ) if Vector3.Distance(Vector3.New(missile.Trans:GetPosition()), missile.StartPos) > 15 then private.DestroyMissile(id) end end end function private.CreateMissile(entity) local trans = AuxUtil.GetEmptyObjectTransform(AuxUtil.GetGlobalEffectRoot()) local pos, rotate local pos, rotate = entity.ExpEntity.RenderEntity.Transform:GetPositionAndRotation(pos, rotate) trans:SetPositionAndRotation(pos, rotate) return { Trans = trans, StartPos = pos, } end function private.DestroyMissile(id) local missile = private.missileMap[id] AuxUtil.StopMissileFollowEffect(id) AuxUtil.ReturnEmptyObject(missile.trans) private.missileMap[id] = nil end function ViewAssets_Controller.DestroyHook() private.startRenderEntity:SetVisible(false) private.targetRenderEntity:SetVisible(false) if private.hookEffectPlayID then AuxUtil.PsHandleEntityUnrelated(private.hookEffectPlayID, private.targetRenderEntity) AuxUtil.StopPsEffect(private.hookEffectPlayID) private.hookEffectPlayID = nil end end return ViewAssets_Controller