public void Init() { GameObject[] portals = GameObject.FindGameObjectsWithTag("Portal"); var channelDict = new Dictionary <int, EcsEntity>(); var filledChannels = new HashSet <int>(); foreach (GameObject portal in portals) { int?channelNum = GetChannelFrom(portal); if (!channelNum.HasValue) { Debug.LogError($"Portal {portal.name} has wrong name!"); continue; } int channel = channelNum.Value; if (filledChannels.Contains(channel)) { Debug.LogError($"Channel {channel.ToString()} for portal {portal.name} already used!"); continue; } EcsEntity portalEntity = _ecsWorld.NewEntityWith( out PortalComponent portalComponent, out CreateWorldObjectEvent createEvt); createEvt.Transform = portal.transform; if (channelDict.ContainsKey(channel)) { filledChannels.Add(channel); EcsEntity otherPortalEntity = channelDict[channel]; portalComponent.OtherPortalEntity = channelDict[channel]; PortalComponent otherPortal = otherPortalEntity.Get <PortalComponent>(); otherPortal.OtherPortalEntity = portalEntity; } else { channelDict.Add(channel, portalEntity); } } }
public void Run() { foreach (int i in _moveObjects) { Vector2Int newPosition = _moveObjects.Get1[i].NewPosition; EcsEntity movableEntity = _moveObjects.Entities[i]; foreach (EcsEntity entity in _worldService.WorldField[newPosition.x][newPosition.y]) { var portal = entity.Get <PortalComponent>(); if (portal == null || portal.EstimateReloadTime > 0) { continue; } EcsEntity otherPortalEntity = portal.OtherPortalEntity; var otherPortal = otherPortalEntity.Get <PortalComponent>(); Vector2Int otherPortalPosition = otherPortalEntity.Get <PositionComponent>().Position; movableEntity.Set <TeleportedEvent>().NewPosition = otherPortalPosition; portal.EstimateReloadTime = _gameDefinitions.portalDefinition.portalReloadTime; otherPortal.EstimateReloadTime = _gameDefinitions.portalDefinition.portalReloadTime; } } float dt = Time.deltaTime; foreach (int i in _portals) { PortalComponent portalComponent = _portals.Get1[i]; if (portalComponent.EstimateReloadTime > 0) { portalComponent.EstimateReloadTime -= dt; } } }