local EventSystem = require('Event/EventSystem') --视图层-视野系统 local ExpVisualFieldSystem = {} function ExpVisualFieldSystem.OnVisualFieldChanged(visualFieldComp, oldLv, oldGroup) if LogicUpdateManager._curEntity then local myVisualFieldComp = LogicUpdateManager._curEntity.components.visualField if myVisualFieldComp == visualFieldComp then --logging.error(LTAG.ERROR, "HYW : OnVisualFieldChanged to ", visualFieldComp:GetVisualLevel(), visualFieldComp:GetVisualGroup(), " entity : ", visualFieldComp.entity.EntityID) for k,_entity in pairs(LogicUpdateManager._entityDic) do --pairs safe 视图操作对顺序不敏感 if LogicUpdateManager._curEntity ~= _entity and _entity:IsActive() then ExpVisualFieldSystem.RefreshEntityVisualToTarget(myVisualFieldComp, _entity) --↑ end end end end end function ExpVisualFieldSystem.OnVisiblityChanged(visualFieldComp, oldLv, oldGroup) if LogicUpdateManager._curEntity then --logging.error(LTAG.ERROR, "HYW : OnVisiblityChanged to ", visualFieldComp:GetVisiblityLevel(), visualFieldComp:GetVisiblityGroup(), " entity : ", visualFieldComp.entity.EntityID) local myVisualFieldComp = LogicUpdateManager._curEntity.components.visualField if myVisualFieldComp == visualFieldComp then if myVisualFieldComp:GetVisiblityLevel() > 0 then LogicUpdateManager._curEntity.ExpEntity:SetMaterialByType(LuaConst.EMaterialType.TRANSPARENT) else LogicUpdateManager._curEntity.ExpEntity:ResetMaterial() end else ExpVisualFieldSystem.RefreshEntityVisualToTarget(myVisualFieldComp, visualFieldComp.entity) end end end function ExpVisualFieldSystem.RefreshEntityVisualToTarget(myVisualFieldComp, targetEntity) if targetEntity.ExpEntity._visible then -- _visible 是视野机制之上的可见性,视野机制导致不可见时是控制的 isActorVisible local canSee = LevelManager.CurLevelFunc:CanSeeEntity(myVisualFieldComp.entity, targetEntity) targetEntity.ExpEntity:SetActorVisible(canSee, true) ExpSystemManager.SetSignEffectVisible(targetEntity.ExpEntity, canSee) LevelManager.CurLevelFunc.exp:OnCanSeeChanged(myVisualFieldComp, targetEntity, canSee) if not canSee or (targetEntity:IsActive() and targetEntity:IsAlive()) then EventSystem.Dispatch(EventID.UIBattle_Element_Active, targetEntity.ExpEntity.RenderEntity, canSee) if targetEntity.ExpEntity.PetRenderEntity then EventSystem.Dispatch(EventID.UIBattle_Element_Active, targetEntity.ExpEntity.PetRenderEntity, canSee) end end if canSee and (targetEntity.components.visualField and targetEntity.components.visualField:GetVisiblityLevel() > 0) then targetEntity.ExpEntity:SetMaterialByType(LuaConst.EMaterialType.TRANSPARENT) else targetEntity.ExpEntity:ResetMaterial() end end end function ExpVisualFieldSystem.RefreshEntityVisualToEnemy(myVisualFieldComp) local entity = myVisualFieldComp.entity for i,_entity in ipairs(LogicUpdateManager.EntityList_Normal) do if _entity:IsActive() and CampManager.IsEnemyEntity(entity, _entity) then ExpVisualFieldSystem.RefreshEntityVisualToTarget(myVisualFieldComp, _entity) end end for i,_entity in ipairs(LogicUpdateManager.EntityList_Sync) do if _entity:IsActive() and CampManager.IsEnemyEntity(entity, _entity) then ExpVisualFieldSystem.RefreshEntityVisualToTarget(myVisualFieldComp, _entity) end end end function ExpVisualFieldSystem.OnConvertRenderVisual(renderEntity, isVisible) if LogicUpdateManager._curEntity then if isVisible then if renderEntity then local expEntity = ExpSystemManager.GetExpEntityByRenderEntity(renderEntity) if expEntity then if CampManager.IsEnemyEntity(LogicUpdateManager._curEntity, expEntity.Entity) then ExpVisualFieldSystem.RefreshEntityVisualToTarget(LogicUpdateManager._curEntity.components.visualField, expEntity.Entity) end end end end end end return ExpVisualFieldSystem