public static GraphElement Deserialize <TGraphView>(this ISerializedGraphElement serializedGraphElement, GraphElement graphElement, TGraphView graphView) where TGraphView : GraphView, IGraphViewCallback
 {
     if (graphView == null)
     {
         throw new ArgumentNullException(nameof(graphView));
     }
     if (graphElement == null)
     {
         var typeName = serializedGraphElement.TypeName;
         if (!s_ConstructorInfos.TryGetValue(typeName, out var info))
         {
             info = Type.GetType(typeName).GetConstructor(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[0], null);
             s_ConstructorInfos[typeName] = info;
         }
         graphElement = info.Invoke(new object[0]) as GraphElement;
         graphView.AddElement(graphElement);
         if (graphElement is IFieldHolder fieldHolder)
         {
             var fieldRegister = new FieldValuesGetter(serializedGraphElement, graphView);
             fieldHolder.RegisterFields(fieldRegister);
         }
     }
     graphElement.persistenceKey = serializedGraphElement.Guid;
     graphElement.SetPosition(serializedGraphElement.Position);
     if (graphElement is Node node)
     {
         var guidsQueue = new Queue <string>(serializedGraphElement.ReferenceGuids);
         node.Query <Port>().ForEach(port => port.persistenceKey = guidsQueue.Dequeue());
     }
     return(graphElement);
 }
Пример #2
0
 public FieldValuesGetter(ISerializedGraphElement serializedGraphElement, IGraphViewCallback graphView)
 {
     m_SerializedGraphElement = serializedGraphElement;
     m_GraphView = graphView;
 }