private void InitIfNeeded() { if (_init) { return; } InitCommandsAndConditions(); _vnSaver = new VNSaver(new JsonFileStorage(() => Application.dataPath + "/Resources/NodeTrees/", ".txt"), _mediaType); _menuBar = new NodeEditorMenuBar(this, Save, Load, New, Center, ResetZoom); _menuBar.NodeTreeName = "Untitled"; _startNode = new StartNode(new Vector2(this.position.width / 2, this.position.height / 3), OnClickConnectionPoint); _init = true; if (File.Exists(Application.dataPath + "/Resources/NodeTrees/PreviousAutoSave.vn")) { File.Delete(Application.dataPath + "/Resources/NodeTrees/PreviousAutoSave.vn"); } if (File.Exists(Application.dataPath + "/Resources/NodeTrees/AutoSave.vn")) { File.Move(Application.dataPath + "/Resources/NodeTrees/AutoSave.vn", Application.dataPath + "/Resources/NodeTrees/PreviousAutoSave.vn"); } Save("AutoSave"); }
private void Load() { var path = EditorUtility.OpenFilePanel("Load Dialogue File", Application.dataPath + "/Dialogues", "vn"); if (path.Length != 0) { var nodeEditor = _mediaType.ConvertFrom <NodeTreeEditorData>(File.ReadAllText(path)); _menuBar.NodeTreeName = nodeEditor.Name; _startNode = new StartNode(_mediaType, nodeEditor.StartNode, OnClickConnectionPoint); _nodes = nodeEditor.Nodes.Select(CreateNode).ToList(); _connections = nodeEditor.Connections .Select(x => new Connection(_mediaType, x, _nodes, _startNode, OnClickRemoveConnection)).ToList(); _zoom = nodeEditor.Zoom > 0 ? nodeEditor.Zoom : 1; } }
private Connection(ConnectionData data, List <Node> nodes, StartNode startNode, Action <Connection> onClick) : this( nodes.First(x => x.ID == data.InNodeID).InPoint, startNode.ID == data.OutNodeID ? startNode.OutPoint : nodes.First(x => x.ID == data.OutNodeID).OutPoint, onClick) { }
public Connection(IMediaType mediaType, string media, List <Node> nodes, StartNode startNode, Action <Connection> onClick) : this(mediaType.ConvertFrom <ConnectionData>(media), nodes, startNode, onClick) { }