public void AddShapesToPosition(IndexedPosition indexedPosition) { var parent = TableViewManager.ContainerTransform; var height = BlockViews.GetLength(0); var width = BlockViews.GetLength(1); Shape = null; var index = 0; for (var i = 0; i < height; i++) { for (var j = 0; j < width; j++) { if (BlockViews[i, j] != null) { BlockViews[i, j].SetParent(parent); BlockViews[i, j].SetLocalPosition(new Vector3(j + indexedPosition.X, -i - indexedPosition.Y)); TableViewManager.BlockViews[indexedPosition.Y + i, indexedPosition.X + j] = BlockViews[i, j]; } } } BlockViews = null; }
public void SendTryAddShapeSignal(IndexedPosition position) { if (position.Y < 0 || position.X < 0) { return; } TryAddShapeToMapSignal.Dispatch(ShapeView.Shape, position, AddShapes); }
public static IndexedPosition GetPosition(int index) { IndexedPosition result; if (!indexes.TryGetValue(index, out result)) { result = new IndexedPosition(index); indexes[index] = result; } return(result); }
private bool CheckShapes(IndexedPosition position) { foreach (var shape in MapModel.Shapes) { if (CheckShape(position, shape.ShapeMatrix)) { return(true); } } return(false); }
private void OnMouseUp() { if (!_isDrag) { return; } var height = Shape.GetLength(0); var width = Shape.GetLength(1); var topLeftShapePos = new Vector3(0.5f - width / 2f, height / 2f - 0.5f); var topLeftPos = TableViewManager.TopLeftAnchorPosition - topLeftShapePos; var yIndex = topLeftPos.y - transform.position.y + 0.5f; var xIndex = transform.position.x - topLeftPos.x + 0.5f; var indexedPosition = new IndexedPosition((int)yIndex, (int)xIndex); _isDrag = false; _animator.SetBool("Take", false); GoToCenter(); ShapeContainer.SendTryAddShapeSignal(indexedPosition); }
private bool CheckShape(IndexedPosition position, bool[,] shape) { if (MapModel.Map.GetLength(0) < position.Y + shape.GetLength(0)) { return(false); } if (MapModel.Map.GetLength(1) < position.X + shape.GetLength(1)) { return(false); } for (var i = 0; i < shape.GetLength(0); i++) { for (var j = 0; j < shape.GetLength(1); j++) { if (shape[i, j] && MapModel.Map[position.Y + i, position.X + j]) { return(false); } } } return(true); }
int GetOffset(IndexedPosition @from, IndexedPosition toPosition) { throw new NotImplementedException(); }
private void AddShapes(IndexedPosition position) { ShapeView.AddShapesToPosition(position); }