Пример #1
0
        private bool TryAttachComponentInternal(Attachable comp, GridPoint pos, bool attach)
        {
            var end = pos + new GridPoint(comp.GridWidth, comp.GridHeight);

            if (pos.X < 0 || pos.Y < 0 ||
                end.X >= size.X || end.Y >= size.Y ||
                AreaHasComponent(pos, end))
            {
                return(false);
            }

            if (attach)
            {
                for (var x = pos.X; x < end.X; x++)
                {
                    for (var y = pos.Y; y < end.Y; y++)
                    {
                        grid[x, y] = comp;
                    }
                }
            }

            return(true);
        }
Пример #2
0
 public bool CanAttachComponent(Attachable comp, GridPoint pos)
 {
     return(!TryAttachComponentInternal(comp, pos, false));
 }
Пример #3
0
 public bool TryAttachComponent(Attachable comp, GridPoint pos)
 {
     return(TryAttachComponentInternal(comp, pos, true));
 }
Пример #4
0
 private void Start()
 {
     size = new GridPoint(Width, Height);
     grid = new Attachable[size.X, size.Y];
 }