private void GetRoomTiles() { tiles = new Dictionary <Vector3Int, WorldTile>(); teleporter = new List <WorldTile>(); foreach (Tilemap map in grid.GetComponentsInChildren <Tilemap>()) { foreach (Vector3Int pos in map.cellBounds.allPositionsWithin) { Vector3Int localplace = new Vector3Int(pos.x, pos.y, pos.z); if (!map.HasTile(localplace)) { continue; } if (tiles.ContainsKey(localplace)) { tiles.Remove(localplace); } WorldTile tile = new WorldTile() { localPlace = localplace, worldLocation = map.GetCellCenterWorld(localplace), tileBase = map.GetTile(localplace), tilemapMember = map, }; tile.name = tile.tileBase.name; if (map.name == "Teleporter") { if (tile.name[0] == 'I' && tile.name.Length == 2 && char.IsDigit(tile.name[1])) { TeleporterData teleporter = RoomManager.main.activeRoomData.teleporters.SingleOrDefault(x => x.teleporter == tile.name); if (teleporter != null) { tile.roomTarget = teleporter.targetRoom; tile.teleportTarget = teleporter.targetTeleporter; } } teleporter.Add(tile); } tiles.Add(tile.localPlace, tile); } } }
bool IsNearPos(GlobalStructureList aGlobalStructureList, TeleporterData aTarget, PVector3 aTestPos) { var StructureInfo = SearchEntity(aGlobalStructureList, aTarget.Id); if (StructureInfo == null) { log($"TargetStructure missing:{aTarget.Id} pos={aTarget.Position.String()}", LogLevel.Error); return(false); } var StructureRotation = GetMatrix4x4(GetVector3(StructureInfo.Data.rot)); var TeleporterPos = Vector3.Transform(aTarget.Position, StructureRotation) + GetVector3(StructureInfo.Data.pos); var Distance = Math.Abs(Vector3.Distance(TeleporterPos, GetVector3(aTestPos))); log($"FoundTarget:{StructureInfo.Data.id}/{StructureInfo.Data.type} pos={StructureInfo.Data.pos.String()} TeleportPos={TeleporterPos.String()} TEST {aTestPos.String()} => {Distance}", LogLevel.Message); return(Distance < 4); }
TeleporterTargetData GetCurrentTeleportTargetPosition(GlobalStructureList aGlobalStructureList, TeleporterData aTarget) { var StructureInfo = SearchEntity(aGlobalStructureList, aTarget.Id); if (StructureInfo == null) { log($"TargetStructure missing:{aTarget.Id} pos={aTarget.Position.String()}", LogLevel.Error); return(null); } var StructureInfoRot = GetVector3(StructureInfo.Data.rot); var StructureRotation = GetMatrix4x4(StructureInfoRot); var TeleportTargetPos = Vector3.Transform(aTarget.Position, StructureRotation) + GetVector3(StructureInfo.Data.pos); log($"CurrentTeleportTargetPosition:{StructureInfo.Data.id}/{StructureInfo.Data.type} pos={StructureInfo.Data.pos.String()} TeleportPos={TeleportTargetPos.String()}", LogLevel.Message); return(new TeleporterTargetData() { Id = aTarget.Id, Playfield = StructureInfo.Playfield, Position = TeleportTargetPos, Rotation = aTarget.Rotation + StructureInfoRot }); }