Ejemplo n.º 1
0
    public void SetupNetwork(bool hardReset = false, bool skipDialogue = false)
    {
        // Check if the user really wants to do this
        if (!skipDialogue)
        {
            if (hardReset && !UnityEditor.EditorUtility.DisplayDialog("Hard reset", "You are about to reset every node, regardless whether they are set to reset in their options", "Hard Reset", "I made a mistake"))
            {
                return;
            }
        }

        timer.Start();

        if (!GetAllNodes())
        {
            return;
        }

        List <NodeBehaviour> availableNodes = DataTools.allNodes.ToList();
        NodeBehaviour        currentNode    = availableNodes[0];
        NodeBehaviour        nextNode       = null;

        //currentNode.connected = true; // First one is the starting node and should not be connected with again.

        int time  = 0;
        int error = 100;

        while (availableNodes.Count > 0)
        {
            if (time >= error)
            {
                NodeEditor.editor.RecieveMessage("conecting failed", WarningStatus.Error);
                return;
            }
            time++;

            // End nodes should not connect with any other node
            if (currentNode.endNode)
            {
                break;
            }

            // Hard reset the curves nodes and curves
            if (hardReset)
            {
                currentNode.resetCurves = hardReset;
            }

            // Connect to another node that is the closest to this one
            nextNode = ConnectToOtherNode(currentNode);
            if (!nextNode)
            {
                return;
            }

            // Init the node after it has been connected and check if it connected
            if (!currentNode.InitNode())
            {
                return;
            }

            // Set the new current node to be checked
            currentNode = nextNode;
            availableNodes.Remove(nextNode);
        }

        // Set the last node again when the tracks loops around
        if (!currentNode.endNode)
        {
            if (hardReset)
            {
                currentNode.resetCurves = hardReset;
            }
            currentNode.InitNode();
        }

        FinalizeConnecting(hardReset ? "Hard Reset" : "Connect Network", (int)timer.ElapsedMilliseconds);
    }