Exemplo n.º 1
0
    // Move other nodes up/down to make spot for <..>, changing their list index and position
    private IEnumerator MoveOtherNodes(int start, int end, bool increment)
    {
        // Fix gravity outside this method

        // Move all existing list elements up (from the point where we want to insert the new element) *** Copied - <--- Methods made
        for (int i = start + 1; i <= end; i++) //for (int i=listObjects.Count-1; i >= index; i--)
        {
            NodeRepresentation involvedNodeRep = nodeRepresentations[i];

            // Find new position and move it
            Vector3 newPos = involvedNodeRep.transform.position + oneListIndexUp; // new Vector3(0f, 1f, 0f); <- oneListIndexUp
            involvedNodeRep.MoveNodeRepresentation(newPos);

            if (increment)
            {
                involvedNodeRep.ListIndex  = i - 1;
                nodeRepresentations[i - 1] = involvedNodeRep;
            }
            else
            {
                if (i + 1 > nodeRepresentations.Count - 1)
                {
                    Debug.Log("Stop!..");
                    continue;
                }
                involvedNodeRep.ListIndex  = i + 1;
                nodeRepresentations[i + 1] = involvedNodeRep;
            }
            yield return(involvedNodeRep.HighlightNodeRepresentation(UtilGraph.DIST_UPDATE_COLOR, seconds)); // 1f);
        }
    }
Exemplo n.º 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--;
    }