Example #1
0
        public void SetValue(T value, Vector2 worldPosition)
        {
            GridObject2D <T> objectToSetValue = GetObjectAt(worldPosition);

            if (objectToSetValue == null)
            {
                return;
            }

            var localPosition = ClampToLocalGridPosition(worldPosition);

            _grid[localPosition.y, localPosition.x] = value;

            objectToSetValue.SetValueAt(localPosition, value);
            _visualization.Refresh();
        }
Example #2
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();
        }