GetTotalLength() public méthode

public GetTotalLength ( ) : float
Résultat float
Exemple #1
0
 public void OnPathComplete(Path p)
 {
     if(p.error)
     {
         length = -1.0f;
     }
     else
     {
         length = p.GetTotalLength();
         startSearch();
     }
 }
Exemple #2
0
    //this function is calculate the path length

    public float CalculatePathLength(Vector3 targetPosition)
    {
        // Create a path and set it based on a target position.

        if (agent.enabled)
        {
            return(-1f);
        }

        Pathfinding.Path newPath = GetComponent <Seeker>().StartPath(agent.GetFeetPosition(), targetPosition);


        return(newPath.GetTotalLength());
    }
 static int GetTotalLength(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         Pathfinding.Path obj = (Pathfinding.Path)ToLua.CheckObject <Pathfinding.Path>(L, 1);
         float            o   = obj.GetTotalLength();
         LuaDLL.lua_pushnumber(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Exemple #4
0
 void OnPathCompleted(Path p)
 {
     if (p.error)
     {
         return;
     }
     pathToCursor = p.vectorPath;
     pathToCursorLength = Mathf.Lerp(Vector3.Distance(pathToCursor[0], pathToCursor[pathToCursor.Count - 1]), p.GetTotalLength(), 0.5f);
 }
 private IEnumerator WaitForPathCalculation()
 {
     Debug.Log ("mAttackingObject.transform.position = " + mAttackingObject.transform.position);
     mAStarPath = mSeeker.StartPath(transform.position, mAttackingObject.transform.position, OnPathComplete);
     yield return StartCoroutine (mAStarPath.WaitForPath ());
     //float temppathlength = 0.0f;
     mNearestTargetPathLength = mAStarPath.GetTotalLength ();
     Debug.Log ("mNearestTargetPathLength = " + mNearestTargetPathLength);
     //mAStarPath.Claim (this);
 }
Exemple #6
0
    public void OnPathComplete(Pathfinding.Path p)
    {
        Debug.Log("A path was calculated. Did it fail with an error? " + p.error);

        if (!p.error)
        {
            path = p;
            // Reset the waypoint counter so that we start to move towards the first point in the path
            currentWaypoint = 0;
        }
        // Debug.Log("Get a path: \n" + path);
        // Debug.Log("duration: " + path.heuristic);
        // Debug.Log("duration: " + path.vectorPath);
        // Debug.Log("GetTotalLength: " + path.GetTotalLength());
        // Debug.Log("GetTraversalCost: " + path.GetTraversalCost);
        // Debug.Log("duration: " + path.duration);
        // break;
        // var stream = System.IO.File.CreateText(file_path);
        // var w = new StreamWriter(file_path);

        for (int i = 0; i < path.vectorPath.Count; i++)
        {
            string x = path.vectorPath[i][0].ToString();
            string y = path.vectorPath[i][1].ToString();
            string z = path.vectorPath[i][2].ToString();
            // File.WriteAllText(file_path, path.vectorPath[i][0].ToString());
            // System.IO.File.WriteAllText(file_path, path.vectorPath[i][0].ToString());
            // System.IO.File.AppendAllText(file_path, path.ToString());
            // Debug.Log("path x: " + i + " " + path.vectorPath[i][0].ToString());
            // Debug.Log("path y: " + i + " " + path.vectorPath[i][1].ToString());
            // Debug.Log("path z: " + i + " " + path.vectorPath[i][2].ToString());
            string csvRow = string.Format("{0},{1},{2},{3},{4},{5},\n", i, x, y, z, path.GetTotalLength(), "");
            // stream.WriteLine(csvRow);
            // Debug.Log("Log to file" + i + " " + csvRow);
            // System.IO.File.AppendAllText(file_path, csvRow);
            // System.IO.File.AppendAllLines(file_path, csvRow);
            // Debug.Log("Path info 1: " + path.path.Count);
            // Debug.Log("Path info 2: " + path.searchedNodes());
            // Debug.Log("Path info 3: " + path.GetTotalLength());
            // Debug.Log("Path info 4: " + path.GetTraversalCost());
            // Debug.Log("Path info 5: " + path.GetState());
            // Debug.Log("Path info 6: " + path.GetHTarget());
            // Debug.Log("Path info 7: " + path.duration);
            // Debug.Log("Path info 8: " + path.pathID);
            // Debug.Log("Path info 9: " + path.path);

            // Node
            // if (pathHandler == null) FailWithError("Field pathHandler is not set. Please report this bug.");
            // PathNode nodeR = pathHandler.GetPathNode(path.path[8]);
            // Debug.Log("Path info 9: " + path.path[i].H);
            // Debug.Log("H: " + nodeR.H);

            // Mark nodes to enable special connection costs for start and end nodes
            // See GetConnectionSpecialCost
            // if (startNode != null) pathHandler.GetPathNode(startNode).flag2 = true;
            // if (endNode != null) pathHandler.GetPathNode(endNode).flag2 = true;

            // Zero out the properties on the start node
            // PathNode startRNode = pathHandler.GetPathNode(startNode);
            // startRNode.node = startNode;
            // startRNode.pathID = pathHandler.PathID;
            // startRNode.parent = null;
            // startRNode.cost = 0;
            // startRNode.G = GetTraversalCost(startNode);
            // startRNode.H = CalculateHScore(startNode);
        }

        // pathHandler = new PathHandler(0,0);
        // pathHandler.InitializeForPath(path);
        // Debug.Log("pathHandler: " + pathHandler.PathID);
        // Debug.Log("node: " + pathHandler.GetPathNode(path.path[0]));

        // pathHandler.InitializeForPath(path);
        // System.IO.File.WriteAllText(file_path, csvRow);
        Debug.Log("Path node count: " + path.path.Count);

        for (int j = 0; j < path.path.Count; j++)
        {
            Debug.Log("Path Node index: " + j + " " + path.path[j].NodeIndex);
            Debug.Log("Path Node position: " + j + " " + path.path[j].position);
            Debug.Log("Path Node Penalty: " + j + " " + path.path[j].Penalty);
            Debug.Log("Path Node: " + j + " " + path.path[j]);
            // Debug.Log("Path Node position: " + j + " " + path.path[j].position);

            // pn = pathHandler.GetPathNode(path.path[j].NodeIndex);
            // pn = pathHandler.GetPathNode(path.path[j]);
            // pathHandler.startNode

            // Debug.Log("pathHandler" + pathHandler.threadID);
            // Debug.Log("pathHandler" + pathHandler.totalThreadCount);
            // Debug.Log("pathHandler" + pathHandler.heap);
        }
    }
Exemple #7
0
    /**
     * Callback function that is triggered once the path has been computed for this alien
     **/
    public void OnPathChecked(Path p)
    {
        //Debug.Log ("Yey, we got a path back. Did it have an error? "+p.error);
        if (!p.error) {
            if(p != null) {
                //AstarAI aiMove = gameObject.GetComponent<AstarAI>();
                if(aiPath == null || p.GetTotalLength() < aiPath.GetTotalLength())
                    aiPath = p;
                    finalMarineTarget = currentMarineTarget;
                //unitStatus = UnitStatus.READY_TO_MOVE;
            }
        } else {
            // there was an error
            Debug.Log ("Yey, we got an alien path back but there was an error "+p.error);
        }

        // check the next marine to see if it has a shorter path
        GameObject marines = GameObject.Find("Marines");
        marineCheckCount ++;
        if(marineCheckCount < marines.transform.childCount) {
            ComputePath(gameObject.transform, marines);
        } else if (aiPath != null) {
            // no more marines, to check. lets go with the best one.
            unitStatus = UnitStatus.READY_TO_MOVE;
            Debug.Log("moving to marine= "+finalMarineTarget.name);
        } else {
            unitStatus = UnitStatus.MOVED;
        }
    }
Exemple #8
0
        /// <summary>
        /// Prints info about the nodes of the AstarPath course.
        /// <remarks>The course the fleet follows is actually derived from path.VectorPath rather than path.path's collection
        /// of nodes that are printed here. The Seeker's StartEndModifier determines whether the closest node to the start 
        /// position is included or simply replaced by the exact start position.</remarks>
        /// </summary>
        /// <param name="path">The course.</param>
        private void __ReportPathNodes(Path path) {
            if (path.path.Any()) {
                float startToFirstNodeDistance = Vector3.Distance(Position, (Vector3)path.path[0].position);
                D.Log(ShowDebugLog, "{0}'s Destination is {1} at {2}. Start is {3} with Topography {4}. Distance to first AStar Node: {5:0.#}.",
                    DebugName, ApTarget.DebugName, ApTarget.Position, Position, _fleet.Topography.GetValueName(), startToFirstNodeDistance);
                float cumNodePenalties = 0F;
                string distanceFromPrevNodeMsg = string.Empty;
                GraphNode prevNode = null;
                path.path.ForAll(node => {
                    Vector3 nodePosition = (Vector3)node.position;
                    if (prevNode != null) {
                        distanceFromPrevNodeMsg = ", distanceFromPrevNode {0:0.#}".Inject(Vector3.Distance(nodePosition, (Vector3)prevNode.position));
                    }
                    if (ShowDebugLog) {
                        Topography topographyFromTag = __GetTopographyFromAStarTag(node.Tag);
                        D.Log("{0}'s Node at {1} has Topography {2}, penalty {3}{4}.",
                            DebugName, nodePosition, topographyFromTag.GetValueName(), (int)path.GetTraversalCost(node), distanceFromPrevNodeMsg);
                    }
                    cumNodePenalties += path.GetTraversalCost(node);
                    prevNode = node;
                });
                //float lastNodeToDestDistance = Vector3.Distance((Vector3)prevNode.position, ApTarget.Position);
                //D.Log(ShowDebugLog, "{0}'s distance from last AStar Node to Destination: {1:0.#}.", DebugName, lastNodeToDestDistance);

                if (ShowDebugLog) {
                    // calculate length of path in units scaled by same factor as used in the rest of the system
                    float unitLength = path.GetTotalLength();
                    float lengthCost = unitLength * Int3.Precision;
                    float totalCost = lengthCost + cumNodePenalties;
                    D.Log("{0}'s Path Costs: LengthInUnits = {1:0.#}, LengthCost = {2:0.}, CumNodePenalties = {3:0.}, TotalCost = {4:0.}.",
                        DebugName, unitLength, lengthCost, cumNodePenalties, totalCost);
                }
            }
            else {
                D.Warn("{0}'s course from {1} to {2} at {3} has no AStar Nodes.", DebugName, Position, ApTarget.DebugName, ApTarget.Position);
            }
        }
Exemple #9
0
    private void OnPathingComplete(Path path)
    {
        if (path.error == false)
        {
            if (_path != null)
            {
                _path.Release(this);
            }

            _path = path;
            _path.Claim(this);

            _pathIndex = 0;
            //Update distanec to objective.
            this.DistanceToObjective = _path.GetTotalLength();
        }
    }