Beispiel #1
0
        private IEnumerator Populate(CellMatrixData data)
        {
            var accessor = data.GetAccessor();

            //Get the height lookup
            _heightLookup = CreateHeightLookup(accessor.heightEntries);

            for (int x = 0; x < _heightMapSizeX; x++)
            {
                for (int z = 0; z < _heightMapSizeZ; z++)
                {
                    var idx    = (x * _heightMapSizeZ) + z;
                    var height = accessor.GetHeight(idx);

                    _heightLookup.Add(x, z, height);

                    yield return(null);
                }
            }

            _heightLookup.Cleanup();

            //Init the cells
            var heightSampler = GetHeightSampler();
            var cellFactory   = GameServices.cellConstruction.cellFactory;
            var maxHeight     = _origin.y + _upperBoundary;
            var minHeight     = _origin.y - _lowerBoundary;

            for (int x = 0; x < this.columns; x++)
            {
                for (int z = 0; z < this.rows; z++)
                {
                    var idx = (z * this.columns) + x;

                    var position = new Vector3(_start.x + (x * _cellSize) + (_cellSize / 2.0f), _origin.y, _start.z + (z * _cellSize) + (_cellSize / 2.0f));
                    position.y = Mathf.Clamp(heightSampler.SampleHeight(position, this), minHeight, maxHeight);

                    var blocked = accessor.IsPermaBlocked(idx);

                    var cell = cellFactory.Create(this, position, x, z, blocked);
                    accessor.InjectData(cell, idx);

                    this.rawMatrix[x, z] = cell;

                    yield return(null);
                }
            }

            //For now we don't bake clearance data
            var cellConstruct = GameServices.cellConstruction;

            if (cellConstruct.clearanceProvider != null)
            {
                var iter = cellConstruct.clearanceProvider.SetClearance(this);
                while (iter.MoveNext())
                {
                    yield return(null);
                }
            }
        }
Beispiel #2
0
        private void InitHeightMapForEditor(CellMatrixData data)
        {
            var accessor = data.GetAccessor();

            //Get the height map
            _heightLookup = CreateHeightLookup(accessor.heightEntries);

            for (int x = 0; x < _heightMapSizeX; x++)
            {
                for (int z = 0; z < _heightMapSizeZ; z++)
                {
                    var idx    = (x * _heightMapSizeZ) + z;
                    var height = accessor.GetHeight(idx);

                    _heightLookup.Add(x, z, height);
                }
            }

            _heightLookup.Cleanup();
        }
Beispiel #3
0
        internal void UpdateForEditor(Bounds extent, CellMatrixData data)
        {
            var bounds = GetMatrixBounds(extent.center, extent.extents.x + (_cellSize * 2), extent.extents.z + (_cellSize * 2), 0.0f, true);

            if (data == null)
            {
                var blockThreshold = Mathf.Max(_obstacleSensitivityRange, 0.01f);
                for (int x = bounds.minColumn; x <= bounds.maxColumn; x++)
                {
                    for (int z = bounds.minRow; z <= bounds.maxRow; z++)
                    {
                        var cell = this.rawMatrix[x, z];

                        if (cell == null)
                        {
                            var position = new Vector3(_start.x + (x * _cellSize) + (_cellSize / 2.0f), _origin.y, _start.z + (z * _cellSize) + (_cellSize / 2.0f));

                            var blocked = IsBlocked(position, blockThreshold);

                            this.rawMatrix[x, z] = _cellFactory.Create(this, position, x, z, blocked);
                        }
                        else
                        {
                            var cellPos = cell.position;
                            var blocked = IsBlocked(cellPos, blockThreshold);

                            cell.UpdateState(cellPos.y, blocked);
                        }
                    }
                }
            }
            else
            {
                var accessor = data.GetAccessor();

                var heightSampler = GetHeightSampler();
                var maxHeight     = _origin.y + _upperBoundary;
                var minHeight     = _origin.y - _lowerBoundary;

                //Init the cells
                for (int x = bounds.minColumn; x <= bounds.maxColumn; x++)
                {
                    for (int z = bounds.minRow; z <= bounds.maxRow; z++)
                    {
                        var cell = this.rawMatrix[x, z];

                        if (cell == null)
                        {
                            var idx = (z * this.columns) + x;

                            var position = new Vector3(_start.x + (x * _cellSize) + (_cellSize / 2.0f), _origin.y, _start.z + (z * _cellSize) + (_cellSize / 2.0f));
                            position.y = Mathf.Clamp(heightSampler.SampleHeight(position, this), minHeight, maxHeight);

                            var blocked = accessor.IsPermaBlocked(idx);

                            cell = _cellFactory.Create(this, position, x, z, blocked);
                            accessor.InjectData(cell, idx);

                            this.rawMatrix[x, z] = cell;

                            cell.EnsureDataForEditor();
                        }
                    }
                }
            }
        }