public virtual void DetachObject() { if (Attachment != null) { _attachment.DetachFromParent(); _attachment.DetachedFromGrid(); _attachment = null; } }
/// <summary> /// Detaches an object from the grid, removing all references to it from the cells. /// </summary> /// <param name="gridObject"></param> public void DetachObject(GridObject gridObject, bool updateParent = true) { Vector2Int coords = gridObject.Coordinates; if (updateParent) { gridObject.transform.parent = transform; } if (_grid[coords.x, coords.y].IsOccupied && _grid[coords.x, coords.y].Occupant.Attachment == gridObject) { _grid[coords.x, coords.y].Occupant.DetachObject(); return; } gridObject.DetachedFromGrid(); if (IsPointWithinBounds(coords.x, coords.y)) { _grid[coords.x, coords.y].Reset(); _emptyCellsList.Add(_grid[coords.x, coords.y]); } }