--视野系统 local VisualFieldSystem = {} function VisualFieldSystem.OnVisualFieldChanged(visualFieldComp, oldLv, oldGroup) if oldLv > visualFieldComp:GetVisiblityLevel() then if visualFieldComp.entity.components.target then if visualFieldComp.entity.components.target.Target and not LevelManager.CurLevelFunc:CanSeeEntity(visualFieldComp.entity, visualFieldComp.entity.components.target.Target) then SystemManager.SetTarget(visualFieldComp.entity, nil) end end end end function VisualFieldSystem.OnVisiblityChanged(visualFieldComp, oldLv, oldGroup) if oldLv < visualFieldComp:GetVisiblityLevel() then local changedEntity = visualFieldComp.entity for i,_entity in ipairs(LogicUpdateManager.EntityList_Normal) do if _entity.components.target and _entity.components.target.Target == changedEntity then SystemManager.SetTarget(_entity, nil) end end for i,_entity in ipairs(LogicUpdateManager.EntityList_Sync) do if _entity.components.target and _entity.components.target.Target == changedEntity then SystemManager.SetTarget(_entity, nil) end end end end --根据视野等级看能否看到entity function VisualFieldSystem.CanSeeEntityByVisualLevel(seeingEntity, beSawEntity) local seeingEntityVisualComp = seeingEntity.components.visualField local otherVisualComp = beSawEntity.components.visualField if seeingEntityVisualComp and otherVisualComp then local beSawEntityVisiblityLevel = otherVisualComp:GetVisiblityLevel() local seeingEntityVisualLevel = seeingEntityVisualComp._visualLv local seeingEntityVisualGroup = seeingEntityVisualComp._visualGroup local beSawEntityVisiblityGroup = otherVisualComp._visualbilityGroup --0 nil 0 -1,四个值,优化 return ((beSawEntityVisiblityGroup == -1 or seeingEntityVisualGroup == -1 or seeingEntityVisualGroup == beSawEntityVisiblityGroup) and seeingEntityVisualLevel == beSawEntityVisiblityLevel) or seeingEntityVisualLevel > beSawEntityVisiblityLevel end return true end --共享视野等级 function VisualFieldSystem.CanSeeEntityByShareVisualLevel(seeingEntity, beSawEntity, campVisualDic) local beSawEntityVisualFieldComp = beSawEntity.components.visualField local beSawEntityVisibilityLv = beSawEntityVisualFieldComp:GetVisiblityLevel() local beSawEntityVisibilityGroup = beSawEntityVisualFieldComp._visualbilityGroup local result = false local campID = seeingEntity:GetCampID() local campVisualList = campVisualDic[campID] if campVisualList then for i,v in ipairs(campVisualList) do if VisualFieldSystem.CanSeeEntityByVisualLevel(seeingEntity, beSawEntity) then return true end end end return false end return VisualFieldSystem