public static bool OpenGameLogicFromAsset(int instanceID, int line) { SerializableDialogData data = EditorUtility.InstanceIDToObject(instanceID) as SerializableDialogData; OpenWindow(data); return(data != null); // we did not handle the open }
public static void OpenWindow(SerializableDialogData data) { if (data != null) { DialogueGraphViewWindow view = GetWindow <DialogueGraphViewWindow>("Dialogue", true, typeof(SceneView)); view.ShowScript(data); } }
void EndDialogue() { Debug.Log("Dialogue End"); m_CurrentDialogue = null; m_CurrentDialogueNode = null; if (m_DialogueEnd != null) { m_DialogueEnd(); } m_DialogueEnd = null; }
public void ShowScript(SerializableDialogData data) { m_DialogData = data; if (!LoadGraphData()) { DialogueNode node = CreateStartNode(); node.addOutput(); m_GraphView.AddElement(node); } }
public void StartDialogue(SerializableDialogData dialogue, Action onDialogueEnd = null) { if (m_CurrentDialogue == null) { Debug.Log("Dialogue Start"); m_CurrentDialogue = dialogue; int startIndex = 0; for (int i = 0; i < dialogue.m_dialogNodes.Count; ++i) { if (dialogue.m_dialogNodes[i].m_title == "START") { startIndex = i; break; } } m_CurrentDialogueNode = dialogue.m_dialogNodes[startIndex]; m_DialogueEnd = onDialogueEnd; ContinueDialogue(); } }
void OnSelectionChanged() { SaveGraphData(); ClearGraphData(); SerializableDialogData[] data = Selection.GetFiltered <SerializableDialogData>(SelectionMode.Assets); if (data.Length != 1) { m_DialogData = null; return; } m_DialogData = data[0]; if (!LoadGraphData()) { DialogueNode node = CreateStartNode(); node.addOutput(); m_GraphView.AddElement(node); } }
public void SaveGraphData() { if (m_DialogData == null) { return; } List <Node> nodes = m_GraphView.nodes.ToList(); SerializableDialogData dialogGraphData = ScriptableObject.CreateInstance <SerializableDialogData>(); dialogGraphData.m_dialogNodes = new List <SerializableDialogData.SerializableDialogNode>(); string outPutString = string.Empty; for (int i = 0; i < nodes.Count; ++i) { SerializableDialogData.SerializableDialogNode dialogGraphNode = new SerializableDialogData.SerializableDialogNode(); Node currentNode = nodes[i]; dialogGraphNode.inputNodeCount = currentNode.inputContainer.childCount; dialogGraphNode.outputNodeCount = currentNode.outputContainer.childCount; dialogGraphNode.m_title = currentNode.title; dialogGraphNode.m_position = currentNode.GetPosition().position; dialogGraphNode.m_outputs = new List <SerializableDialogData.SerializableDialogEdge>(); dialogGraphNode.m_outputDialogs = new List <string>(); foreach (VisualElement element in currentNode.mainContainer) { if (element is TextField) { if (((TextField)element).name == "characterName") { dialogGraphNode.m_speakingCharacterName = ((TextField)element).value; } else if (((TextField)element).name == "characterDialogue") { dialogGraphNode.m_characterDialogue = ((TextField)element).value; } } } foreach (VisualElement element in currentNode.outputContainer) { if (element.childCount > 1 && element[0] is TextField) { outPutString = ((TextField)element[0]).value; dialogGraphNode.m_outputDialogs.Add(outPutString); } if (element.childCount > 1 && element[1] is Port) { foreach (Edge edge in ((Port)element[1]).connections) { SerializableDialogData.SerializableDialogEdge serializedEdge = new SerializableDialogData.SerializableDialogEdge(); var sourceContainer = currentNode.outputContainer.First(e => e[1] == edge.output); serializedEdge.m_sourcePort = sourceContainer == null ? -1 : currentNode.outputContainer.IndexOf(sourceContainer); serializedEdge.m_targetPort = edge.input.node.inputContainer.IndexOf(edge.input); serializedEdge.m_targetNode = nodes.IndexOf(edge.input.node); if (serializedEdge.m_sourcePort == -1 || serializedEdge.m_targetPort == -1) { continue; } dialogGraphNode.m_outputs.Add(serializedEdge); } } } dialogGraphData.m_dialogNodes.Add(dialogGraphNode); } EditorUtility.CopySerialized(dialogGraphData, m_DialogData); AssetDatabase.SaveAssets(); }