public void Update() { playerCoordinate = new Coordinate(Mathf.FloorToInt(player.transform.position.x / CellSize), Mathf.FloorToInt(player.transform.position.y / CellSize)); List <NCell> list = new List <NCell>(); //Debug.Log(playerCoordinate.x + " " + playerCoordinate.y); if (preStartCell.Coordinate.Equals(playerCoordinate)) { //Debug.Log("A"); NCell _startCell = startCell; int pDir = direction; int pPreDir = predirection; NCell pLastCell = lastCell; int localLengthsCount = pathLengths.Count; list = createPath(); //CheckForDistance(startCell, list) || CheckForDistanceBetweenCells(preStartCell, startCell) || CheckForDistance(preStartCell, list) while (CheckForIntersections(list, curPath) || CheckForSelfIntersections(list) || CheckForDistanceBetweenCells(preStartCell, startCell) || CheckForDistance(preStartCell, list)) { //Debug.Log("bSSEECC " + localLengthsCount); RefreshLengths(localLengthsCount); CreateClearData(pLastCell, pDir, pPreDir); list = createPath(); } //Debug.Log("second " + pathLengths[0]); //startCell = lastCell; preStartCell = _startCell; auxiliaryList = curPath; curPath = list; ManifestListOfNCells(curPath); } }
public bool CheckForDistanceBetweenCells(NCell cell1, NCell cell2) { if (Mathf.Abs(cell1.Coordinate.x - cell2.Coordinate.x) < 4 && Mathf.Abs(cell1.Coordinate.y - cell2.Coordinate.y) < 4) { return(true); } return(false); }
public new void Add(NCell item) { if (Data.Count > 0 && (int)Data.First().GetValue(Grid.ColumnProperty) != (int)item.GetValue(Grid.ColumnProperty)) { throw new Exception("加入到集合的元素必须是同一行"); } base.Add(item); }
/// <summary> /// 向当前合并项添加元素 /// </summary> /// <param name="nCell"></param> public void AppendNCell(NCell nCell) { if (nCell==null) { throw new ArgumentNullException(); } nCell.MergeId=Id; nCell.Visibility=Visibility.Collapsed; Data.Add(nCell); }
public bool CheckForDistance(NCell startPoint, List <NCell> list) { //Debug.Log("OOOOOOOOONNNNNNNNNNNNNNEEEEEEEEEEEEEEE"); for (int i = 0; i < list.Count; i++) { //Debug.Log("strartpoint: " + startPoint.Coordinate.x + " " + startPoint.Coordinate.y); //Debug.Log("list i : " + list[i].Coordinate.x + " " + list[i].Coordinate.y); if (Mathf.Abs(list[i].Coordinate.x - startPoint.Coordinate.x) < cellWidth / 2 && Mathf.Abs(list[i].Coordinate.y - startPoint.Coordinate.y) < cellHeight / 2) { return(true); } } return(false); }
public void Start() { instance = gameObject; GameObject virtualScreenQuad = GameObject.Find("Virtual Screen Quad"); screenHeight = virtualScreenQuad.transform.localScale.y; screenWidth = virtualScreenQuad.transform.localScale.x; player = GameObject.FindGameObjectWithTag("Player"); GameObject cell1 = PoolScript.instance.GetObjectFromPool("Cell", Vector3.zero, Quaternion.Euler(0, 0, 0)); CellSize = cell1.GetComponent <BoxCollider2D>().size.x; PoolScript.instance.ReturnObjectToPool(cell1); cellWidth = Mathf.FloorToInt(screenWidth / CellSize) + 1; cellHeight = Mathf.FloorToInt(screenHeight / CellSize) + 1; preStartCell = new NCell(1, 0, true); lastCell = new NCell(0, 0, false); cells.Add(lastCell); cells.Add(preStartCell); lastCell.Manifest(); preStartCell.Manifest(); pathLengths.Add(new Vector2(lastCell.Position.x + CellSize / 2, lastCell.Position.y)); int pDir = direction; int pPreDir = predirection; NCell pLastCell = lastCell; int localLengthsCount = pathLengths.Count; curPath = createPath(); while (CheckForSelfIntersections(curPath) || CheckForDistanceBetweenCells(preStartCell, startCell)) { //Debug.Log("pathLENGTH " + pathLengths.Count); RefreshLengths(localLengthsCount); CreateClearData(pLastCell, pDir, pPreDir); curPath = createPath(); } //Debug.Log("first " + pathLengths[0]); ManifestListOfNCells(curPath); curPath.Add(preStartCell); }
public static NCell FindCell(Coordinate coord, List <NCell> cells) { NCell outCell = null; //Debug.Log(cells.Count); foreach (NCell cell in cells) { if (cell.Coordinate.Equals(coord)) { outCell = cell; } } if (outCell != null) { return(outCell); } else { return(null); } }
/// <summary> /// 重置NTable /// </summary> private void ResetNTable() { NCellContainer.Children.Clear(); NCellContainer.RowDefinitions.Clear(); NCellContainer.ColumnDefinitions.Clear(); _mouseDownNCell = null; _nTableData.Clear(); ClearSelection(); }
private void OnMouseUp(object sender, MouseButtonEventArgs e) { _mouseDownNCell = null; }
private void NCellMouseMove(object sender, NCellMouseEventArgs args) { if (args.MouseEventArgs.LeftButton == MouseButtonState.Pressed && _mouseDownNCell != null) { var currentNCell = GetNCellFromMousePosition(args.MouseEventArgs.GetPosition(this)); if (currentNCell != null && !currentNCell.Equals(_mouseDownNCell) && !currentNCell.Equals(_lastMouseOverNCell)) { var mouseDownNCellRow = (int)_mouseDownNCell.GetValue(Grid.RowProperty); var mouseDownNCellColumn = (int)_mouseDownNCell.GetValue(Grid.ColumnProperty); var currentNCellRow = (int)currentNCell.GetValue(Grid.RowProperty); var currentNCellColumn = (int)currentNCell.GetValue(Grid.ColumnProperty); //计算绘制选中效果的矩形区域的起始点 Point startPoint, endPoint; if (currentNCellRow >= mouseDownNCellRow) { if (currentNCellColumn >= mouseDownNCellColumn) { startPoint = _mouseDownNCell.TranslatePoint(new Point(), NCellContainer); endPoint = currentNCell.TranslatePoint(new Point(currentNCell.ActualWidth, currentNCell.ActualHeight), NCellContainer); } else { startPoint = _mouseDownNCell.TranslatePoint(new Point(_mouseDownNCell.ActualWidth, 0), NCellContainer); endPoint = currentNCell.TranslatePoint(new Point(0, currentNCell.ActualHeight), NCellContainer); } } else { if (currentNCellColumn >= mouseDownNCellColumn) { startPoint = _mouseDownNCell.TranslatePoint(new Point(0, _mouseDownNCell.ActualHeight), NCellContainer); endPoint = currentNCell.TranslatePoint(new Point(currentNCell.ActualWidth, 0), NCellContainer); } else { startPoint = _mouseDownNCell.TranslatePoint(new Point(_mouseDownNCell.ActualWidth, _mouseDownNCell.ActualHeight), NCellContainer); endPoint = currentNCell.TranslatePoint(new Point(0, 0), NCellContainer); } } //设置选中效果 var leftMargin = Math.Min(startPoint.X, endPoint.X); var topMargin = Math.Min(startPoint.Y, endPoint.Y); _effectBorder = new Border() { BorderThickness = new Thickness(2), BorderBrush = Brushes.Blue }; _effectBorder.SetValue(Canvas.LeftProperty, leftMargin); _effectBorder.SetValue(Canvas.TopProperty, topMargin); _effectBorder.Width = Math.Abs(startPoint.X - endPoint.X); _effectBorder.Height = Math.Abs(startPoint.Y - endPoint.Y); _effectBorder.Background = Brushes.SkyBlue; _effectBorder.Opacity = 0.3; //当合并项处于选中边界时 var selectedRect = NTableUtils.BuildRect(startPoint, endPoint); //标识经过合并项的处理,选中区域是否已改变,若已改变则重新扫描,是否有合并项处于边界 bool isSelectionRectChanged; do { isSelectionRectChanged = false; foreach (var mergeItem in _nTableData.MergeCollection) { var mergeItemRect = NTableUtils.TranslateBounds(mergeItem.RootNCell, NCellContainer); if (NTableUtils.IsRectIntersect(selectedRect, mergeItemRect)) { if (mergeItemRect.Y < selectedRect.Y) { _effectBorder.SetValue(Canvas.TopProperty, mergeItemRect.Y); _effectBorder.Height += selectedRect.Y - mergeItemRect.Y; } if (mergeItemRect.X < selectedRect.X) { _effectBorder.SetValue(Canvas.LeftProperty, mergeItemRect.X); _effectBorder.Width += selectedRect.X - mergeItemRect.X; } if (mergeItemRect.Right > selectedRect.Right) { _effectBorder.Width += mergeItemRect.Right - selectedRect.Right; } if (mergeItemRect.Bottom > selectedRect.Bottom) { _effectBorder.Height += mergeItemRect.Bottom - selectedRect.Bottom; } var newSelectionRect = new Rect((double)_effectBorder.GetValue(Canvas.LeftProperty), (double)_effectBorder.GetValue(Canvas.TopProperty), _effectBorder.Width, _effectBorder.Height); if (newSelectionRect != selectedRect) { selectedRect = newSelectionRect; isSelectionRectChanged = true; } } } } while (isSelectionRectChanged); //实时更新选中的单元格集合 _selectedNCells.Clear(); var rows = _nTableData.Rows.Count; var columns = _nTableData.Columns.Count; for (var i = 0; i < rows; i++) { for (var j = 0; j < columns; j++) { if (NTableUtils.IsRectIntersect(NTableUtils.TranslateBounds((FrameworkElement)NCellContainer.Children[i * columns + j], NCellContainer), selectedRect)) { _selectedNCells.Add((NCell)NCellContainer.Children[i * columns + j]); } } } for (var i = 0; i < _selectedNCells.Count; i++) { if (_selectedNCells[i].MergeId != Guid.Empty) { var mergeItem = _nTableData.MergeCollection.First(x => x.Id == _selectedNCells[i].MergeId); mergeItem.ToList().ForEach(x => { if (!_selectedNCells.Contains(x)) { _selectedNCells.Add(x); } }); } } ClearSelection(); EffectContainer.Children.Add(_effectBorder); } _lastMouseOverNCell = currentNCell; } }
private void NCellMouseLeftDown(object sender, NCellMouseEventArgs args) { _mouseDownNCell = GetNCellFromMousePosition(args.MouseEventArgs.GetPosition(this)); ClearSelection(); }
private void NCellLostKeyboardFocus(object sender, RoutedEventArgs e) { _keyboardFocusedNCell = null; }
private void InsertRight_OnClick(object sender, RoutedEventArgs e) { if (_keyboardFocusedNCell == null) return; var rowCount = _nTableData.Rows.Count; var currentColumn = 0; //如果当前操作元素是合并项 if (_keyboardFocusedNCell.MergeId != Guid.Empty) { var rightBottomNCell = _nTableData.MergeCollection.First(x => x.Id == _keyboardFocusedNCell.MergeId).GetRightBottomNCell(); currentColumn = (int)rightBottomNCell.GetValue(Grid.ColumnProperty); } else { currentColumn = (int)_keyboardFocusedNCell.GetValue(Grid.ColumnProperty); } NCellContainer.ColumnDefinitions.Insert(currentColumn, new ColumnDefinition() { Width = new GridLength(_nTableData.NCellDefaultWidth) }); for (var i = currentColumn + 1; i < _nTableData.Columns.Count; i++) { _nTableData.Columns[i].ToList().ForEach(x => x.SetValue(Grid.ColumnProperty, (int)x.GetValue(Grid.ColumnProperty) + 1)); } //如果当前列中有合并项,并且当前列不是合并项的最后一列,则修改合并项的根单元格的ColumnSpan var currentRowMergeItem = _nTableData.MergeCollection.Where(x => _nTableData.Columns[currentColumn].Any(y => y.MergeId == x.Id)); currentRowMergeItem.ToList().ForEach(x => { if ((int)x.GetRightBottomNCell().GetValue(Grid.ColumnProperty) > currentColumn) { x.RootNCell.SetValue(Grid.ColumnSpanProperty, ((int)x.RootNCell.GetValue(Grid.ColumnSpanProperty) + 1)); } }); NCellContainer.Width += _nTableData.NCellDefaultWidth; var newColumn = new NTableColumn(); for (var i = 0; i < rowCount; i++) { var newNCell = new NCell { Background = Brushes.DarkGray }; newNCell.SetValue(Grid.RowProperty, i); newNCell.SetValue(Grid.ColumnProperty, currentColumn + 1); //将处于合并项的单元格加到合并项中 if (_nTableData.Columns[currentColumn][i].Visibility == Visibility.Collapsed || _nTableData.MergeCollection.Any(x => x.RootNCell.Equals(_nTableData.Columns[currentColumn][i]))) { var nCell = _nTableData.MergeCollection.First(x => x.Id == _nTableData.Columns[currentColumn][i].MergeId).GetRightBottomNCell(); if ((int)nCell.GetValue(Grid.ColumnProperty) > currentColumn) { _nTableData.MergeCollection.First(x => x.Id == _nTableData.Columns[currentColumn][i].MergeId).AppendNCell(newNCell); } } NCellContainer.Children.Add(newNCell); _nTableData.Rows[i].Insert(currentColumn + 1, newNCell); newColumn.Add(newNCell); } _nTableData.Columns.Insert(currentColumn + 1, newColumn); }
private void EffectContainerOnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { _mouseDownNCell = GetNCellFromMousePosition(e.GetPosition(this)); ClearSelection(); }
public void CreateClearData(NCell pLastNCell, int pDir, int pPreDir) { lastCell = pLastNCell; predirection = pPreDir; direction = pDir; }
private void Build_OnClick(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(RowInput.Text) || string.IsNullOrEmpty(ColumnInput.Text)) { MessageBox.Show("输入点儿东西撒"); return; }; var rows = int.Parse(RowInput.Text); var columns = int.Parse(ColumnInput.Text); ResetNTable(); for (int i = 0; i < rows; i++) { var rowDef = new RowDefinition() { Height = new GridLength(_nTableData.NCellDefaultHeight) }; NCellContainer.RowDefinitions.Add(rowDef); } var columnDefaultWidth = _nTableData.NTableDefaultWidth / columns; _nTableData.NCellDefaultWidth = columnDefaultWidth; for (int i = 0; i < columns; i++) { var columnDef = new NTabelColumnDefinition(){ Width = new GridLength(columnDefaultWidth) }; NCellContainer.ColumnDefinitions.Add(columnDef); var thumb = new Thumb(); var rd = new ResourceDictionary { Source = new Uri("pack://application:,,,/NTable.Core;component/Themes/Common.xaml") }; thumb.Style = (Style)rd["DragThumbVerStyle"]; thumb.SetValue(Grid.ColumnProperty,i); thumb.HorizontalAlignment=HorizontalAlignment.Right; NCellContainer.Children.Add(thumb); } for (var i = 0; i < rows; i++) { var row = new NTableRow(); for (var j = 0; j < columns; j++) { var nCell = new NCell { Content = i + "," + j }; nCell.SetValue(Grid.RowProperty, i); nCell.SetValue(Grid.ColumnProperty, j); NCellContainer.Children.Add(nCell); row.Add(nCell); } _nTableData.Rows.Add(row); } for (var i = 0; i < columns; i++) { var nCellCollection = new NTableColumn(); for (var j = 0; j < rows; j++) { nCellCollection.Add((NCell)NCellContainer.Children[j * columns + i]); } _nTableData.Columns.Add(nCellCollection); } }
/// <summary> /// 删除合并项中的行时调整合并项 /// </summary> /// <param name="deletedRow"></param> private void AdjustMergeCollectionBeforeDeleteRow(int deletedRow) { var rootNCellRow = (int)RootNCell.GetValue(Grid.RowProperty); var rootNCellColumn = (int)RootNCell.GetValue(Grid.ColumnProperty); if (rootNCellRow==deletedRow) { //删除已经执行了,所以之前根单元格的位置放置着新单元格 var newRootNCell = _data.Rows[rootNCellRow][rootNCellColumn]; newRootNCell.SetValue(Grid.RowSpanProperty, (int)RootNCell.GetValue(Grid.RowSpanProperty) - 1); newRootNCell.SetValue(Grid.ColumnSpanProperty, (int)RootNCell.GetValue(Grid.ColumnSpanProperty)); newRootNCell.Visibility=Visibility.Visible; RootNCell = newRootNCell; } else { RootNCell.SetValue(Grid.RowSpanProperty, (int)RootNCell.GetValue(Grid.RowSpanProperty) - 1); } if ((int)RootNCell.GetValue(Grid.RowSpanProperty)==1&&(int)RootNCell.GetValue(Grid.ColumnSpanProperty)==1) { _data.MergeCollection.Remove(this); } }
private void InsertTop_OnClick(object sender, RoutedEventArgs e) { if (_keyboardFocusedNCell == null) return; var currentRow = (int)_keyboardFocusedNCell.GetValue(Grid.RowProperty); var columnCount = _nTableData.Columns.Count; NCellContainer.RowDefinitions.Insert(currentRow, new RowDefinition() { Height = new GridLength(_nTableData.NCellDefaultHeight) }); for (var i = currentRow; i < _nTableData.Rows.Count; i++) { _nTableData.Rows[i].ToList().ForEach(x => x.SetValue(Grid.RowProperty, (int)x.GetValue(Grid.RowProperty) + 1)); } //如果当前行中有合并项,则修改合并项的根单元格的RowSpan var currentRowMergeItem = _nTableData.MergeCollection.Where(x => _nTableData.Rows[currentRow].Any(y => y.MergeId == x.Id)); currentRowMergeItem.ToList().ForEach(x => { if ((int)x.GetLeftTopNCell().GetValue(Grid.RowProperty) < currentRow) { x.RootNCell.SetValue(Grid.RowSpanProperty, ((int)x.RootNCell.GetValue(Grid.RowSpanProperty) + 1)); } }); var newRow = new NTableRow(); for (var i = 0; i < columnCount; i++) { var newNCell = new NCell { Background = Brushes.Thistle }; newNCell.SetValue(Grid.RowProperty, currentRow); newNCell.SetValue(Grid.ColumnProperty, i); //将处于合并项的单元格加到合并项中 if (_nTableData.Rows[currentRow][i].Visibility == Visibility.Collapsed || _nTableData.MergeCollection.Any(x => x.RootNCell.Equals(_nTableData.Rows[currentRow][i]))) { var nCell = _nTableData.MergeCollection.First(x => x.Id == _nTableData.Rows[currentRow][i].MergeId).GetLeftTopNCell(); if ((int)nCell.GetValue(Grid.RowProperty) < currentRow) { _nTableData.MergeCollection.First(x => x.Id == _nTableData.Rows[currentRow][i].MergeId).AppendNCell(newNCell); } } NCellContainer.Children.Add(newNCell); _nTableData.Columns[i].Insert(currentRow, newNCell); newRow.Add(newNCell); } _nTableData.Rows.Insert(currentRow, newRow); }
private void NCellGotKeyboardFocus(object sender, RoutedEventArgs e) { _keyboardFocusedNCell = (NCell)e.Source; }
public List <NCell> createPath() { //Debug.Log(lastCell.Coordinate.x + " " + lastCell.Coordinate.y); List <NCell> currentLocalList = new List <NCell>(); int cellCount = 0; while (cellCount < pathLength) { int localLength = DetermineLineLength(); cellCount += localLength; //Debug.Log(direction); switch (direction) { case 1: if (predirection == 4) { while (localLength > 1) { localLength -= 2; currentLocalList.Add(new NCell(lastCell.Coordinate.x + 1, lastCell.Coordinate.y + 1, true)); currentLocalList.Add(new NCell(lastCell.Coordinate.x, lastCell.Coordinate.y + 1, true)); lastCell = FindCell(new Coordinate(lastCell.Coordinate.x + 1, lastCell.Coordinate.y + 1), currentLocalList); } if (localLength == 1) { currentLocalList.Add(new NCell(lastCell.Coordinate.x, lastCell.Coordinate.y + 1, true)); currentLocalList.Add(new NCell(lastCell.Coordinate.x + 1, lastCell.Coordinate.y + 1, false)); lastCell = FindCell(new Coordinate(lastCell.Coordinate.x + 1, lastCell.Coordinate.y + 1), currentLocalList); } else { currentLocalList.Add(new NCell(lastCell.Coordinate.x, lastCell.Coordinate.y + 1, false)); lastCell = FindCell(new Coordinate(lastCell.Coordinate.x, lastCell.Coordinate.y + 1), currentLocalList); } } else { while (localLength > 1) { localLength -= 2; currentLocalList.Add(new NCell(lastCell.Coordinate.x + 1, lastCell.Coordinate.y + 1, true)); currentLocalList.Add(new NCell(lastCell.Coordinate.x + 1, lastCell.Coordinate.y, true)); lastCell = FindCell(new Coordinate(lastCell.Coordinate.x + 1, lastCell.Coordinate.y + 1), currentLocalList); } if (localLength == 1) { currentLocalList.Add(new NCell(lastCell.Coordinate.x + 1, lastCell.Coordinate.y, true)); currentLocalList.Add(new NCell(lastCell.Coordinate.x + 1, lastCell.Coordinate.y + 1, false)); lastCell = FindCell(new Coordinate(lastCell.Coordinate.x + 1, lastCell.Coordinate.y + 1), currentLocalList); } else { currentLocalList.Add(new NCell(lastCell.Coordinate.x + 1, lastCell.Coordinate.y, false)); lastCell = FindCell(new Coordinate(lastCell.Coordinate.x + 1, lastCell.Coordinate.y), currentLocalList); } } break; case 2: if (predirection == 1) { while (localLength > 1) { localLength -= 2; currentLocalList.Add(new NCell(lastCell.Coordinate.x - 1, lastCell.Coordinate.y, true)); currentLocalList.Add(new NCell(lastCell.Coordinate.x - 1, lastCell.Coordinate.y + 1, true)); lastCell = FindCell(new Coordinate(lastCell.Coordinate.x - 1, lastCell.Coordinate.y + 1), currentLocalList); } if (localLength == 1) { currentLocalList.Add(new NCell(lastCell.Coordinate.x - 1, lastCell.Coordinate.y, true)); currentLocalList.Add(new NCell(lastCell.Coordinate.x - 1, lastCell.Coordinate.y + 1, false)); lastCell = FindCell(new Coordinate(lastCell.Coordinate.x - 1, lastCell.Coordinate.y + 1), currentLocalList); } else { currentLocalList.Add(new NCell(lastCell.Coordinate.x - 1, lastCell.Coordinate.y, false)); lastCell = FindCell(new Coordinate(lastCell.Coordinate.x - 1, lastCell.Coordinate.y), currentLocalList); } } else { while (localLength > 1) { localLength -= 2; currentLocalList.Add(new NCell(lastCell.Coordinate.x, lastCell.Coordinate.y + 1, true)); currentLocalList.Add(new NCell(lastCell.Coordinate.x - 1, lastCell.Coordinate.y + 1, true)); lastCell = FindCell(new Coordinate(lastCell.Coordinate.x - 1, lastCell.Coordinate.y + 1), currentLocalList); } if (localLength == 1) { currentLocalList.Add(new NCell(lastCell.Coordinate.x, lastCell.Coordinate.y + 1, true)); currentLocalList.Add(new NCell(lastCell.Coordinate.x - 1, lastCell.Coordinate.y + 1, false)); lastCell = FindCell(new Coordinate(lastCell.Coordinate.x - 1, lastCell.Coordinate.y + 1), currentLocalList); } else { currentLocalList.Add(new NCell(lastCell.Coordinate.x, lastCell.Coordinate.y + 1, false)); lastCell = FindCell(new Coordinate(lastCell.Coordinate.x, lastCell.Coordinate.y + 1), currentLocalList); } } break; case 3: if (predirection == 2) { while (localLength > 1) { localLength -= 2; currentLocalList.Add(new NCell(lastCell.Coordinate.x - 1, lastCell.Coordinate.y - 1, true)); currentLocalList.Add(new NCell(lastCell.Coordinate.x, lastCell.Coordinate.y - 1, true)); lastCell = FindCell(new Coordinate(lastCell.Coordinate.x - 1, lastCell.Coordinate.y - 1), currentLocalList); } if (localLength == 1) { currentLocalList.Add(new NCell(lastCell.Coordinate.x, lastCell.Coordinate.y - 1, true)); currentLocalList.Add(new NCell(lastCell.Coordinate.x - 1, lastCell.Coordinate.y - 1, false)); lastCell = FindCell(new Coordinate(lastCell.Coordinate.x - 1, lastCell.Coordinate.y - 1), currentLocalList); } else { currentLocalList.Add(new NCell(lastCell.Coordinate.x, lastCell.Coordinate.y - 1, false)); lastCell = FindCell(new Coordinate(lastCell.Coordinate.x, lastCell.Coordinate.y - 1), currentLocalList); } } else { while (localLength > 1) { localLength -= 2; currentLocalList.Add(new NCell(lastCell.Coordinate.x - 1, lastCell.Coordinate.y, true)); currentLocalList.Add(new NCell(lastCell.Coordinate.x - 1, lastCell.Coordinate.y - 1, true)); lastCell = FindCell(new Coordinate(lastCell.Coordinate.x - 1, lastCell.Coordinate.y - 1), currentLocalList); } if (localLength == 1) { currentLocalList.Add(new NCell(lastCell.Coordinate.x - 1, lastCell.Coordinate.y, true)); currentLocalList.Add(new NCell(lastCell.Coordinate.x - 1, lastCell.Coordinate.y - 1, false)); lastCell = FindCell(new Coordinate(lastCell.Coordinate.x - 1, lastCell.Coordinate.y - 1), currentLocalList); } else { currentLocalList.Add(new NCell(lastCell.Coordinate.x - 1, lastCell.Coordinate.y, false)); lastCell = FindCell(new Coordinate(lastCell.Coordinate.x - 1, lastCell.Coordinate.y), currentLocalList); } } break; case 4: if (predirection == 3) { while (localLength > 1) { localLength -= 2; currentLocalList.Add(new NCell(lastCell.Coordinate.x + 1, lastCell.Coordinate.y - 1, true)); currentLocalList.Add(new NCell(lastCell.Coordinate.x + 1, lastCell.Coordinate.y, true)); lastCell = FindCell(new Coordinate(lastCell.Coordinate.x + 1, lastCell.Coordinate.y - 1), currentLocalList); } if (localLength == 1) { currentLocalList.Add(new NCell(lastCell.Coordinate.x + 1, lastCell.Coordinate.y, true)); currentLocalList.Add(new NCell(lastCell.Coordinate.x + 1, lastCell.Coordinate.y - 1, false)); lastCell = FindCell(new Coordinate(lastCell.Coordinate.x + 1, lastCell.Coordinate.y - 1), currentLocalList); } else { currentLocalList.Add(new NCell(lastCell.Coordinate.x + 1, lastCell.Coordinate.y, false)); lastCell = FindCell(new Coordinate(lastCell.Coordinate.x + 1, lastCell.Coordinate.y), currentLocalList); } } else { while (localLength > 1) { localLength -= 2; currentLocalList.Add(new NCell(lastCell.Coordinate.x + 1, lastCell.Coordinate.y - 1, true)); currentLocalList.Add(new NCell(lastCell.Coordinate.x, lastCell.Coordinate.y - 1, true)); lastCell = FindCell(new Coordinate(lastCell.Coordinate.x + 1, lastCell.Coordinate.y - 1), currentLocalList); } if (localLength == 1) { currentLocalList.Add(new NCell(lastCell.Coordinate.x + 1, lastCell.Coordinate.y - 1, false)); currentLocalList.Add(new NCell(lastCell.Coordinate.x, lastCell.Coordinate.y - 1, true)); lastCell = FindCell(new Coordinate(lastCell.Coordinate.x + 1, lastCell.Coordinate.y - 1), currentLocalList); } else { currentLocalList.Add(new NCell(lastCell.Coordinate.x, lastCell.Coordinate.y - 1, false)); lastCell = FindCell(new Coordinate(lastCell.Coordinate.x, lastCell.Coordinate.y - 1), currentLocalList); } } break; } int _dir = direction; if ((direction == 1 && localLength % 2 == 1 && predirection == 4) || (direction == 1 && localLength % 2 == 0 && predirection == 2) || (direction == 3 && localLength % 2 == 0 && predirection == 2) || (direction == 3 && localLength % 2 == 1 && predirection == 4)) { direction = 2; } else if ((direction == 1 && localLength % 2 == 0 && predirection == 4) || (direction == 1 && localLength % 2 == 1 && predirection == 2) || (direction == 3 && localLength % 2 == 1 && predirection == 2) || (direction == 3 && localLength % 2 == 0 && predirection == 4)) { direction = 4; } else if ((direction == 2 && localLength % 2 == 1 && predirection == 3) || (direction == 2 && localLength % 2 == 0 && predirection == 1) || (direction == 4 && localLength % 2 == 1 && predirection == 3) || (direction == 4 && localLength % 2 == 0 && predirection == 1)) { direction = 1; } else if ((direction == 2 && localLength % 2 == 1 && predirection == 1) || (direction == 2 && localLength % 2 == 0 && predirection == 3) || (direction == 4 && localLength % 2 == 1 && predirection == 1) || (direction == 4 && localLength % 2 == 0 && predirection == 3)) { direction = 3; } predirection = _dir; if (predirection == 3 && direction == 4 || predirection == 2 && direction == 1) { startCell = FindCell(new Coordinate(lastCell.Coordinate.x + 1, lastCell.Coordinate.y), currentLocalList); } if (predirection == 3 && direction == 2 || predirection == 4 && direction == 1) { startCell = FindCell(new Coordinate(lastCell.Coordinate.x, lastCell.Coordinate.y + 1), currentLocalList); } if (predirection == 4 && direction == 3 || predirection == 1 && direction == 2) { startCell = FindCell(new Coordinate(lastCell.Coordinate.x - 1, lastCell.Coordinate.y), currentLocalList); } if (predirection == 1 && direction == 4 || predirection == 2 && direction == 3) { startCell = FindCell(new Coordinate(lastCell.Coordinate.x, lastCell.Coordinate.y - 1), currentLocalList); } //Debug.Log("added: " + lastCell.Position + " " + startCell.Position); pathLengths.Add((lastCell.Position + startCell.Position) / 2); } return(currentLocalList); }