コード例 #1
0
    static Vector2[] GetPath(InternalBuildingNode endObject)
    {
        InternalBuildingNode currentObject = endObject;

        Vector2[] returnPath = new Vector2[GetPathLength(endObject)];
        int       index      = 0;

        while (currentObject.HasFakeParent() && index < 10000)
        {
            Debug.DrawLine(currentObject.position3, currentObject.GetFakeParent().position3, Color.red, 10f);
            returnPath[index] = currentObject.position2;
            currentObject     = currentObject.GetFakeParent();
            //print("index = " + index + " and pos = " + returnPath[index]);
            index++;
        }

        if (index > 9990)
        {
            print("failed to get path, while loop crash!");
        }


//      print("index length = " + index + " and array length = " + GetPathLength(endObject));


        return(returnPath);
    }
コード例 #2
0
//
//
//function GetPathLength(curNode : Node) : int {
//	if (curNode.fakeParent == null) {
//		return 0;
//	} else {
//		return 1 + GetPathLength(curNode.fakeParent);
//	}
//}
//

/**
 *	Generic return path function
 */
    static Vector2[] GeneratePath(InternalBuildingNode endObject, Dictionary <int, InternalBuildingNode> openList)
    {
        int index = 0;
        InternalBuildingNode curObject = endObject;
        bool loopEnabled = true;

        Vector3[] waypoints = new Vector3[1024];

        // add position of first cell, then look if that cell has a fakeParent
        // if so, increase index and add in next loop to list
        // otherwise, stop loop
        while (loopEnabled)
        {
            //print ("index = " + index + " and size = " + openList.Count);
            waypoints[index] = curObject.position3;

            if (curObject.HasFakeParent())
            {
                curObject = curObject.GetFakeParent();
                index++;
            }
            else
            {
                loopEnabled = false;
            }

            // while loop protection
            if (index > 999999)
            {
                loopEnabled = false;
                print("while loop crash");
            }
        }

        // create returnable list with correct size and add end position at start
        Vector2[] return_waypoints = new Vector2[index + 1];
        //return_waypoints [0] = new Vector2(endPosition.x, endPosition.z);

        for (int i = 0; i < return_waypoints.Length; i++)
        {
            return_waypoints[i] = new Vector2(waypoints[i].x, waypoints[i].z);
        }


        if (debugging)
        {
            //DrawPath(return_waypoints, 0.2f);
        }

        return(return_waypoints);
    }
コード例 #3
0
    static int GetPathLength(InternalBuildingNode endObject)
    {
        int counter = 0;
        InternalBuildingNode currentObject = endObject;

        while (currentObject.HasFakeParent() && counter < 10000)
        {
            currentObject = currentObject.GetFakeParent();
            counter++;
        }

        if (counter > 9990)
        {
            print("failed to get path, while loop crash!");
        }

        return(counter);
    }
コード例 #4
0
    static float CalculateG(InternalBuildingNode curObject)
    {
        float newG = 0;

        if (!curObject.HasFakeParent())           // gridCell.ultimateParent

        {
            print("problems!!!");
            return(-999);

            // if there is a parent
        }
        else
        {
            // check if connection is straight or diagonal (ID's because of performance issues)
            newG = (HORIZONTAL_VERTICAL_COST * curObject.GetGCostMultiplier()) + curObject.GetFakeParent().GetGCost();

            curObject.SetGCost(newG);
            return(newG);
        }
    }
コード例 #5
0
    static float CalculateG(InternalBuildingNode curObject)
    {
        float newG = 0;

        if (!curObject.HasFakeParent()) { // gridCell.ultimateParent

            print("problems!!!");
            return -999;

        // if there is a parent
        } else {

            // check if connection is straight or diagonal (ID's because of performance issues)
            newG = (HORIZONTAL_VERTICAL_COST * curObject.GetGCostMultiplier())+ curObject.GetFakeParent().GetGCost();

            curObject.SetGCost(newG);
            return newG;

        }
    }