Пример #1
0
 void ChangeConversation(Conversation newConversation)
 {
     selectedConnector = null;
     selectedNode      = null;
     if (nodes != null)
     {
         nodes.Clear();
     }
     else
     {
         nodes = new List <EditorNode>();
     }
     if (newConversation != null)
     {
         conversation           = newConversation;
         serializedConversation = new SerializedObject(conversation);
         foreach (DialogueEntry entry in conversation.Entries)
         {
             AddNode(entry);
         }
         foreach (DialogueEntry entry in conversation.Entries)
         {
             SetupNodeConnections(entry);
         }
     }
 }
Пример #2
0
        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);
                    }
                }
            }
        }
Пример #3
0
 void SetupNodeActions(EditorNode node)
 {
     node.OnStartMakeTransition = OnStartMakeTransition;
 }
Пример #4
0
 public void SelectNode(EditorNode node)
 {
     selectedNode = node;
 }