示例#1
0
    // Adding a visual representation of the node, with priority based on its distance value)
    public void PriorityAdd(Node node, int index)
    {
        UpdateListRoofPosition();

        // Move all existing list elements up (from the point where we want to insert the new element)
        for (int i = 0; i < index; i++)
        {
            // Remove gravity to make it easier to move the objects
            nodeRepresentations[i].GetComponent <Rigidbody>().useGravity = false;
            // Find new position and move it
            Vector3 newPos = nodeRepresentations[i].transform.position + oneListIndexUp; // new Vector3(0f, 1f, 0f);
            nodeRepresentations[i].GetComponent <MoveObject>().SetDestination(newPos);
        }

        // Add new element into the open slot
        Vector3            pos            = spawnPointList.position + oneListIndexUp * (nodeRepresentations.Count - index); // new Vector3(0f, 1f, 0f) <- oneListIndexUp
        NodeRepresentation newPrioNodeRep = CreateNodeRepresentation(node, pos, index);

        //newPrioNodeRep.GetComponent<TextHolder>().SetSurfaceText(node.NodeAlphaID, node.Dist);
        newPrioNodeRep.UpdateSurfaceText(UtilGraph.VISITED_COLOR);
        newPrioNodeRep.MoveNodeRepresentation(pos);
        nodeRepresentations.Insert(index, newPrioNodeRep);

        // Change color of the node representation we are looking for
        if (node.IsEndNode)
        {
            newPrioNodeRep.CurrentColor = UtilGraph.SHORTEST_PATH_COLOR;
        }


        // Enable gravity again and update indexes
        for (int i = 0; i < nodeRepresentations.Count; i++)
        {
            NodeRepresentation nodeRep = nodeRepresentations[i];
            nodeRep.SetGravity(true);
            nodeRep.ListIndex = i;
        }
    }
示例#2
0
    // Updates value and position of one node representation and other involved node reps.
    public IEnumerator UpdateValueAndPositionOf(Node node, int index, bool increment)
    {
        graphMain.UpdateCheckList(UtilGraph.LIST_VISUAL, false);

        Color prevColor = node.CurrentColor;

        node.CurrentColor = UtilGraph.DIST_UPDATE_COLOR;

        // Node representation we want to move
        NodeRepresentation mainNodeRep = FindNodeRepresentation(node);

        // Update surface text
        mainNodeRep.UpdateSurfaceText(UtilGraph.DIST_UPDATE_COLOR);

        // Moving from index
        int mainNodeRepIndex = mainNodeRep.ListIndex;

        //Debug.Log("Updating value of node '" + node.NodeAlphaID + "'. Current index=" + currentNodeRepIndex + " == " + nodeRepresentations.IndexOf(nodeRep) + " ???");

        // Check if index changed
        if (mainNodeRepIndex - index != 0)
        {
            // Disable gravity of swapping node reps
            SetGravityForMultipleNodeReps(0, index, false);

            // Move node left and down
            Vector3 moveLeft = mainNodeRep.transform.position + new Vector3(-1f, 0f, 0f);
            mainNodeRep.MoveNodeRepresentation(moveLeft);
            yield return(smallDuration);

            if (increment)
            {
                int     moveDownYpos = mainNodeRepIndex - index;
                Vector3 moveDown     = mainNodeRep.transform.position + new Vector3(-1f, moveDownYpos, 0f);
                mainNodeRep.MoveNodeRepresentation(moveDown);
                yield return(mediumDuration);

                // Move all the other involved up
                yield return(MoveOtherNodes(mainNodeRepIndex, index, true));
            }
            else
            {
                // Backward step (Move node representation up)
                int     moveUpYpos = index - mainNodeRepIndex;
                Vector3 moveUp     = mainNodeRep.transform.position + new Vector3(-1f, moveUpYpos, 0f);
                mainNodeRep.MoveNodeRepresentation(moveUp);
                yield return(mediumDuration);

                // Move all the other involved down
                yield return(MoveOtherNodes(mainNodeRepIndex, index, false));
            }


            // Move back into list
            Vector3 backInTheList = new Vector3(spawnPointList.position.x, mainNodeRep.transform.position.y, mainNodeRep.transform.position.z);
            mainNodeRep.MoveNodeRepresentation(backInTheList); //nodeRep.UpdateIndexPosition(index);
            mainNodeRep.ListIndex      = index;
            nodeRepresentations[index] = mainNodeRep;
            yield return(mainNodeRep.HighlightNodeRepresentation(UtilGraph.DIST_UPDATE_COLOR, seconds)); // 1f);

            // Enable gravity again
            SetGravityForMultipleNodeReps(0, index, true);
        }
        node.CurrentColor = prevColor;

        graphMain.UpdateCheckList(UtilGraph.LIST_VISUAL, true);
        graphMain.WaitForSupportToComplete--;
    }