Example #1
0
    //adds a node to the graph and returns its index
    public int AddNode(NavGraphNode node)
    {
        if ( node.Index() < nodes_.Count ) {
            //make sure the client is not trying to add a node with the same ID as
            //a currently active node
            //DebugUtils.Assert( nodes_[node.GetIndex()].GetIndex() == NavGraphNode.invalid_node_index, "<NavGraph::AddNode>: Attempting to add a node with a duplicate ID" );
            nodes_[node.Index()] = node;

            return nextNodeIndex_;
          		} else {
            //make sure the new node has been indexed correctly
            DebugUtils.Assert( node.Index() == nextNodeIndex_, "<NavGraph::AddNode>:invalid index" );

            nodes_.Add(node);
            edges_.Add(new List<NavGraphEdge>());

            return nextNodeIndex_++;
          		}
    }
Example #2
0
    //adds a node to the graph and returns its index
    public int AddNode(NavGraphNode node)
    {
        if (node.Index() < nodes_.Count)
        {
            //make sure the client is not trying to add a node with the same ID as
            //a currently active node
            //DebugUtils.Assert( nodes_[node.GetIndex()].GetIndex() == NavGraphNode.invalid_node_index, "<NavGraph::AddNode>: Attempting to add a node with a duplicate ID" );
            nodes_[node.Index()] = node;

            return(nextNodeIndex_);
        }
        else
        {
            //make sure the new node has been indexed correctly
            DebugUtils.Assert(node.Index() == nextNodeIndex_, "<NavGraph::AddNode>:invalid index");

            nodes_.Add(node);
            edges_.Add(new List <NavGraphEdge>());

            return(nextNodeIndex_++);
        }
    }
Example #3
0
    /// </summary>



    public int SearchNonAlloc(Vector3 srcPos, Vector3 destPos, ref Stack <Vector3> pathPos)
    {
        NavGraphNode destNode = _graph.FindNearNode(destPos);
        NavGraphNode srcNode  = _graph.FindNearNode(srcPos);
        NavGraphNode tempNode = null;

        if (null == pathPos)
        {
            return(0);
        }

        if (true == this.PossibleLinearMove(srcPos, destPos, GlobalConstants.Layer.Mask.building))
        {
            if (null != pathPos)
            {
                pathPos.Clear();
                pathPos.Push(destPos);
            }
            return(1);
        }

        _searchDFS.Init(_graph, srcNode.Index(), destNode.Index());
        List <int> pathList = _searchDFS.GetPathToTarget();

        //-------- chamto test --------
//		string nodeChaine = "nodeChaine : ";
//		foreach (int node in pathList)
//		{
//			nodeChaine += node + "<-";
//		}
//		Debug.Log (nodeChaine);
        //-------- ------------ --------


        pathPos.Clear();
        pathPos.Push(destPos);
        foreach (int node in pathList)
        {
            tempNode = _graph.GetNode(node) as NavGraphNode;
            pathPos.Push(tempNode.Pos());
        }
        //pathPos.Push (srcPos);

        return(pathPos.Count);
    }
Example #4
0
    public Stack <Vector3> Search(Vector3 srcPos, Vector3 destPos)
    {
        NavGraphNode    destNode = _graph.FindNearNode(destPos);
        NavGraphNode    srcNode  = _graph.FindNearNode(srcPos);
        NavGraphNode    tempNode = null;
        Stack <Vector3> pathPos  = new Stack <Vector3>();

        if (true == this.PossibleLinearMove(srcPos, destPos, GlobalConstants.Layer.Mask.building))
        {
            pathPos.Push(destPos);
            return(pathPos);
        }

        _searchDFS.Init(_graph, srcNode.Index(), destNode.Index());
        List <int> pathList = _searchDFS.GetPathToTarget();

        //-------- chamto test --------
        string nodeChaine = "nodeChaine : ";

        foreach (int node in pathList)
        {
            nodeChaine += node + "<-";
        }
        Debug.Log(nodeChaine);
        //-------- ------------ --------


        pathPos.Push(destPos);
        foreach (int node in pathList)
        {
            tempNode = _graph.GetNode(node) as NavGraphNode;
            pathPos.Push(tempNode.Pos());
        }
        //pathPos.Push (srcPos);

        return(pathPos);
    }