|  |  | @ -6,10 +6,12 @@ using TNode.Cache; | 
			
		
	
		
		
			
				
					
					|  |  |  | using TNode.Editor.Inspector; |  |  |  | using TNode.Editor.Inspector; | 
			
		
	
		
		
			
				
					
					|  |  |  | using TNode.Editor.Model; |  |  |  | using TNode.Editor.Model; | 
			
		
	
		
		
			
				
					
					|  |  |  | using TNode.Models; |  |  |  | using TNode.Models; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | using Unity.VisualScripting; | 
			
		
	
		
		
			
				
					
					|  |  |  | using UnityEditor; |  |  |  | using UnityEditor; | 
			
		
	
		
		
			
				
					
					|  |  |  | using UnityEditor.Experimental.GraphView; |  |  |  | using UnityEditor.Experimental.GraphView; | 
			
		
	
		
		
			
				
					
					|  |  |  | using UnityEngine; |  |  |  | using UnityEngine; | 
			
		
	
		
		
			
				
					
					|  |  |  | using UnityEngine.UIElements; |  |  |  | using UnityEngine.UIElements; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | using Edge = UnityEditor.Experimental.GraphView.Edge; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | namespace TNode.Editor.BaseViews{ |  |  |  | namespace TNode.Editor.BaseViews{ | 
			
		
	
		
		
			
				
					
					|  |  |  |     /* |  |  |  |     /* | 
			
		
	
	
		
		
			
				
					|  |  | @ -107,9 +109,13 @@ namespace TNode.Editor.BaseViews{ | 
			
		
	
		
		
			
				
					
					|  |  |  |      */ |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     public  abstract  class DataGraphView<T>:GraphView,IDataGraphView where T:GraphData{ |  |  |  |     public  abstract  class DataGraphView<T>:GraphView,IDataGraphView where T:GraphData{ | 
			
		
	
		
		
			
				
					
					|  |  |  |         private T _data; |  |  |  |         private T _data; | 
			
		
	
		
		
			
				
					
					|  |  |  |         private SearchWindowProvider _searchWindowProvider; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         private bool _isInspectorOn; |  |  |  |         private bool _isInspectorOn; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |          | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         private SearchWindowProvider _searchWindowProvider; | 
			
		
	
		
		
			
				
					
					|  |  |  |         private NodeInspector _nodeInspector; |  |  |  |         private NodeInspector _nodeInspector; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         public GraphEditor<T> Owner; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         private Dictionary<string,Node> _nodeDict = new(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |          | 
			
		
	
		
		
			
				
					
					|  |  |  |         public T Data{ |  |  |  |         public T Data{ | 
			
		
	
		
		
			
				
					
					|  |  |  |             get{ return _data; } |  |  |  |             get{ return _data; } | 
			
		
	
		
		
			
				
					
					|  |  |  |             set{ |  |  |  |             set{ | 
			
		
	
	
		
		
			
				
					|  |  | @ -129,8 +135,8 @@ namespace TNode.Editor.BaseViews{ | 
			
		
	
		
		
			
				
					
					|  |  |  |             foreach (var edge in edges){ |  |  |  |             foreach (var edge in edges){ | 
			
		
	
		
		
			
				
					
					|  |  |  |                 RemoveElement(edge); |  |  |  |                 RemoveElement(edge); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |             Dictionary<string,Node> nodeDict = new Dictionary<string, Node>(); |  |  |  |        | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             if (nodeDict == null) throw new ArgumentNullException(nameof(nodeDict)); |  |  |  |             if (_nodeDict == null) throw new ArgumentNullException(nameof(_nodeDict)); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             foreach (var dataNode in _data.NodeDictionary.Values){ |  |  |  |             foreach (var dataNode in _data.NodeDictionary.Values){ | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if(dataNode==null) |  |  |  |                 if(dataNode==null) | 
			
		
	
		
		
			
				
					
					|  |  |  |                     continue; |  |  |  |                     continue; | 
			
		
	
	
		
		
			
				
					|  |  | @ -138,25 +144,18 @@ namespace TNode.Editor.BaseViews{ | 
			
		
	
		
		
			
				
					
					|  |  |  |                 //Get the node type |  |  |  |                 //Get the node type | 
			
		
	
		
		
			
				
					
					|  |  |  |                 var nodeType = dataNode.GetType(); |  |  |  |                 var nodeType = dataNode.GetType(); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 //Get the derived type of NodeAttribute View from the node type |  |  |  |                 //Get the derived type of NodeAttribute View from the node type | 
			
		
	
		
		
			
				
					
					|  |  |  |                 var nodeViewType = typeof(NodeView<>).MakeGenericType(nodeType); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                  |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 //Fetch the node view from the node view type |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 var nodeView = NodeEditorExtensions.CreateInstance(nodeViewType); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             |  |  |  |             | 
			
		
	
		
		
			
				
					
					|  |  |  |                 //Cast the node view to the nodeViewType |  |  |  |                 var nodePos = Owner.graphEditorData.nodesData. | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 AddElement((Node)nodeView); |  |  |  |                     FirstOrDefault(x => x.nodeGuid == dataNode.id)?.nodePos??new Rect(0,0,200,200); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                  |  |  |  |                  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 ((INodeView)nodeView).SetNodeData(dataNode); |  |  |  |                 AddTNode(dataNode,nodePos); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                  |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 //Add the node view to the node dictionary |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 nodeDict.Add(dataNode.id, (Node)nodeView); |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             foreach (var edge in _data.NodeLinks){ |  |  |  |             foreach (var edge in _data.nodeLinks){ | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 var inputNode = _data.NodeDictionary[edge.inPort.nodeDataId]; |  |  |  |                 var inputNode = _data.NodeDictionary[edge.inPort.nodeDataId]; | 
			
		
	
		
		
			
				
					
					|  |  |  |                 var outputNode = _data.NodeDictionary[edge.outPort.nodeDataId]; |  |  |  |                 var outputNode = _data.NodeDictionary[edge.outPort.nodeDataId]; | 
			
		
	
		
		
			
				
					
					|  |  |  |                 var inputNodeView = nodeDict[inputNode.id]; |  |  |  |                 var inputNodeView = _nodeDict[inputNode.id]; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 var outputNodeView = nodeDict[outputNode.id]; |  |  |  |                 var outputNodeView = _nodeDict[outputNode.id]; | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 Edge newEdge = new Edge(){ |  |  |  |                 Edge newEdge = new Edge(){ | 
			
		
	
		
		
			
				
					
					|  |  |  |                     input = inputNodeView.inputContainer.Q<Port>(edge.inPort.portName), |  |  |  |                     input = inputNodeView.inputContainer.Q<Port>(edge.inPort.portName), | 
			
		
	
		
		
			
				
					
					|  |  |  |                     output = outputNodeView.outputContainer.Q<Port>(edge.outPort.portName) |  |  |  |                     output = outputNodeView.outputContainer.Q<Port>(edge.outPort.portName) | 
			
		
	
	
		
		
			
				
					|  |  | @ -165,7 +164,7 @@ namespace TNode.Editor.BaseViews{ | 
			
		
	
		
		
			
				
					
					|  |  |  |                 newEdge.output?.Connect(newEdge); |  |  |  |                 newEdge.output?.Connect(newEdge); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 AddElement(newEdge); |  |  |  |                 AddElement(newEdge); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |             nodeDict.Clear(); |  |  |  |             _nodeDict.Clear(); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |         //A Constructor for the DataGraphView ,never to override it |  |  |  |         //A Constructor for the DataGraphView ,never to override it | 
			
		
	
		
		
			
				
					
					|  |  |  |         public DataGraphView(){ |  |  |  |         public DataGraphView(){ | 
			
		
	
	
		
		
			
				
					|  |  | @ -235,9 +234,11 @@ namespace TNode.Editor.BaseViews{ | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         public void SaveEditorData(GraphEditorData graphEditorData){ |  |  |  |         public void SaveEditorData(GraphEditorData graphEditorData){ | 
			
		
	
		
		
			
				
					
					|  |  |  |             graphEditorData.nodesData.Clear(); |  |  |  |             graphEditorData.nodesData?.Clear(); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             //iterator nodes |  |  |  |             //iterator nodes | 
			
		
	
		
		
			
				
					
					|  |  |  |         |  |  |  |             if (graphEditorData.nodesData == null){ | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 graphEditorData.nodesData = new List<NodeEditorData>(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |             foreach (var node in this.nodes){ |  |  |  |             foreach (var node in this.nodes){ | 
			
		
	
		
		
			
				
					
					|  |  |  |                 var nodeEditorData = new NodeEditorData{ |  |  |  |                 var nodeEditorData = new NodeEditorData{ | 
			
		
	
		
		
			
				
					
					|  |  |  |                     nodePos = node.GetPosition(), |  |  |  |                     nodePos = node.GetPosition(), | 
			
		
	
	
		
		
			
				
					|  |  | @ -249,25 +250,14 @@ namespace TNode.Editor.BaseViews{ | 
			
		
	
		
		
			
				
					
					|  |  |  |                 EditorUtility.SetDirty(graphEditorData); |  |  |  |                 EditorUtility.SetDirty(graphEditorData); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |         public void LoadEditorData(GraphEditorData graphEditorData){ |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             //Load node position |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             foreach (var nodeEditorData in graphEditorData.nodesData){ |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 var node = this.nodes.Select(x => x as INodeView).First(x=>x?.GetNodeData().id==nodeEditorData.nodeGuid); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                  |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (node != null){ |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     ((GraphElement)node).SetPosition(nodeEditorData.nodePos); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |          |  |  |  |          | 
			
		
	
		
		
			
				
					
					|  |  |  |         public  void SaveWithEditorData(GraphEditorData graphEditorData){ |  |  |  |         public  void SaveWithEditorData(GraphEditorData graphEditorData){ | 
			
		
	
		
		
			
				
					
					|  |  |  |             SaveEditorData(graphEditorData); |  |  |  |             SaveEditorData(graphEditorData); | 
			
		
	
		
		
			
				
					
					|  |  |  |             SaveGraphData(); |  |  |  |             SaveGraphData(); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         private void SaveGraphData(){ |  |  |  |         private void SaveNode(){ | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |          | 
			
		
	
		
		
			
				
					
					|  |  |  |             foreach (var node in nodes){ |  |  |  |             foreach (var node in nodes){ | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (node is INodeView nodeView){ |  |  |  |                 if (node is INodeView nodeView){ | 
			
		
	
		
		
			
				
					
					|  |  |  |                     var nodeData = nodeView.GetNodeData(); |  |  |  |                     var nodeData = nodeView.GetNodeData(); | 
			
		
	
	
		
		
			
				
					|  |  | @ -276,11 +266,13 @@ namespace TNode.Editor.BaseViews{ | 
			
		
	
		
		
			
				
					
					|  |  |  |                     } |  |  |  |                     } | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |             //force edge to write as links |  |  |  |         } | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         private void SaveEdge(){ | 
			
		
	
		
		
			
				
					
					|  |  |  |             foreach (var edge in edges){ |  |  |  |             foreach (var edge in edges){ | 
			
		
	
		
		
			
				
					
					|  |  |  |                 var inputNode = edge.input.node as INodeView; |  |  |  |                 var inputNode = edge.input.node as INodeView; | 
			
		
	
		
		
			
				
					
					|  |  |  |                 var outputNode = edge.output.node as INodeView; |  |  |  |                 var outputNode = edge.output.node as INodeView; | 
			
		
	
		
		
			
				
					
					|  |  |  |                 var links = new List<NodeLink>(); |  |  |  |                 var links = new List<NodeLink>(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 Debug.Log($"Edge{inputNode},{outputNode}"); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (inputNode != null && outputNode != null){ |  |  |  |                 if (inputNode != null && outputNode != null){ | 
			
		
	
		
		
			
				
					
					|  |  |  |                     var inputNodeData = inputNode.GetNodeData(); |  |  |  |                     var inputNodeData = inputNode.GetNodeData(); | 
			
		
	
		
		
			
				
					
					|  |  |  |                     var outputNodeData = outputNode.GetNodeData(); |  |  |  |                     var outputNodeData = outputNode.GetNodeData(); | 
			
		
	
	
		
		
			
				
					|  |  | @ -292,15 +284,24 @@ namespace TNode.Editor.BaseViews{ | 
			
		
	
		
		
			
				
					
					|  |  |  |                         nodeDataId = outputNodeData.id, |  |  |  |                         nodeDataId = outputNodeData.id, | 
			
		
	
		
		
			
				
					
					|  |  |  |                         portName = edge.output.name |  |  |  |                         portName = edge.output.name | 
			
		
	
		
		
			
				
					
					|  |  |  |                     }); |  |  |  |                     }); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     links.Add(newNodeLink); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 _data.NodeLinks = links; |  |  |  |                 _data.nodeLinks = links; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                  |  |  |  |                  | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         private void SaveGraphData(){ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             _data.NodeDictionary.Clear(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |    | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             SaveNode(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             SaveEdge(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     | 
			
		
	
		
		
			
				
					
					|  |  |  |             EditorUtility.SetDirty(_data); |  |  |  |             EditorUtility.SetDirty(_data); | 
			
		
	
		
		
			
				
					
					|  |  |  |             AssetDatabase.SaveAssets(); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         public override List<Port> GetCompatiblePorts(Port startPort, NodeAdapter nodeAdapter){ |  |  |  |         public override List<Port> GetCompatiblePorts(Port startPort, NodeAdapter nodeAdapter){ | 
			
		
	
		
		
			
				
					
					|  |  |  |             return ports.Where(x => x.portType == startPort.portType).ToList(); |  |  |  |             return ports.Where(x => x.portType == startPort.portType).ToList(); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
	
		
		
			
				
					|  |  | @ -316,7 +317,7 @@ namespace TNode.Editor.BaseViews{ | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         public void AddTNode(NodeData nodeData, Rect rect){ |  |  |  |         public void AddTNode(NodeData nodeData, Rect rect){ | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (NodeEditorExtensions.CreateNodeViewFromNodeType(nodeData.GetType()) is GraphElement nodeView){ |  |  |  |             if (NodeEditorExtensions.CreateNodeViewFromNodeType(nodeData.GetType()) is Node nodeView){ | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 nodeView.SetPosition(rect); |  |  |  |                 nodeView.SetPosition(rect); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 AddElement(nodeView); |  |  |  |                 AddElement(nodeView); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 //Add a select callback to the nodeView |  |  |  |                 //Add a select callback to the nodeView | 
			
		
	
	
		
		
			
				
					|  |  | @ -333,6 +334,7 @@ namespace TNode.Editor.BaseViews{ | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if(nodeView is INodeView nodeViewInterface){ |  |  |  |                 if(nodeView is INodeView nodeViewInterface){ | 
			
		
	
		
		
			
				
					
					|  |  |  |                     nodeViewInterface.SetNodeData(nodeData); |  |  |  |                     nodeViewInterface.SetNodeData(nodeData); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 _nodeDict.Add(nodeData.id, nodeView); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | 
 |