Exemplo n.º 1
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);
    }
Exemplo n.º 2
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);
    }