public void RemoveNode(DialogueGraphNode node) { int index = nodes.IndexOf(node); nodes.Remove(node); for (int i = 0; i < transitions.Count; i++) { DialogueGraphTransition transition = transitions[i]; if (transition.from == index || transition.to == index) { transitions.Remove(transition); i--; } if (transition.from > index) { transition.from--; } else if (transition.to > index) { transition.to--; } } GUI.changed = true; }
private void DrawTransition(DialogueGraphTransition transition) { string from = graph.nodes[transition.from].name; string to = "Exit"; if (transition.to >= 0) { to = graph.nodes[transition.to].name; } float width = Screen.width * 0.3f; //75% of available width is for text; ~40% of that space is for each word. Thus, 30% is for each word. GUIStyle style = GUI.skin.label; from = EditorUtils.TrimStringToFit(from, width, style); to = EditorUtils.TrimStringToFit(to, width, style); Rect rect = EditorGUILayout.BeginHorizontal(); GUI.Box(rect, GUIContent.none); GUILayout.Label($"{from} -> {to}"); if (GUILayout.Button("Remove")) { graph.transitions.Remove(transition); } EditorGUILayout.EndHorizontal(); }
private void DrawTransitions() { GUILayout.Label("Transitions"); for (int i = 0; i < graph.transitions.Count; i++) { DialogueGraphTransition t = graph.transitions[i]; if (t.from == graph.selectedNode || t.to == graph.selectedNode) { DrawTransition(t); GUILayout.Space(5); } } }
private void OnDialogueOptionClicked(int index) { DialogueGraphTransition[] transitions = GetTransitionsFor(currentGraph, currentNode); DialogueGraphTransition transition = transitions[index]; if (transition.to < 0) { dialogueUI.SetActive(false); } else { StartCoroutine(ShowDialogue(transition.to)); } }
private DialogueGraphTransition[] GetTransitionsFor(DialogueGraph graph, int node) { LinkedList <DialogueGraphTransition> transitionsList = new LinkedList <DialogueGraphTransition>(); foreach (DialogueGraphTransition t in graph.transitions) { if (t.from == node) { transitionsList.AddLast(t); } } DialogueGraphTransition[] transitions = new DialogueGraphTransition[transitionsList.Count]; transitionsList.CopyTo(transitions, 0); return(transitions); }