public void StartConversation() { current = conversation.Start; UISystem.OnConversationStart(); OnConversationStart.Invoke(); }
public void EndConversation() { current = null; UISystem.OnConversationEnd(); OnConversationEnd.Invoke(); }
public DialogueEntry FindEntry(string title) { DialogueEntry entry = Entries.Find(e => e.Title == title); return(entry); }
public void RemoveEntry(DialogueEntry entry) { Entries.Remove(entry); }
public DialogueEntry FindEntry(int id) { DialogueEntry entry = Entries.Find(e => e.ID == id); return(entry); }
void UpdateNodes() { HashSet <int> seenIDs = new HashSet <int>(); List <EditorNode> toRemove = new List <EditorNode>(); List <EditorNode> nodeToAdd = new List <EditorNode>(); foreach (EditorNode node in nodes) { DialogueEntryEditorNode dialogueNode = node as DialogueEntryEditorNode; ResponseEditorNode responseNode = node as ResponseEditorNode; if (dialogueNode != null) { // Check if node is removed from conversation seenIDs.Add(dialogueNode.entryID); DialogueEntry entry = conversation.FindEntry(dialogueNode.entryID); if (entry == null) { toRemove.Add(node); // Remove any responses from destroyed node foreach (EditorConnector connection in dialogueNode.Connections) { if (connection.Target as ResponseEditorNode != null) { toRemove.Add(connection.Target); } } } else { // Check responses on node dialogueNode.entry = entry; int maxIndexSeen = -1; foreach (EditorConnector connection in dialogueNode.Connections) { //check if there's responses to remove ResponseEditorNode childNode = connection.Target as ResponseEditorNode; if (childNode != null) { if (childNode.index < entry.Responses.Count) { maxIndexSeen = Mathf.Max(maxIndexSeen, childNode.index); childNode.response = entry.Responses[childNode.index]; } else { // Node has out of range index toRemove.Add(childNode); } } } // Add any needed responses for (int i = maxIndexSeen + 1; i < entry.Responses.Count(); ++i) { Response response = entry.Responses[i]; ResponseEditorNode newNode = new ResponseEditorNode(response.Position, NODE_WIDTH, NODE_HEIGHT, responseNodeStyle, responseSelectedNodeStyle); newNode.response = response; newNode.entryID = entry.ID; newNode.index = i; SetupNodeActions(newNode); EditorConnector connector = new EditorConnector(); connector.Parent = dialogueNode; connector.Target = newNode; dialogueNode.Connections.Add(connector); nodeToAdd.Add(newNode); } } } } // Remove nodes and any connections to them nodes.RemoveAll(n => toRemove.Contains(n)); if (selectedConnector != null && toRemove.Contains(selectedConnector.Parent)) { selectedConnector = null; } if (toRemove.Contains(selectedNode)) { selectedNode = null; } foreach (EditorNode node in nodes) { node.Connections.RemoveAll(c => toRemove.Contains(c.Target)); } // Create new nodes for any dialogue entries not already seen List <DialogueEntry> toAdd = conversation.Entries.Where(e => !seenIDs.Contains(e.ID)).ToList(); foreach (DialogueEntry entry in toAdd) { AddNode(entry); } // Add new response nodes to list nodes.AddRange(nodeToAdd); // Now all nodes exist (or don't) check all transitions foreach (EditorNode node in nodes) { DialogueEntryEditorNode dialogueNode = node as DialogueEntryEditorNode; ResponseEditorNode responseNode = node as ResponseEditorNode; List <int> targetsRequired; List <EditorConnector> connectorToRemove = new List <EditorConnector>(); if (dialogueNode != null) { targetsRequired = dialogueNode.entry.transitions.transitions.Select(o => o.transition.TargetID).ToList(); } else if (responseNode != null) { targetsRequired = responseNode.response.transitions.transitions.Select(o => o.transition.TargetID).ToList(); } else { targetsRequired = new List <int>(); } foreach (EditorConnector connection in node.Connections) { DialogueEntryEditorNode targetDialogue = connection.Target as DialogueEntryEditorNode; if (targetDialogue != null) { if (targetsRequired.Contains(targetDialogue.entryID)) { targetsRequired.Remove(targetDialogue.entryID); } else { connectorToRemove.Add(connection); } } } node.Connections.RemoveAll(c => connectorToRemove.Contains(c)); // Create required connections foreach (int targetID in targetsRequired) { DialogueEntryEditorNode targetNode = FindDialogueNode(targetID); if (targetNode != null) { EditorConnector newConnector = new EditorConnector(); newConnector.Parent = node; newConnector.Target = targetNode; node.Connections.Add(newConnector); } } } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { //TODO add buttons for moving transitions, add/remove SerializedProperty optionsList = property.FindPropertyRelative("transitions"); SerializedProperty defaultTransition = property.FindPropertyRelative("defaultTransition"); int optionSize = optionsList.arraySize; //HACK if transitions can ever be displayed outside a conversation being selected this will have to change Conversation conversation = Selection.activeObject as Conversation; ListActions action = ListActions.Nothing; int selectedIndex = -1; //TODO figure out good place to extract out this list drawing code (have attribute to use?) SerializedProperty option; SerializedProperty targetID; SerializedProperty condition; EditorGUILayout.BeginVertical(); //EditorGUILayout.LabelField(label, EditorStyles.boldLabel); optionsList.isExpanded = EditorGUILayout.Foldout(optionsList.isExpanded, label, true, EditorStyles.boldLabel); //TODO create "Bold Foldout style" if (optionsList.isExpanded) { for (int i = 0; i < optionSize; ++i) { option = optionsList.GetArrayElementAtIndex(i); targetID = option.FindPropertyRelative("transition.TargetID"); condition = option.FindPropertyRelative("condition"); // Get name of int optionTarget = targetID.intValue; DialogueEntry targetEntry = conversation.FindEntry(optionTarget); string targetName = "Dialogue entry not found"; if (targetEntry != null) { targetName = "To " + StringUtility.TruncateString(targetEntry.Name(), MAX_DIALOGUE_NAME_LENGTH); } EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginVertical(); EditorGUILayout.PropertyField(option, new GUIContent(targetName), true); //EditorGUILayout.PropertyField(condition, true); //EditorGUILayout.PropertyField(targetID, true); EditorGUILayout.EndVertical(); bool moveUp = false, moveDown = false, remove = false; using (new EditorGUI.DisabledScope(i == 0)) // Disable if already first { moveUp = GUILayout.Button("^", GUILayout.Width(MOVE_BUTTON_WIDTH)); } using (new EditorGUI.DisabledScope(i + 1 >= optionSize)) // Disable if last { moveDown = GUILayout.Button("v", GUILayout.Width(MOVE_BUTTON_WIDTH)); } // remove = GUILayout.Button("X", GUILayout.Width(MOVE_BUTTON_WIDTH)); EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); if (moveUp) { action = ListActions.MoveUp; selectedIndex = i; } else if (moveDown) { action = ListActions.MoveDown; selectedIndex = i; } else if (remove) { action = ListActions.Delete; selectedIndex = i; } } GUILayout.BeginHorizontal(); bool addItem = false, clearItems = false; addItem = GUILayout.Button("Add Transition"); using (new EditorGUI.DisabledScope(optionSize == 0)) { clearItems = GUILayout.Button("Clear Transitions"); } GUILayout.EndHorizontal(); if (addItem) { optionsList.InsertArrayElementAtIndex(optionSize); } if (clearItems) { optionsList.ClearArray(); } // Handle choice switch (action) { case ListActions.MoveUp: if (selectedIndex > 0) { optionsList.MoveArrayElement(selectedIndex, selectedIndex - 1); } break; case ListActions.MoveDown: if (selectedIndex >= 0 && selectedIndex < (optionSize - 1)) { optionsList.MoveArrayElement(selectedIndex, selectedIndex + 1); } break; case ListActions.Delete: if (selectedIndex >= 0 && selectedIndex < optionSize) { optionsList.DeleteArrayElementAtIndex(selectedIndex); } break; case ListActions.Nothing: default: break; } } else { optionsList.isExpanded = GUILayout.Button("Show"); } EditorGUILayout.EndVertical(); //base.OnGUI(position, property, label); }
public IEnumerator ResponseSelectedRoutine(int id) { acceptingInput = false; if (id >= 0 && id < current.Responses.Count) { Response response = current.Responses[id]; if (response.CheckPrerequisite(this)) { // Do onExit events foreach (DialogueEventInstance e in current.OnExit) { e.Execute(this); if (e.IsRoutine) { yield return(e.DoRoutine(this)); } // Some events force end conversation, if so breaking here if (!m_inConversation) { yield break; } } // Do response events foreach (DialogueEventInstance e in response.OnChosen) { e.Execute(this); if (e.IsRoutine) { yield return(e.DoRoutine(this)); } // Some events force end conversation, if so breaking here if (!m_inConversation) { yield break; } } Transition selectedTransition = response.transitions.SelectTransition(this); if (selectedTransition != null) { current = conversation.FindEntry(selectedTransition.TargetID); // do onEnter for current foreach (DialogueEventInstance e in current.OnEnter) { e.Execute(this); if (e.IsRoutine) { yield return(e.DoRoutine(this)); } // Some events force end conversation, if so breaking here if (!m_inConversation) { yield break; } } UISystem.SetDialogueEntry(current); } else { EndConversation(); } } } acceptingInput = true; }
// Called when a new DialogueEntry is entered public virtual void DisplayDialogueEntry(DialogueEntry entry) { throw new System.NotImplementedException(); }