private void LoadSpecific(string assetPath) { // Load selected asset into container class dialogue = (DialogueContainer)AssetDatabase.LoadAssetAtPath(assetPath, typeof(DialogueContainer)); // Clear nodes and connections of current dialogue nodes.Clear(); connections.Clear(); // Loop through all nodes and connections in loaded container class and add them to current dialogue foreach (Node node in dialogue.nodes) { if (node is StartNode) { StartNode newNode = CreateInstance <StartNode>(); newNode.Init(node.id, node.rect.position, StartNode.width, StartNode.defaultHeight, nodeStyle, selectedNodeStyle, outPointStyle, OnClickOutPoint, OnClickRemoveNode); nodes.Add(newNode); } if (node is DialogueLineNode) { DialogueLineNode newNode = CreateInstance <DialogueLineNode>(); newNode.Init(node.id, node.rect.position, DialogueLineNode.width, DialogueLineNode.defaultHeight, nodeStyle, selectedNodeStyle, inPointStyle, outPointStyle, OnClickInPoint, OnClickOutPoint, OnClickRemoveNode); DialogueLineNode tempNode = (DialogueLineNode)node; newNode.Load(tempNode.actorName, tempNode.dialogueLine, node.inPoints.Count, tempNode.DayBank, tempNode.Day, tempNode.Clip, tempNode.Char, tempNode._fmod, tempNode.Dia); nodes.Add(newNode); } else if (node is PlayerChoiceNode) { PlayerChoiceNode newNode = CreateInstance <PlayerChoiceNode>(); newNode.Init(node.id, node.rect.position, PlayerChoiceNode.width, PlayerChoiceNode.defaultHeight, nodeStyle, selectedNodeStyle, inPointStyle, outPointStyle, OnClickInPoint, OnClickOutPoint, OnClickRemoveNode); PlayerChoiceNode tempNode = (PlayerChoiceNode)node; newNode.Load(tempNode.optionLines, node.inPoints.Count, node.outPoints.Count); nodes.Add(newNode); } else if (node is CheckVariableNode) { CheckVariableNode newNode = CreateInstance <CheckVariableNode>(); newNode.Init(node.id, node.rect.position, CheckVariableNode.width, CheckVariableNode.defaultHeight, nodeStyle, selectedNodeStyle, inPointStyle, outPointStyle, OnClickInPoint, OnClickOutPoint, OnClickRemoveNode); CheckVariableNode tempNode = (CheckVariableNode)node; newNode.Load(tempNode.boolIndex, node.inPoints.Count); nodes.Add(newNode); } else if (node is SetVariableNode) { SetVariableNode newNode = CreateInstance <SetVariableNode>(); newNode.Init(node.id, node.rect.position, SetVariableNode.width, SetVariableNode.defaultHeight, nodeStyle, selectedNodeStyle, inPointStyle, outPointStyle, OnClickInPoint, OnClickOutPoint, OnClickRemoveNode); SetVariableNode tempNode = (SetVariableNode)node; newNode.Load(tempNode.boolIndex, tempNode.boolValueIndex, node.inPoints.Count); nodes.Add(newNode); } // Make sure currentHighestID is updated to avoid multiple nodes with same id if (node.id > currentHighestID) { currentHighestID = node.id; } } foreach (Connection connection in dialogue.connections) { Connection newConnection = CreateInstance <Connection>(); Node inPointNode = null; Node outPointNode = null; // Go through all nodes in current dialogue to find which ones to create a connection between foreach (Node node in nodes) { if (connection.inPoint.node.id == node.id) { inPointNode = node; } if (connection.outPoint.node.id == node.id) { outPointNode = node; } } if (inPointNode != null && outPointNode != null) { // Create a connection between nodes newConnection.Load(inPointNode, outPointNode, connection.inPoint.index, connection.outPoint.index, OnClickRemoveConnection); connections.Add(newConnection); } else { Debug.Log("Load connection failed. inPointNode: " + inPointNode + " outPointNode: " + outPointNode); } } }
private void Load() { // Show file browser string assetPath = EditorUtility.OpenFilePanel("Select asset", "Assets/Resources/Dialogues", "asset"); if (assetPath != "") { // Make selected path relative instead of absolute assetPath = assetPath.Replace(Application.dataPath, "Assets"); string[] splitAssetPath = assetPath.Split('/'); lastSavedName = splitAssetPath[splitAssetPath.Length - 1]; } else { return; } // Load selected asset into container class dialogue = (DialogueContainer)AssetDatabase.LoadAssetAtPath(assetPath, typeof(DialogueContainer)); // Clear nodes and connections of current dialogue nodes.Clear(); connections.Clear(); // Loop through all nodes and connections in loaded container class and add them to current dialogue foreach (Node node in dialogue.nodes) { if (node is StartNode) { StartNode newNode = CreateInstance <StartNode>(); newNode.Init(node.id, node.rect.position, StartNode.width, StartNode.defaultHeight, nodeStyle, selectedNodeStyle, outPointStyle, OnClickOutPoint, OnClickRemoveNode); nodes.Add(newNode); } if (node is DialogueLineNode) { DialogueLineNode newNode = CreateInstance <DialogueLineNode>(); newNode.Init(node.id, node.rect.position, DialogueLineNode.width, DialogueLineNode.defaultHeight, nodeStyle, selectedNodeStyle, inPointStyle, outPointStyle, OnClickInPoint, OnClickOutPoint, OnClickRemoveNode); DialogueLineNode tempNode = (DialogueLineNode)node; newNode.Load(tempNode.actorName, tempNode.dialogueLine, node.inPoints.Count, tempNode.DayBank, tempNode.Day, tempNode.Clip, tempNode.Char, tempNode._fmod, tempNode.Dia); nodes.Add(newNode); } else if (node is PlayerChoiceNode) { PlayerChoiceNode newNode = CreateInstance <PlayerChoiceNode>(); newNode.Init(node.id, node.rect.position, PlayerChoiceNode.width, PlayerChoiceNode.defaultHeight, nodeStyle, selectedNodeStyle, inPointStyle, outPointStyle, OnClickInPoint, OnClickOutPoint, OnClickRemoveNode); PlayerChoiceNode tempNode = (PlayerChoiceNode)node; newNode.Load(tempNode.optionLines, node.inPoints.Count, node.outPoints.Count); nodes.Add(newNode); } else if (node is CheckVariableNode) { CheckVariableNode newNode = CreateInstance <CheckVariableNode>(); newNode.Init(node.id, node.rect.position, CheckVariableNode.width, CheckVariableNode.defaultHeight, nodeStyle, selectedNodeStyle, inPointStyle, outPointStyle, OnClickInPoint, OnClickOutPoint, OnClickRemoveNode); CheckVariableNode tempNode = (CheckVariableNode)node; newNode.Load(tempNode.boolIndex, node.inPoints.Count); nodes.Add(newNode); } else if (node is SetVariableNode) { SetVariableNode newNode = CreateInstance <SetVariableNode>(); newNode.Init(node.id, node.rect.position, SetVariableNode.width, SetVariableNode.defaultHeight, nodeStyle, selectedNodeStyle, inPointStyle, outPointStyle, OnClickInPoint, OnClickOutPoint, OnClickRemoveNode); SetVariableNode tempNode = (SetVariableNode)node; newNode.Load(tempNode.boolIndex, tempNode.boolValueIndex, node.inPoints.Count); nodes.Add(newNode); } // Make sure currentHighestID is updated to avoid multiple nodes with same id if (node.id > currentHighestID) { currentHighestID = node.id; } } foreach (Connection connection in dialogue.connections) { Connection newConnection = CreateInstance <Connection>(); Node inPointNode = null; Node outPointNode = null; // Go through all nodes in current dialogue to find which ones to create a connection between foreach (Node node in nodes) { if (connection.inPoint.node.id == node.id) { inPointNode = node; } if (connection.outPoint.node.id == node.id) { outPointNode = node; } } if (inPointNode != null && outPointNode != null) { // Create a connection between nodes newConnection.Load(inPointNode, outPointNode, connection.inPoint.index, connection.outPoint.index, OnClickRemoveConnection); connections.Add(newConnection); } else { Debug.Log("Load connection failed. inPointNode: " + inPointNode + " outPointNode: " + outPointNode); } } }