public void LoadData(GraphData graphData)
 {
     this.graphData = graphData;
     if (graphData != null && graphData.__rootGuid != null && graphData.__rootGuid != "")
     {
         rootGuid = graphData.__rootGuid;
         graphData.__nodes.ForEach(_nodeData => {
             if (_nodeData.guid == graphData.__rootGuid)
             {
                 //_nodeData.name = "Entry"; // graphData.name;
                 AddNode(new RootNode().Init(_nodeData), true);
             }
         });
     }
     else if (graphData != null)
     {
         NodeData _newRootNode = new NodeData()
         {
             name = "Graph Entry", position = new Vector2(250, 100)
         };
         JSONGraphData _rootJSONGraphData = new JSONGraphData();
         _rootJSONGraphData.data = JsonUtility.ToJson(graphData.GetRootPortData());
         _newRootNode.dataJSON   = JsonUtility.ToJson(_rootJSONGraphData);
         rootGuid = AddNode(new RootNode().Init(_newRootNode), true).guid;
     }
     GenerateNodes();
     ConnectNodes();
     // Add Search Window
     AddSearchWindow(_editorWindow, graphData);
 }
        public CoreNode Init(NodeData nodeData)
        {
            title = nodeData.name;
            guid  = (nodeData.guid != null) ? nodeData.guid : System.Guid.NewGuid().ToString();
            Rect _placement = new Rect();

            _placement.position = nodeData.position;
            _placement.size     = nodeData.size;
            this.SetPosition(_placement);
            jsonData = JsonUtility.FromJson(nodeData.dataJSON, typeof(JSONGraphData)) as JSONGraphData;
            if (jsonData == null)
            {
                jsonData = new JSONGraphData();
            }
            OnInitialize();
            return(this);
        }
        /*public void getPortDetails(string nodeGuid = null)
         * {
         *  List<LinkData> links = this.__links.Where(l =>
         *  {
         *      return (nodeGuid != null) ? (l.sourceGuid == nodeGuid) : (l.sourceGuid == this.__rootGuid);
         *  }).ToList();
         *  if (links != null && links.Count > 0)
         *  {
         *      links.ForEach(_linkData =>
         *      {
         *          NodeData _nodeData = this.__nodes.First(n => n.guid == _linkData.targetGuid);
         *          JSONGraphData jsonData = JsonUtility.FromJson(_nodeData.dataJSON, typeof(JSONGraphData)) as JSONGraphData;
         *          Debug.Log(_nodeData.dataJSON);
         *      }
         *      );
         *  }
         * }
         * public List<NodeDetail> getNodeDetails(string nodeGuid = null)
         * {
         *  List<NodeDetail> nodeDetails = new List<NodeDetail>();
         *  List<LinkData> links = this.__links.Where(l =>
         *  {
         *      return (nodeGuid != null) ? (l.sourceGuid == nodeGuid) : (l.sourceGuid == this.__rootGuid);
         *  }).ToList();
         *  if (links != null && links.Count > 0)
         *  {
         *      links.ForEach(_linkData =>
         *      {
         *          NodeData _nodeData = this.__nodes.First(n => n.guid == _linkData.targetGuid);
         *          JSONGraphData jsonData = JsonUtility.FromJson(_nodeData.dataJSON, typeof(JSONGraphData)) as JSONGraphData;
         *          NodeDetail nodeDetail = new NodeDetail() {
         *              guid = _nodeData.guid,
         *              name = _nodeData.name,
         *              type = _nodeData.type,
         *              dataJSON = _nodeData.dataJSON
         *          };
         *          nodeDetails.Add(nodeDetail);
         *      }
         *      );
         *  }
         *  return nodeDetails;
         * }*/
        public NodeDetail getNodeDetail(string nodeGuid = null)
        {
            if (nodeGuid == null)
            {
                nodeGuid = this.__rootGuid;
            }
            NodeData      _nodeData  = this.__nodes.First(n => n.guid == nodeGuid);
            JSONGraphData jsonData   = JsonUtility.FromJson(_nodeData.dataJSON, typeof(JSONGraphData)) as JSONGraphData;
            NodeDetail    nodeDetail = new NodeDetail()
            {
                guid     = _nodeData.guid,
                name     = _nodeData.name,
                type     = _nodeData.type,
                dataJSON = jsonData.data
            };

            List <LinkData> links = this.__links.Where(l =>
            {
                return(l.sourceGuid == nodeGuid);
            }).ToList();

            if (links != null && links.Count > 0)
            {
                links.ForEach(_linkData =>
                {
                    NodeData _linkNodeData      = this.__nodes.First(n => n.guid == _linkData.targetGuid);
                    JSONGraphData _linkJsonData = JsonUtility.FromJson(_nodeData.dataJSON, typeof(JSONGraphData)) as JSONGraphData;
                    NodeDetail _linkNodeDetail  = new NodeDetail()
                    {
                        guid     = _linkNodeData.guid,
                        name     = _linkNodeData.name,
                        type     = _linkNodeData.type,
                        dataJSON = _linkJsonData.data,
                        connectedSourcePortName = _linkData.sourcePortName,
                        connectedTargetPortName = _linkData.targetPortName
                    };
                    nodeDetail.connectedNodes.Add(_linkNodeDetail);
                }
                              );
            }
            return(nodeDetail);
        }
 public void Process(ProcessPassData passData)
 {
     //Debug.Log($"Start Processing {JsonUtility.ToJson(passData)}");
     if (graphs.ContainsKey(passData.graphId) && eventDictionary.ContainsKey(passData.graphId))
     {
         GraphData       _data = graphs[passData.graphId];
         List <LinkData> links = _data.__links.Where(l =>
         {
             return(l.sourceGuid == passData.guid && l.sourcePortName == passData.flow);
         }).ToList();
         GraphProcessEvent listners = eventDictionary[passData.graphId];
         if (links != null && links.Count > 0)
         {
             links.ForEach(_linkData => {
                 NodeData _nodeData     = _data.__nodes.First(n => n.guid == _linkData.targetGuid);
                 JSONGraphData jsonData = JsonUtility.FromJson(_nodeData.dataJSON, typeof(JSONGraphData)) as JSONGraphData;
                 ProcessReceiveData processReceiveData = new ProcessReceiveData
                 {
                     guid           = _nodeData.guid,
                     customDataJson = jsonData.data,
                     type           = _nodeData.type
                 };
                 jsonData.outputPorts.ForEach(portData => {
                     ProcessOption processOption = new ProcessOption
                     {
                         name = portData.name,
                         type = portData.portType
                     };
                     _data.__links.ForEach(l => {
                         if (l.sourceGuid == _linkData.targetGuid && l.sourcePortName == portData.name)
                         {
                             processOption.targetConnection.Add(new TargetPort
                             {
                                 name = l.targetPortName,
                                 guid = l.targetGuid,
                                 type = portData.portType
                             });
                         }
                     });
                     if (portData.portType == "UnityNodeGraph.PortTypeFlow")
                     {
                         processReceiveData.flows.Add(processOption);
                     }
                     else if (portData.portType == "UnityNodeGraph.PortTypeAction")
                     {
                         // search for port connection
                         processReceiveData.actions.Add(processOption);
                     }
                     else
                     {
                         processReceiveData.customOptions.Add(processOption);
                     }
                 });
                 listners.Invoke(processReceiveData);
             });
         }
         else
         {
             NodeData           _nodeData          = _data.__nodes.First(n => n.guid == passData.guid);
             JSONGraphData      jsonData           = JsonUtility.FromJson(_nodeData.dataJSON, typeof(JSONGraphData)) as JSONGraphData;
             ProcessReceiveData processReceiveData = new ProcessReceiveData
             {
                 guid           = _nodeData.guid,
                 customDataJson = jsonData.data,
                 type           = _nodeData.type
             };
             listners.Invoke(processReceiveData);
         }
     }
     else
     {
         Debug.Log($"Didn't find GraphId{passData.graphId}");
     }
 }