Example #1
0
    public void SetRoomWalls(Vector2 pos)
    {
        int right = (int)pos.x;
        int up    = (int)pos.y;
        ShipComponent_Room room       = ship.GetRoom(new Vector2(right, up));
        GameObject         roomObject = representation.rooms[right, up];

        ShipComponent_Room.WallType[] walls = new ShipComponent_Room.WallType[4];
        for (int i = 0; i < roomObject.transform.childCount; i++)
        {
            Destroy(roomObject.transform.GetChild(i).gameObject);
        }
        if (up + 1 > grid.rows - 1 || ship.GetRoom(new Vector2(right, up + 1)) == null)
        {
            walls[0] = ShipComponent_Room.WallType.wall;
            CreateWallRepresentation(roomObject, new Vector2(0, 1));
        }
        if (right + 1 > grid.cols - 1 || ship.GetRoom(new Vector2(right + 1, up)) == null)
        {
            walls[1] = ShipComponent_Room.WallType.wall;
            GameObject wall     = CreateWallRepresentation(roomObject, new Vector2(1, 0));
            Vector3    rotation = wall.transform.rotation.eulerAngles;
            rotation.z += 90;
            Quaternion q = Quaternion.Euler(rotation);
            wall.transform.rotation = q;
        }
        if (up - 1 < 0 || ship.GetRoom(new Vector2(right, up - 1)) == null)
        {
            walls[2] = ShipComponent_Room.WallType.wall;
            CreateWallRepresentation(roomObject, new Vector2(0, -1));
        }
        if (right - 1 < 0 || ship.GetRoom(new Vector2(right - 1, up)) == null)
        {
            walls[3] = ShipComponent_Room.WallType.wall;
            GameObject wall     = CreateWallRepresentation(roomObject, new Vector2(-1, 0));
            Vector3    rotation = wall.transform.rotation.eulerAngles;
            rotation.z += 90;
            Quaternion q = Quaternion.Euler(rotation);
            wall.transform.rotation = q;
        }
        ship.SetWalls(room, walls);
    }