private void RunUpdate(ref UnitySensorNode node) { node.Sensor.Sensor.Pulse(); node.Targets.UpdateWatchTargets(); for (int i = 0; i < node.Sensor.Sensor.DetectedColliders.Count; i++) { var enemy = UnityToEntityBridge.GetEntity(node.Sensor.Sensor.DetectedColliders[i]); if (enemy == null || enemy == node.Entity) { continue; } var faction = enemy.Get <FactionComponent>(); if (!World.Get <FactionSystem>().AreEnemies(faction, node.Faction)) { continue; } node.Targets.AddWatch(enemy, true); Console.Log(node.Entity.DebugId + " saw " + enemy.DebugId); } if (node.Targets.WatchTargets.Count != 0) { return; } _tempEnemyList.Clear(); World.Get <FactionSystem>().FillFactionEnemiesList(_tempEnemyList, node.Faction.Faction); var nodePos = node.Tr.position.WorldToGenericGrid(HearingSectorSize); for (int f = 0; f < _tempEnemyList.Count; f++) { var enemy = _tempEnemyList[f]; var tr = enemy.Get <TransformComponent>(); if (tr == null) { Debug.Log("Enemy has no TR " + enemy.DebugId); continue; } if (tr.position.WorldToGenericGrid(HearingSectorSize) != nodePos) { continue; } var hearingChance = HearingChance; if (enemy.Tags.Contain(EntityTags.PerformingCommand)) { hearingChance *= 4; } else if (enemy.Tags.Contain(EntityTags.Moving)) { hearingChance *= 2; } if (Game.Random.DiceRollSucess(hearingChance)) { if (!Physics.Linecast(tr.position, node.Tr.position, LayerMasks.Walls)) { node.Targets.AddWatch(enemy, false); Console.Log(node.Entity.DebugId + " heard " + enemy.DebugId); } } } }
public SensorSystem() { NodeFilter <SensorDetectingNode> .Setup(SensorDetectingNode.GetTypes()); _sensorNodes = EntityController.GetNodeList <SensorDetectingNode>(); NodeFilter <UnitySensorNode> .Setup(UnitySensorNode.GetTypes()); _unitySensorNodes = EntityController.GetNodeList <UnitySensorNode>(); EntityController.RegisterReceiver(new EventReceiverFilter(this, new[] { typeof(SensorTargetsComponent) })); }