コード例 #1
0
        public void StopListening(string eventName, UnityAction <ProcessReceiveData> listener)
        {
            if (graphProcessor == null)
            {
                return;
            }
            GraphProcessEvent thisEvent = null;

            if (instance.eventDictionary.TryGetValue(eventName, out thisEvent))
            {
                thisEvent.RemoveListener(listener);
            }
        }
コード例 #2
0
        public string RegisterProcessor(out string _graphId, GraphData data, UnityAction <ProcessReceiveData> listener, string jsonData = "{}")
        {
            _graphId = System.Guid.NewGuid().ToString();
            if (data == null)
            {
                Debug.Log("GraphData passed to GraphProcessor.RegisterProcessor is empty");
                return(null);
            }
            graphs.Add(_graphId, data);

            GraphProcessEvent thisEvent = null;

            if (instance.eventDictionary.TryGetValue(_graphId, out thisEvent))
            {
                thisEvent.AddListener(listener);
            }
            else
            {
                thisEvent = new GraphProcessEvent();
                thisEvent.AddListener(listener);
                instance.eventDictionary.Add(_graphId, thisEvent);
            }
            Process(new ProcessPassData
            {
                graphId  = _graphId,
                guid     = data.__rootGuid,
                flow     = "Action",
                jsonData = jsonData
            });
            Process(new ProcessPassData {
                graphId  = _graphId,
                guid     = data.__rootGuid,
                flow     = "Flow",
                jsonData = jsonData
            });
            return(_graphId);
        }
コード例 #3
0
 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}");
     }
 }