コード例 #1
0
ファイル: MapEditWindow.cs プロジェクト: ubiquitous42/robots
    void AddWallInDirection(Facing direction)
    {
        GrabTilesFromSelection();

        string wallPath = "Assets/Prefabs/Walls/Basic Wall.prefab";
        var    prefab   = Resources.LoadAssetAtPath(wallPath, typeof(Wall));

        if (null == prefab)
        {
            Debug.Log("Wall prefab not found!");
            return;
        }

        foreach (Tile tile in selectedTiles)
        {
            if (null != tile.adjacentWalls[(int)direction])
            {
                Debug.Log("Wall already exists in that direction!");
                continue;
            }

            var rotation = Utils.RotationForFacing(direction);
            var position = (new Vector3(tile.x_pos, 0, tile.y_pos) * (1 + tileSeparation)) + (0.5f * (1 + tileSeparation) * Utils.UnitOffsetForDirection(direction));

            Wall newWall = (Wall)GameObject.Instantiate(prefab, position, rotation);

            newWall.transform.parent = tile.transform.parent;
            newWall.facing           = direction;

            newWall.Setup();

            newWall.adjacentTiles.Add(tile);
            tile.adjacentWalls[(int)direction] = newWall;

            var otherTile = currentMap.GetTileInDirection(tile, direction);
            if (null != otherTile)
            {
                newWall.adjacentTiles.Add(otherTile);
                otherTile.adjacentWalls[(int)Utils.UTurnFacing(direction)] = newWall;
            }

            TileVisualizer.instance.SetVisualizationForWall(newWall);
        }
    }