private void RemoveBranchClicked(DialogueDatam dialogueDatam, DialogueBranch branch, VisualElement ui) { // remove any link uis from other branches for (int i = 0; i < uis.Count; i++) { if (uis[i] != ui) { var linkUIs = uis[i].Query("Links"); //for (int j = 0; j < linkUIs.Count; j++) //foreach (var linkUI in linkUIs.Descendents) linkUIs.ForEach((linkUI) => { var content = linkUI.Query("unity-content").First().Query <Button>(); content.ForEach((childButton) => { if (childButton.text == "[" + branch.id + "]") { childButton.parent.Remove(childButton); // remove the link to branch } }); }); } } dialogueDatam.dialogueTree.RemoveBranch(branch); // remove the UI as well uis.Remove(ui); ui.parent.Remove(ui); // check for branches - if they are linked to this branch for (int i = 0; i < dialogueDatam.dialogueTree.branches.Length; i++) { var otherBranch = dialogueDatam.dialogueTree.branches[i]; for (int j = 0; j < otherBranch.links.Length; j++) { if (otherBranch.links[j] == branch.id) { // reset branch link dialogueDatam.SetBranchLink(otherBranch, j, 0); // also set the link ui uis[i].Query <Foldout>("Links").ToList()[j].text = "[Unlinked]"; } } } }
private void OnLinkClicked(Foldout linksFoldout, DialogueDatam dialogueDatam, DialogueBranch branch, int linkIndex, int nextID, string nextSpeech) { if (nextSpeech == null) { nextSpeech = ""; } // set id to the text if (linkIndex >= branch.links.Length) { Debug.LogError("Link Index out of bounds: " + branch.id + ":" + linkIndex); } else { branch = dialogueDatam.SetBranchLink(branch, linkIndex, nextID); //branch.links[linkIndex] = nextID; linksFoldout.text = "Next Branch [" + branch.links[linkIndex] + "]: " + nextSpeech.Substring(0, Mathf.Min(nextSpeech.Length, 16)) + ".."; linksFoldout.value = false; EditorUtility.SetDirty(cachedObject.targetObject); } }