Пример #1
0
        public override void Initialise()
        {
            // Sanity check
            if (MaxGridSize.x <= 0 || MaxGridSize.y <= 0 || GridScale <= 0)
            {
                return;
            }

            _fences = new List <Fence>();

            _gridOffset = new Vector3(MaxGridSize.x * GridScale, 0, MaxGridSize.y * GridScale) * -0.5f;


            for (var y = 0; y <= MaxGridSize.y; ++y)
            {
                for (var x = 0; x <= MaxGridSize.x; ++x)
                {
                    if (y < MaxGridSize.y)
                    {
                        _fences.Add(new Fence(
                                        new Vector2Int(x, y),
                                        new Vector3(x * GridScale, 0, y * GridScale) + _gridOffset,
                                        true,
                                        false)
                                    );
                    }
                    if (x < MaxGridSize.x)
                    {
                        _fences.Add(new Fence(
                                        new Vector2Int(x, y),
                                        new Vector3(x * GridScale, 0, y * GridScale) + _gridOffset,
                                        false,
                                        false)
                                    );
                    }
                }
            }

            _fenceCollection = new ViewModelCollection <Fence>(gameObject, GroundTile, _container);
            _fenceCollection.AddItems(_fences);
        }
Пример #2
0
        public override void Initialise()
        {
            // Sanity check
            if (MaxGridSize.x <= 0 || MaxGridSize.y <= 0 || GridScale <= 0)
            {
                return;
            }

            _tiles = new List <Tile>();

            _gridOffset = new Vector3(MaxGridSize.x * GridScale, 0, MaxGridSize.y * GridScale) * -0.5f;

            // Create initial grid in center
            Vector2Int initialGridOffset = (MaxGridSize - InitialGridSize);

            initialGridOffset.x /= 2;
            initialGridOffset.y /= 2;

            for (var y = 0; y < MaxGridSize.y; ++y)
            {
                for (var x = 0; x < MaxGridSize.x; ++x)
                {
                    bool isBuilt = x >= initialGridOffset.x &&
                                   x < initialGridOffset.x + InitialGridSize.x &&
                                   y >= initialGridOffset.y &&
                                   y < initialGridOffset.y + InitialGridSize.y;

                    _tiles.Add(new Tile(
                                   new Vector2Int(x, y),
                                   new Vector3(x * GridScale, 0, y * GridScale) + _gridOffset,
                                   isBuilt)
                               );
                }
            }

            _tileCollection = new ViewModelCollection <Tile>(gameObject, GroundTile, _container);
            _tileCollection.AddItems(_tiles);
        }