示例#1
0
        public Vector2 SnapToWorldGridPosition(Vector2 centerWorldPosition, GridObject2DData objectData)
        {
            int rightOffset  = (int)-objectData.rightPartWidth;
            int leftOffset   = (int)objectData.leftPartWidth;
            int topOffset    = (int)-objectData.topPartHeight;
            int bottomOffset = (int)objectData.bottomPartHeight;

            return(SnapToWorldGridPosition(centerWorldPosition, leftOffset, rightOffset, bottomOffset, topOffset));
        }
示例#2
0
        public bool CanPutDownObject(GridObject2DData objectData, Vector2 worldPosition)
        {
            var positionInGridReferenceFrame = ClampToLocalGridPosition(worldPosition);

            foreach (var occupiedOffsetOnObject in objectData.occupiedOffsets)
            {
                var point = positionInGridReferenceFrame + occupiedOffsetOnObject;
                if (_gridObjectInstances.Any(o => o.IsPositionOnObject(point)))
                {
                    return(false);
                }
            }

            return(true);
        }
示例#3
0
        private GridObject2D(string name, List <Vector2Int> occupiedOffsets, T initialValue = default(T))
        {
            this._data    = null;
            _initialValue = initialValue;

            foreach (var offset in occupiedOffsets)
            {
                var newCellLocalPosition = new Vector2Int(gridReferenceFramePosition.x + offset.x, gridReferenceFramePosition.y + offset.y);
                _gridObjectCells.Add(new GridObjectCell <T>()
                {
                    value         = _initialValue,
                    localPosition = newCellLocalPosition
                });
            }
        }
示例#4
0
        public void PutDownObject(GridObject2DData objectData, Vector2 worldPosition, T value = default(T))
        {
            var positionOnGrid = SnapToLocalGridPosition(worldPosition, objectData);
            var newGridObject  = new GridObject2D <T>("Grid Object", objectData, value);

            newGridObject.SetLocalPosition(new Vector2Int(positionOnGrid.x, positionOnGrid.y));

            foreach (var position in newGridObject.gridReferenceFrameCellPositions)
            {
                _grid[position.y, position.x] = newGridObject.GetValueAt(position);
            }

            _gridObjectInstances.Add(newGridObject);

            _visualization.Refresh();
        }
示例#5
0
 public GridObject2D(string name, GridObject2DData data, T initialValue = default(T)) : this(name, data.occupiedOffsets, initialValue)
 {
     this._data = data;
 }