Beispiel #1
0
    //will add any potential neighbouring nodes to the potential path list if they haven't already, will check to see if the path has reached the goal
    void CalculateNeighbours()
    {
        List <STR_ID> neighbours = currentNode.ReturnNeighbours();

        for (int i = 0; i < neighbours.Count; i++)
        {
            SCR_NodeClass neighbourNode      = nodeManager.ReturnNode(neighbours[i]);
            STR_ID        currentNeighbourID = neighbourNode.returnID();
            STR_ID        currentNodeID      = currentNode.returnID();
            if (currentNodeID.Compare(currentNeighbourID) == false)
            {
                if (listOfNodes.Contains(neighbourNode))
                {
                    if (neighbourNode.ReturnRoomType() != RoomType.BlockedRoute)
                    {
                        var current = new CalculatePath(neighbourNode, currentNode);

                        if (neighbourNode.ReturnRoomType() == RoomType.InitialFightRoom || neighbourNode.ReturnRoomType() == RoomType.ChallangeRoom)
                        {
                            if (!finalPathPoints.Contains(neighbourNode))
                            {
                                closed.Add(current);
                            }
                        }



                        if ((!open.Contains(current)) && (!closed.Contains(current)))
                        {
                            if (CheckOpenList(currentNodeID, currentNeighbourID) == false && CheckClosedList(currentNodeID, currentNeighbourID) == false)
                            {
                                open.Add(current);
                            }
                        }
                    }
                }
            }
        }

        closed.Add(open[currentPos]);

        Vector3 endPos          = goal.returnID().body.transform.position;
        STR_ID  currentID       = currentNode.returnID();
        Vector3 currentPosition = currentNode.returnID().body.transform.position;

        if (currentNode == goal)
        {
            pathfound = true;
            pathEnd   = closed.Count - 1;
        }
        open.Remove(open[currentPos]);
    }
    //draws handles within the map
    private void OnSceneGUI()
    {
        for (int i = 0; i < nodeManager.ReturnListSize(); i++)
        {
            finalPathSelection = nodeManager.ReturnFinalPathSelection();
            SCR_NodeClass currentNode = nodeManager.ReturnNodeAtIndex(i);

            List <STR_ID> currentNeighbours = currentNode.ReturnNeighbours();
            Transform     nodePos           = currentNode.returnID().body.transform;
            GUIStyle      style             = new GUIStyle();
            style.normal.textColor = Color.white;
            Handles.Label(nodePos.position, nodePos.gameObject.name, style);
            Color currentColour = Color.blue;

            RoomType currentRoomType = currentNode.ReturnRoomType();
            if (currentRoomType == RoomType.PrimaryRoom || currentRoomType == RoomType.InitialFightRoom || currentRoomType == RoomType.KeyRoom)
            {
                if (finalPathSelection.Contains(currentNode))
                {
                    currentColour = Color.green;
                }
                else
                {
                    currentColour = new Color(1.0f, 0.64f, 0.0f, 1.0f);
                }
            }
            else if (currentRoomType == RoomType.SecondaryPathway)
            {
                currentColour = Color.gray;
            }
            else if (currentRoomType == RoomType.StartRoom || currentRoomType == RoomType.EndRoom)
            {
                currentColour = new Color(1.0f, 0.64f, 0.0f, 1.0f);
            }
            else if (currentRoomType == RoomType.LootRoom)
            {
                currentColour = Color.blue;
            }
            else if (currentRoomType == RoomType.BlockedRoute)
            {
                currentColour = Color.red;
            }
            else if (currentRoomType == RoomType.UpgradeRoom)
            {
                currentColour = Color.yellow;
            }
            else if (currentRoomType == RoomType.ChallangeRoom)
            {
                currentColour = Color.magenta;
            }
            else if (currentRoomType == RoomType.smoothingPath)
            {
                currentColour = Color.white;
            }
            Handles.color = currentColour;
            Handles.DrawSolidDisc(nodePos.position, Vector3.up, nodeManager.nodeRadius);



            for (int j = 0; j < currentNeighbours.Count; j++)
            {
                Transform neighbourPos = currentNeighbours[j].body.transform;
                currentColour = Color.blue;
                SCR_NodeClass NeighbourNode = nodeManager.ReturnNode(currentNeighbours[j]);
                if (finalPathSelection.Contains(NeighbourNode) && finalPathSelection.Contains(currentNode))
                {
                    currentColour = Color.green;
                }
                Handles.color = currentColour;
                Handles.DrawLine(nodePos.position, neighbourPos.position);
            }
        }
    }