private static void LoadNodes(EasyGraphAsset easyGraphAsset, EasyGraphView easyGraphView) { foreach (var nodeData in easyGraphAsset.commonNodeData) { easyGraphView.LoadAndAddNode(nodeData); } }
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 }); } }
public static void SaveGraphView(EasyGraphView easyGraphView, string guid) { string assetPath; if (string.IsNullOrEmpty(guid)) { string filePath = EditorUtility.SaveFilePanel("where to save", ".", "new EasyGraph", "asset"); if (string.IsNullOrEmpty(filePath)) { return; } if (File.Exists(filePath)) { Debug.Log("will overwrite"); } assetPath = FileUtil.GetProjectRelativePath(filePath); } else { string path = AssetDatabase.GUIDToAssetPath(guid); assetPath = path; } var newAsset = ScriptableObject.CreateInstance <EasyGraphAsset>(); SaveGraphView(easyGraphView, newAsset); AssetDatabase.CreateAsset(newAsset, assetPath); AssetDatabase.SaveAssets(); }
public void Initialize(EditorWindow window, EasyGraphView graphView) { _window = window; _graphView = graphView; _icon = new Texture2D(1, 1); _icon.SetPixel(0, 0, new Color(0, 0, 0, 0)); _icon.Apply(); }
private void CreateGraphView() { _graphView = new EasyGraphView(this) { name = "GraphViewDemo", }; _graphView.StretchToParentSize(); _graphView.deleteSelection += DeleteSelectionImplementation; rootVisualElement.Add(_graphView); }
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))); } }
private static void ClearGraph(EasyGraphView easyGraphView) { var nodes = ExtractNodes(easyGraphView); foreach (var node in nodes) { var edges = ExtractEdges(easyGraphView); edges.Where(x => x.input.node == node || x.output.node == node).ToList() .ForEach(edge => easyGraphView.RemoveElement(edge)); easyGraphView.RemoveElement(node); } }
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 void CleanUp() { if (_graphView != null) { _graphView.deleteSelection -= DeleteSelectionImplementation; rootVisualElement.Remove(_graphView); _graphView = null; } if (_toolbar != null) { rootVisualElement.Remove(_toolbar); _toolbar = null; } _miniMap = null; }
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 static void LoadGraphViewAsset(EasyGraphView easyGraphView) { string filePath = EditorUtility.OpenFilePanel("where to load?", ".", "asset"); if (string.IsNullOrEmpty(filePath)) { return; } if (!File.Exists(filePath)) { Debug.LogError("not exist"); return; } string assetPath = FileUtil.GetProjectRelativePath(filePath); var easyGraphAsset = AssetDatabase.LoadAssetAtPath <EasyGraphAsset>(assetPath); LoadGraphViewAsset(easyGraphAsset, easyGraphView); }
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); }
private static IEnumerable <Group> ExtractGroups(EasyGraphView easyGraphView) { return(easyGraphView.graphElements.ToList().Where(e => e is Group).Cast <Group>()); }
private static IEnumerable <Edge> ExtractEdges(EasyGraphView easyGraphView) { return(easyGraphView.edges.ToList()); }
private static IEnumerable <BaseNode> ExtractNodes(EasyGraphView easyGraphView) { return(easyGraphView.nodes.ToList().Where(n => n is BaseNode).Cast <BaseNode>()); }