public static bool removeNodeContent(DialogueNode node, int index) { // Make sure the parameters for this call are in any way reasonable: if (node == null || node.content == null || index < 0 || index >= node.content.Length) { return(false); } int newContentCount = node.content.Length - 1; // If there's only one content block remaining, kill the array: if (newContentCount <= 0) { node.content = null; return(true); } // Generate new content array: DialogueContent[] newContents = new DialogueContent[newContentCount]; // Copy contents from previous content array: for (int i = 0; i < newContentCount; ++i) { int srcIndex = i < index ? i : i + 1; newContents[i] = node.content[srcIndex]; } // Assign array back to the node: node.content = newContents; EditorUtility.SetDirty(node); return(true); }
public static void addNodeContent(DialogueNode node, int index) { int newContentCount = node != null ? node.content.Length + 1 : 1; index = Mathf.Clamp(index, 0, newContentCount); DialogueContent[] newContents = new DialogueContent[newContentCount]; // Copy contents from previous array: if (node.content != null) { for (int i = 0; i < newContentCount; ++i) { int srcIndex = Mathf.Max(i < index ? i : i - 1, 0); newContents[i] = node.content[srcIndex]; } } // Create new blank content at index: newContents[index] = DialogueContent.Blank; // Assign array back to the node: node.content = newContents; EditorUtility.SetDirty(node); }