Beispiel #1
0
        public WallsSpecification CreateWallsSpecification(FloorSpecification floorSpecification)
        {
            _outsideWallWidgets = GetComponents <WallGenerationWidget>().ToList();
            var wallsSpecification = new WallsSpecification(new Vector2Int(floorSpecification.FloorPresenceArray.GetLength(0), floorSpecification.FloorPresenceArray.GetLength(1)));

            _outsideWallWidgets.ForEach(c => c.AddWalls(wallsSpecification, floorSpecification));
            return(wallsSpecification);
        }
Beispiel #2
0
        public void InstantiateWalls(Vector2Int size, WallsSpecification wallsSpecification)
        {
            for (int x = 0; x < size.x; x++)
            {
                for (int y = 0; y < size.y; y++)
                {
                    var directions = wallsSpecification.GetWallDirections(new Vector2Int(x, y));

                    foreach (var aDirection in directions)
                    {
                        float angle;
                        switch (aDirection)
                        {
                        case WallDirection.Up:
                            angle = 90;
                            break;

                        case WallDirection.Down:
                            angle = -90;
                            break;

                        case WallDirection.Left:
                            angle = 0;
                            break;

                        case WallDirection.Right:
                            angle = 180;
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }

                        var center = size / 2;

                        var position = new Vector3(x, 0, y) - new Vector3(center.x, 0, center.y);
                        var rotation = Quaternion.Euler(0, angle, 0);

                        Transform prefab = wallsSpecification.GetIsDestructible(new Vector2Int(x, y))
                            ? _destructibleWallPrefab
                            : _indestructibleWallsPrefab;

                        var wall = GameObject.Instantiate(prefab, position, rotation, _wallsParent);
                        wall.transform.localPosition = position;
                        wall.transform.localRotation = rotation;
                        wall.name = $"Wall {x}-{y}-{aDirection}-{prefab.name}";
                    }
                }
            }
        }