private void ProcessNode(DialogueNode node) { ClearChoices(); string dialogueTextContent = node.dialogueText; if (language != null) { dialogueTextContent = language.Translate(dialogueTextContent); } StopAllCoroutines(); StartCoroutine(TypeSentence(dialogueText, dialogueTextContent)); foreach (string choiceContent in node.choices) { Transform choice = Instantiate(choiceTemplate, choicesContainer); choice.GetComponent <RectTransform>().anchoredPosition = new Vector2(0.0f, -choicesContainerHeight * choiceList.Count); choice.gameObject.SetActive(true); StartCoroutine(TypeSentence(choice.Find("Text").GetComponent <Text>(), language.Translate(choiceContent))); XNode.NodePort connections = node.GetOutputPort("Choice_" + choiceList.Count); Button choiceButton = choice.GetComponent <Button>(); if (connections.IsConnected) { DialogueNode choiceOutput = connections.GetConnection(0).node as DialogueNode; choiceButton.onClick.AddListener(() => ProcessNode(choiceOutput)); } else { choiceButton.onClick.AddListener(EndDialogue); } choiceList.Add(choice); } }
/// <summary> /// Draw label field at noodle connections. Implement <seealso cref="XNode.INodeNoodleLabel"/> at their nodes to /// set label properties. /// </summary> /// <param name="window">window of the NodeGraph</param> public static void DrawNoodleLabels(NodeEditorWindow window) { try { if (window == null) { return; } NodeGraph target = window.graph; List <Vector2> gridPoints = new List <Vector2>(2); Object selectedObject = Selection.activeObject; foreach (XNode.Node node in target.nodes) { //If a null node is found, return. This can happen if the nodes associated script is deleted. It is currently not possible in Unity to delete a null asset. if (node == null) { continue; } if (node is INodeNoodleLabel == false) { continue; } if (AllowShowLabe(node) == false) { continue; } // Draw full connections and output > reroute foreach (XNode.NodePort output in node.Outputs) { //Needs cleanup. Null checks are ugly Rect fromRect; if (!window.portConnectionPoints.TryGetValue(output, out fromRect)) { continue; } for (int k = 0; k < output.ConnectionCount; k++) { XNode.NodePort input = output.GetConnection(k); // Error handling if (input == null) { continue; //If a script has been updated and the port doesn't exist, it is removed and null is returned. If this happens, return. } //if (!input.IsConnectedTo(output)) input.Connect(output); Rect toRect; if (!window.portConnectionPoints.TryGetValue(input, out toRect)) { continue; } List <Vector2> reroutePoints = output.GetReroutePoints(k); gridPoints.Clear(); gridPoints.Add(fromRect.center); gridPoints.AddRange(reroutePoints); gridPoints.Add(toRect.center); DrawNoodleLabesPositions(gridPoints, node, input); } } foreach (XNode.NodePort input in node.Inputs) { //Needs cleanup. Null checks are ugly Rect fromRect; if (!window.portConnectionPoints.TryGetValue(input, out fromRect)) { continue; } for (int k = 0; k < input.ConnectionCount; k++) { XNode.NodePort output = input.GetConnection(k); // Error handling if (output == null) { continue; //If a script has been updated and the port doesn't exist, it is removed and null is returned. If this happens, return. } //if (!input.IsConnectedTo(output)) input.Connect(output); Rect toRect; if (!window.portConnectionPoints.TryGetValue(output, out toRect)) { continue; } List <Vector2> reroutePoints = output.GetReroutePoints(k); gridPoints.Clear(); gridPoints.Add(fromRect.center); gridPoints.AddRange(reroutePoints); gridPoints.Add(toRect.center); DrawNoodleLabesPositions(gridPoints, node, output); } } } } catch { } }