当前位置: 首页>>代码示例>>C#>>正文


C# Pathfinding.Node类代码示例

本文整理汇总了C#中Pathfinding.Node的典型用法代码示例。如果您正苦于以下问题:C# Node类的具体用法?C# Node怎么用?C# Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Node类属于Pathfinding命名空间,在下文中一共展示了Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateNodes

		/// <summary>
		/// Creates a number of nodes with the correct type for the graph.
		/// </summary>
		/// <remarks>Called by graph generators and when deserializing a graph with nodes.
		/// Override this function if you do not use the default <see cref="Node"/> class.</remarks>
		/// <param name="number">
		/// A <see cref="System.Int32"/>
		/// </param>
		/// <returns>
		/// A <see cref="Node[]"/>
		/// </returns>
		public virtual Node[] CreateNodes (int number) {
			Node[] tmp = new Node[number];
			for (int i=0;i<number;i++) {
				tmp[i] = new Node ();
			}
			return tmp;
		}
开发者ID:pravusjif,项目名称:PravusUnityTests,代码行数:18,代码来源:Base.cs

示例2: Grid

        public Grid(int row, int column)
        {
            this.random = new Random();

            this.Row = row;
            this.Column = column;
            matrizNodes = new Node[this.Row,this.Column];
            Nodes = new Node[this.Row * this.Column];

            for (var i = 0; i < this.Row; i++)
            {
                for (var j = 0; j < this.Column; j++)
                {
                    Nodes[i * this.Column + j] = new Node(i, j);
                }
            }
            for (int x = 0; x < matrizNodes.GetLength(0); x++)
            {
                for (int y = 0; y < matrizNodes.GetLength(1); y++)
                {
                    var index = x * matrizNodes.GetLength(1) + y;
                    matrizNodes[x, y] = Nodes[index];
                }
            }
        }
开发者ID:Nuno-Duarte,项目名称:Pathfinding--XNA-C-,代码行数:25,代码来源:Grid.cs

示例3: CreateNodes

		/** Creates a number of nodes with the correct type for the graph.
		This should not set the #nodes array, only return the nodes.
		Called by graph generators and when deserializing a graph with nodes.
		Override this function if you do not use the default Pathfinding.Node class.
		*/
		public virtual Node[] CreateNodes (int number) {
			Node[] tmp = new Node[number];
			for (int i=0;i<number;i++) {
				tmp[i] = new Node ();
				tmp[i].penalty = initialPenalty;
			}
			return tmp;
		}
开发者ID:JustSAT,项目名称:Tower-Defence,代码行数:13,代码来源:Base.cs

示例4: GetNearest

        /// <summary>
        /// This will be called on the same time as Awake on the gameObject which the AstarPath script is attached to. (remember, not in the editor)
        /// Use this for any initialization code which can't be placed in Scan
        /// </summary>
        //public override void Awake() {
        //    base.Awake();
        //}


        // IMPROVE not really necessary. I just override this NavGraph method to add the debug line at the bottom. Otherwise its identical
        public override NNInfo GetNearest(Vector3 position, NNConstraint constraint, Node hint) {

            if (nodes == null) {
                return new NNInfo();
            }

            float maxDistSqr = constraint.constrainDistance ? AstarPath.active.maxNearestNodeDistanceSqr : float.PositiveInfinity;

            float minDist = float.PositiveInfinity;
            Node minNode = null;

            float minConstDist = float.PositiveInfinity;
            Node minConstNode = null;

            for (int i = 0; i < nodes.Length; i++) {

                Node node = nodes[i];
                float dist = (position - (Vector3)node.position).sqrMagnitude;

                if (dist < minDist) {
                    minDist = dist;
                    minNode = node;
                }

                if (dist < minConstDist && dist < maxDistSqr && constraint.Suitable(node)) {
                    minConstDist = dist;
                    minConstNode = node;
                }
            }

            NNInfo nnInfo = new NNInfo(minNode);

            nnInfo.constrainedNode = minConstNode;

            if (minConstNode != null) {
                nnInfo.constClampedPosition = (Vector3)minConstNode.position;
            }
            else if (minNode != null) {
                nnInfo.constrainedNode = minNode;
                nnInfo.constClampedPosition = (Vector3)minNode.position;
            }

            #region Debugging

            if (nnInfo.constrainedNode == null) {
                float closestDistance;
                Node closestNode = __FindClosestNode(position, out closestDistance);
                D.Warn("Can't find node close enough to {0}. ClosestNode is {1} away.", position, closestDistance);
            }
            else {
                D.Log("Closest Node is at {0}, {1} from {2}.", (Vector3)nnInfo.constrainedNode.position, Mathf.Sqrt(minDist), position);
            }

            //D.Log("GetNearest() constraint.Suitable = {0}.", constraint.Suitable(nnInfo.node));
            #endregion

            return nnInfo;
        }
开发者ID:Maxii,项目名称:UnityEntry,代码行数:68,代码来源:MyAStarPointGenerator.cs

示例5: UpdateGraphsNoBlock

		/** Updates graphs and checks if all nodes are still reachable from each other.
		 * Graphs are updated, then a check is made to see if the nodes are still reachable from each other.
		 * If they are not, the graphs are reverted to before the update and \a false is returned.\n
		 * This is slower than a normal graph update.
		 * All queued graph updates and thread safe callbacks will be flushed during this function.
		 * 
		 * \note This might return true for small areas even if there is no possible path if AstarPath.minAreaSize is greater than zero (0).
		 * So when using this, it is recommended to set AstarPath.minAreaSize to 0 (A* Inspector -> Settings -> Pathfinding)
		 * 
		 * \param guo The GraphUpdateObject to update the graphs with
		 * \param node1 Node which should have a valid path to \a node2. All nodes should be walkable or \a false will be returned.
		 * \param node2 Node which should have a valid path to \a node1. All nodes should be walkable or \a false will be returned.
		 * \param alwaysRevert If true, reverts the graphs to the old state even if no blocking ocurred
		 */
		public static bool UpdateGraphsNoBlock (GraphUpdateObject guo, Node node1, Node node2, bool alwaysRevert = false) {
			List<Node> buffer = ListPool<Node>.Claim ();
			buffer.Add (node1);
			buffer.Add (node2);
			
			bool worked = UpdateGraphsNoBlock (guo,buffer, alwaysRevert);
			ListPool<Node>.Release (buffer);
			return worked;
		}
开发者ID:JustSAT,项目名称:Tower-Defence,代码行数:23,代码来源:GraphUpdateUtilities.cs

示例6: DrawPath

        public void DrawPath(Node goal,ref Grid grid,ref Tree[] _trees)
        {
            Point startingPoint = StateToPoint(nodeState.ORIGIN);

            int pointX = startingPoint.X;
            int pointY = startingPoint.Y;

            path.Add(origin);

            if (pointX == -1 && pointY == -1)
            {
                return;
            }

            while (true)
            {

                Point lowestPoint = Point.Zero;
                int lowest = 10000;

                foreach (Point movePoint in CheckStep(pointX, pointY))
                {
                    int count = _squares[movePoint.X, movePoint.Y].distanceSteps;
                    if (count < lowest)
                    {
                        lowest = count;
                        lowestPoint.X = movePoint.X;
                        lowestPoint.Y = movePoint.Y;
                    }
                }
                if (lowest != 10000)
                {
                    _squares[lowestPoint.X, lowestPoint.Y].hasPath = true;
                    _squares[lowestPoint.X, lowestPoint.Y].ChangeTexture(ImageLibrary.getInstance().getImage("Clear"));
                    path.Add(_squares[lowestPoint.X, lowestPoint.Y]);
                    pointX = lowestPoint.X;
                    pointY = lowestPoint.Y;
                }
                else
                {
                    Search(origin, goal, ref grid, this.game, ref _trees, ref this.path);
                    return;
                }

                if (_squares[pointX, pointY].state == nodeState.GOAL)
                {
                    _squares[pointX, pointY].ChangeTexture(ImageLibrary.getInstance().getImage("Origin"));
                    origin.ChangeTexture(ImageLibrary.getInstance().getImage("Origin"));
                    path.Add(_squares[pointX, pointY]);
                    CreateTrees(ref _trees);
                    break;
                }
            }
        }
开发者ID:manoela-reis,项目名称:computacaonatural-towerdefense,代码行数:54,代码来源:AStar.cs

示例7: CreateMap

        protected void CreateMap(ref bool[,] boolArray)
        {
            this.dimension = new Point(boolArray.GetLength(0), boolArray.GetLength(1));

            map = new Node[dimension.X, dimension.Y];

            for (int x = 0; x < this.dimension.X; x++)
                for (int y = 0; y < this.dimension.Y; y++)
                {
                    map[x, y] = new Node(new Point(x, y), boolArray[x, y], this.start, this.end, this.distanceType);
                }
        }
开发者ID:MaxPlay,项目名称:GameEngine,代码行数:12,代码来源:BoolAStar.cs

示例8: Node

        public Node(int i, int j, int x = 0, int y = 0, int w = 50, int h = 50, Node father = null)
        {
            I = i;
            J = j;

            W = w;
            H = h;

            X = W + I * W + I;
            Y = H + J * H + J;

            Father = father;
        }
开发者ID:Nuno-Duarte,项目名称:Pathfinding--XNA-C-,代码行数:13,代码来源:Node.cs

示例9: Character

        public Character(Game game, Vector3 scale, Vector3 rotation, Vector3 position, Texture2D texture, Camera camera, Node target)
        {
            this.scale = scale;
            this.target = target;
            this.camera = camera;
            this.world = Matrix.CreateScale(scale) * Matrix.CreateFromYawPitchRoll(rotation.Y, rotation.X, rotation.Z) * Matrix.CreateTranslation(position);
            this.position = position;
            this.rotation = rotation;
            this.texture = texture;

            Vector3[] _verts = new Vector3[]
            {
                new Vector3(-1, 0, -1),
                new Vector3(-1, 0, 1),
                new Vector3(1, 0, -1),
                new Vector3(1,0,1)

            };

            int[] triangles = new int[]
            {
                0,1,2,
                2,1,3
            };

            Vector2[] uv = new Vector2[]
            {
                new Vector2(0, 0),
                new Vector2(0, 1),
                new Vector2(1, 0),

                new Vector2(1,0),
                new Vector2(0, 1),
                new Vector2(1, 1)
            };

            int[] trianglesuv = new int[]
            {
                0,1,2,
                3,4,5
            };

            ConvertMesh myMesh = new ConvertMesh();
            verts = myMesh.returnTriangle(_verts, triangles, uv, trianglesuv);

            vertexBuffer = new VertexBuffer(game.GraphicsDevice, typeof(VertexPositionTexture), verts.Length, BufferUsage.None);
            vertexBuffer.SetData<VertexPositionTexture>(verts);

            effect = new BasicEffect(game.GraphicsDevice);
        }
开发者ID:manoela-reis,项目名称:computacaonatural-towerdefense,代码行数:50,代码来源:Character.cs

示例10: GetDistance

        public static int GetDistance(Node from, Node to)
        {
            int distX = Mathf.Abs(from.gridPos.x - to.gridPos.x);
            int distY = Mathf.Abs(from.gridPos.y - to.gridPos.y);

            if (distX > distY)
            {
                return 14 * distY + 10 * (distX - distY);
            }
            else
            {
                return 14 * distX + 10 * (distY - distX);
            }
        }
开发者ID:xCosmix,项目名称:Random_Project,代码行数:14,代码来源:Grid.cs

示例11: AddLayers

        /** Increases the capacity of the nodes array to hold more layers.
          * After this function has been called and new nodes have been set up, the AstarPath.DataUpdate function must be called.
          */
        public void AddLayers(int count)
        {
            int newLayerCount = layerCount + count;

            if (newLayerCount > LevelGridNode.MaxLayerCount) {
                Debug.LogError ("Too many layers, a maximum of LevelGridNode.MaxLayerCount are allowed (required "+newLayerCount+")");
                return;
            }

            Node[] tmp = nodes;
            nodes = new Node[width*depth*newLayerCount];
            for (int i=0;i<tmp.Length;i++) nodes[i] = tmp[i];
            layerCount = newLayerCount;
        }
开发者ID:paillardf,项目名称:RV01_WALL,代码行数:17,代码来源:LayerGridGraphGenerator.cs

示例12: Raffle

        public void Raffle(ref List<Node> list, Node origem, Node destino)
        {
            list.Clear();
            for (int i = 0; i < matrizNodes.GetLength(0); i++)
            {
                for (int j = 0; j < matrizNodes.GetLength(1); j++)
                {
                    matrizNodes[i, j].EstadoNode = EstadoNode.nenhum;
                    matrizNodes[i, j].IsPath = false;
                    matrizNodes[i, j].DistanciaPassos = 10000;

                }
            }
            for (int i = 0; i < matrizNodes.GetLength(0); i++)
            {
                for (int j = 0; j < matrizNodes.GetLength(1); j++)
                {

                    matrizNodes[i, j].EstadoNode = EstadoNode.nenhum;

                    if (matrizNodes[i,j] == origem)
                    {
                        matrizNodes[i, j].EstadoNode = EstadoNode.origem;
                    }
                    else if (matrizNodes[i, j] == destino)
                    {
                        matrizNodes[i, j].EstadoNode = EstadoNode.alvo;
                    }
                }
            }
            for (var i = 0; i < matrizNodes.GetLength(0); i++)
            {
                for (var j = 0; j < matrizNodes.GetLength(1); j++)
                {
                    if (this.random.Next(100) < 30)
                    {
                        var index = j * this.Column + i;
                        if (this.matrizNodes[i,j].EstadoNode != EstadoNode.origem &&
                           this.matrizNodes[i, j].EstadoNode != EstadoNode.alvo)
                        {
                            this.matrizNodes[i, j].EstadoNode = EstadoNode.parede;
                            list.Add(this.matrizNodes[i, j]);
                        }
                    }
                }
            }
        }
开发者ID:Nuno-Duarte,项目名称:Pathfinding--XNA-C-,代码行数:47,代码来源:Grid.cs

示例13: PathfindForOrigin

        public void PathfindForOrigin(Node alvo, ref Grid grid)
        {
            Point pontoInicial = ProcurarNode(alvo.EstadoNode);
            int alvoX = pontoInicial.X;
            int alvoY = pontoInicial.Y;
            if (alvoX == -1 || alvoY == -1)
            {
                return;
            }

            matrizNodes[alvoX, alvoY].DistanciaPassos = 0;

            while (true)
            {
                bool verificando = false;

                foreach (Point pontoAtual in TodosNodes())
                {
                    int x = pontoAtual.X;
                    int y = pontoAtual.Y;

                    if (CampoAberto(x,y))
                    {
                        int andandoAqui = matrizNodes[x, y].DistanciaPassos;

                        foreach (Point pontoDeLocomocao in ValidarMovimentos(x, y))
                        {
                            int nX = pontoDeLocomocao.X;
                            int nY = pontoDeLocomocao.Y;
                            int novoAndar = andandoAqui + 1;

                            if (matrizNodes[nX, nY].DistanciaPassos > novoAndar)
                            {
                                matrizNodes[nX, nY].DistanciaPassos = novoAndar;
                                verificando = true;
                            }
                        }
                    }
                }
                if (!verificando)
                {
                    break;
                }
            }
        }
开发者ID:Nuno-Duarte,项目名称:Pathfinding--XNA-C-,代码行数:45,代码来源:General.cs

示例14: Grid

        public Grid(Game game,Camera mainCamera,int Rows, int Columns)
        {
            this.Rows = Rows;
            this.Columns = Columns;

            nodes = new Node[Rows, Columns];

            for (int x = 0; x < Columns; x++)
            {
                for (int y = 0; y < Rows; y++)
                {
                    float positionX = 1 * x;
                    float positionY = 1 * y;
                    nodes[x, y] = new Node(game, new Vector3(1.25f, 0, 1.25f), new Vector3(0, 0, 0), new Vector3(positionX*2.5f, 0, positionY*2.5f),ImageLibrary.getInstance().getImage("Floor"), mainCamera);
                    nodes[x, y].x = x;
                    nodes[x, y].y = y;
                }
            }
        }
开发者ID:manoela-reis,项目名称:computacaonatural-towerdefense,代码行数:19,代码来源:Grid.cs

示例15: Create

        public static void Create(float nodeRadius, Vector2 worldSize, Vector2 center, LayerMask unwalkableMask)
        {
            Grid.nodeSize = nodeRadius * 2;
            int gridSizeX = Mathf.RoundToInt(worldSize.x / nodeSize);
            int gridSizeY = Mathf.RoundToInt(worldSize.y / nodeSize);
            gridSize = new Coords(gridSizeX, gridSizeY);
            grid = new Node[gridSize.x, gridSize.y];

            Vector2 bottomLeft = center - (Vector2.right * (worldSize.x / 2)) - (Vector2.up * (worldSize.y / 2));

            for (int x = 0; x < gridSize.x; x++)
            {
                for (int y = 0; y < gridSize.y; y++)
                {
                    Vector2 worldPoint = bottomLeft + Vector2.right * (x * nodeSize + nodeRadius) + Vector2.up * (y * nodeSize + nodeRadius);
                    bool walkable = !(Physics2D.OverlapCircle(worldPoint, nodeRadius, unwalkableMask));
                    grid[x, y] = new Node(walkable, worldPoint, x, y);
                }
            }
        }
开发者ID:xCosmix,项目名称:Random_Project,代码行数:20,代码来源:Grid.cs


注:本文中的Pathfinding.Node类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。