Exemple #1
0
        /// <summary>
        /// Recalculate RoomData
        /// </summary>
        public void RecalculateData()
        {
            receivers = new List <ReceiverData>();
            Grid grid = Room.GetComponentInChildren <Grid>();

            foreach (Tilemap map in grid.GetComponentsInChildren <Tilemap>())
            {
                if (map.name == "Teleporter")
                {
                    foreach (Vector3Int pos in map.cellBounds.allPositionsWithin)
                    {
                        Vector3Int localplace = new Vector3Int(pos.x, pos.y, pos.z);

                        if (!map.HasTile(localplace))
                        {
                            continue;
                        }

                        string     tileName     = map.GetTile(pos).name;
                        Vector2Int tileChunkPos = MVUtility.TilePosToLocalChunkPos(pos.x, pos.y, chunkTopLeft, new Vector2Int(24, 16));

                        if (tileName[0] == 'O' && tileName.Length == 2 && char.IsDigit(tileName[1]))
                        {
                            //Receiver
                            ReceiverData receiverData = new ReceiverData {
                                name     = tileName,
                                chunkPos = tileChunkPos
                            };
                            receivers.Add(receiverData);
                        }
                        else if (tileName[0] == 'I' && tileName.Length == 2 && char.IsDigit(tileName[1]))
                        {
                            //Teleporter
                            TeleporterData teleporter = teleporters.FirstOrDefault(x => x.teleporter == tileName);
                            if (teleporter == null)
                            {
                                continue;
                            }
                            //atas
                            if (tileChunkPos.x < 0)
                            {
                                teleporter.teleporterType      = TeleporterData.TeleporterType.Vertical;
                                teleporter.teleporterDirection = Direction.Up;
                                teleporter.chunkPos            = tileChunkPos + Vector2Int.right;
                            }
                            //bawah
                            else if (tileChunkPos.x >= chunkSize.x)
                            {
                                teleporter.teleporterType      = TeleporterData.TeleporterType.Vertical;
                                teleporter.teleporterDirection = Direction.Down;
                                teleporter.chunkPos            = tileChunkPos + Vector2Int.left;
                            }
                            //kiri
                            else if (tileChunkPos.y < 0)
                            {
                                teleporter.teleporterType      = TeleporterData.TeleporterType.Horizontal;
                                teleporter.teleporterDirection = Direction.Left;
                                teleporter.chunkPos            = tileChunkPos + Vector2Int.up;
                            }
                            //kanan
                            else if (tileChunkPos.y >= chunkSize.y)
                            {
                                teleporter.teleporterType      = TeleporterData.TeleporterType.Horizontal;
                                teleporter.teleporterDirection = Direction.Right;
                                teleporter.chunkPos            = tileChunkPos + Vector2Int.down;
                            }
                            //bug :v
                            else
                            {
                                teleporter.teleporterType      = TeleporterData.TeleporterType.Direct;
                                teleporter.teleporterDirection = Direction.Up;
                                teleporter.chunkPos            = tileChunkPos;
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Get local chunk position based from tile position
 /// </summary>
 /// <param name="pos">tile position</param>
 /// <returns>position of chunk in room</returns>
 public Vector2Int GetLocalChunkPos(Vector3Int pos)
 {
     return(MVUtility.TilePosToLocalChunkPos(pos.x, pos.y, activeRoomData.chunkTopLeft, new Vector2Int(24, 16)));
 }