using System; using System.Collections.Generic; using System.Linq; using System.Text; using UnityEngine; using UnityEngine.Graphing; namespace UnityEditor.Graphing.Util { [Serializable] internal class CopyPasteGraph : ISerializationCallbackReceiver { [NonSerialized] private HashSet m_Edges = new HashSet(); [NonSerialized] private HashSet m_Nodes = new HashSet(); [SerializeField] List m_SerializableNodes = new List(); [SerializeField] List m_SerializableEdges = new List(); public virtual void AddNode(INode node) { m_Nodes.Add(node); } public void AddEdge(IEdge edge) { m_Edges.Add(edge); } public IEnumerable GetNodes() where T : INode { return m_Nodes.OfType(); } public IEnumerable edges { get { return m_Edges; } } public virtual void OnBeforeSerialize() { m_SerializableNodes = SerializationHelper.Serialize(m_Nodes); m_SerializableEdges = SerializationHelper.Serialize(m_Edges); } public virtual void OnAfterDeserialize() { var nodes = SerializationHelper.Deserialize(m_SerializableNodes, null); m_Nodes.Clear(); foreach (var node in nodes) m_Nodes.Add(node); m_SerializableNodes = null; var edges = SerializationHelper.Deserialize(m_SerializableEdges, null); m_Edges.Clear(); foreach (var edge in edges) m_Edges.Add(edge); m_SerializableEdges = null; } } }