private static void SaveNodesAndEdges(EasyGraphView easyGraphView, EasyGraphAsset easyGraphAsset) { var edges = ExtractEdges(easyGraphView).Where(x => x.input.node != null && x.output.node != null).ToArray(); for (var i = 0; i < edges.Count(); i++) { var outputNode = edges[i].output.node as BaseNode; var inputNode = edges[i].input.node as BaseNode; easyGraphAsset.edgeData.Add(new EdgeData { sourcePort = edges[i].output.portName, targetPort = edges[i].input.portName, sourceNodeGUID = outputNode.GUID, targetNodeGUID = inputNode.GUID, }); } foreach (var node in ExtractNodes(easyGraphView)) { easyGraphAsset.commonNodeData.Add(new CommonNodeData { nodeGUID = node.GUID, nodeTypeId = node.GetType().AssemblyQualifiedName, serializedData = node.Serialize(), position = node.GetPosition().position }); } }
private static void LoadNodes(EasyGraphAsset easyGraphAsset, EasyGraphView easyGraphView) { foreach (var nodeData in easyGraphAsset.commonNodeData) { easyGraphView.LoadAndAddNode(nodeData); } }
private static void LoadCommentGroups(EasyGraphAsset easyGraphAsset, EasyGraphView easyGraphView) { foreach (var groupData in easyGraphAsset.commentGroupData) { var group = easyGraphView.CreateCommentGroup( new Rect(groupData.position, EasyGraphView.CommentGroupSize), groupData); group.AddElements(ExtractNodes(easyGraphView).Where(x => groupData.managedNodes.Contains(x.GUID))); } }
public static void LoadGraphViewAsset(EasyGraphAsset easyGraphAsset, EasyGraphView easyGraphView) { if (easyGraphAsset == null) { Debug.LogError("failed to load"); return; } ClearGraph(easyGraphView); LoadNodes(easyGraphAsset, easyGraphView); LoadEdges(easyGraphAsset, easyGraphView); LoadCommentGroups(easyGraphAsset, easyGraphView); }
private static void SaveCommentGroups(EasyGraphView easyGraphView, EasyGraphAsset easyGraphAsset) { var groups = ExtractGroups(easyGraphView); foreach (var group in groups) { var nodeGuidList = group.containedElements.Where(x => x is BaseNode).Cast <BaseNode>().Select(x => x.GUID).ToList(); easyGraphAsset.commentGroupData.Add(new CommentGroupData { managedNodes = nodeGuidList, title = group.title, position = group.GetPosition().position }); } }
public void Initialize(string guid) { AssetGuid = guid; string path = AssetDatabase.GUIDToAssetPath(guid); EasyGraphAsset easyGraphAsset = AssetDatabase.LoadAssetAtPath <EasyGraphAsset>(path); if (easyGraphAsset == null) { Debug.LogError("load failed"); return; } SaveLoadUtils.LoadGraphViewAsset(easyGraphAsset, _graphView); Repaint(); }
private static void LoadEdges(EasyGraphAsset easyGraphAsset, EasyGraphView easyGraphView) { cache.Clear(); foreach (var node in ExtractNodes(easyGraphView)) { cache.Add(node.GUID, node); } foreach (var e in easyGraphAsset.edgeData) { var sourceNode = cache[e.sourceNodeGUID]; var targetNode = cache[e.targetNodeGUID]; var sourcePort = sourceNode.outputContainer.Q <Port>(e.sourcePort); var targetPort = targetNode.inputContainer.Q <Port>(e.targetPort); var edge = MakeEdge(sourcePort, targetPort); easyGraphView.Add(edge); } cache.Clear(); }
private static void SaveGraphView(EasyGraphView easyGraphView, EasyGraphAsset easyGraphAsset) { SaveNodesAndEdges(easyGraphView, easyGraphAsset); SaveCommentGroups(easyGraphView, easyGraphAsset); }