コード例 #1
0
ファイル: MainGrid.cs プロジェクト: dachidahu/AutoFollow
        public List<GridNode> GetNeighbors(GridNode node, int distance = 1)
        {
            var neighbors = new List<GridNode>();
            if (node == null)
            {
                return neighbors;
            }
            var gridPoint = node.GridPoint;
            if (gridPoint == default(GridPoint)) return neighbors;

            for (var x = gridPoint.X - distance; x <= gridPoint.X + distance; x++)
            {
                if (x < 0 || x > GridMaxX) continue;
                for (var y = gridPoint.Y - distance; y <= gridPoint.Y + distance; y++)
                {
                    if (y < 0 || y > GridMaxY) continue;

                    // Excluding itself
                    if (x == gridPoint.X && y == gridPoint.Y) continue;
                    var gridNode = InnerGrid[x, y];
                    if (gridNode != null)
                    {
                        neighbors.Add(gridNode);
                    }
                }
            }
            return neighbors;
        }
コード例 #2
0
ファイル: GridNode.cs プロジェクト: dachidahu/AutoFollow
        public static GridNode Create(Vector2 center, GridScene gridScene, NavCellDefinition navCell)
        {
            var def = new GridNode
            {
                _center = center,
                Center = center + gridScene.Min,

                _navCellDefinition = navCell,
                _gridScene = gridScene
            };
            return def;
        }