// Serialize this node and its connected nodes recursively
        public int SerializeRecursively(Dictionary <ReferenceNode, int> nodeToIndex, List <SearchResult.SerializableNode> serializedNodes)
        {
            int index;

            if (nodeToIndex.TryGetValue(this, out index))
            {
                return(index);
            }

            SearchResult.SerializableNode serializedNode = new SearchResult.SerializableNode()
            {
                instanceId    = instanceId ?? 0,
                isUnityObject = instanceId.HasValue,
                description   = description
            };

            index             = serializedNodes.Count;
            nodeToIndex[this] = index;
            serializedNodes.Add(serializedNode);

            if (links.Count > 0)
            {
                serializedNode.links            = new List <int>(links.Count);
                serializedNode.linkDescriptions = new List <string>(links.Count);

                for (int i = 0; i < links.Count; i++)
                {
                    serializedNode.links.Add(links[i].targetNode.SerializeRecursively(nodeToIndex, serializedNodes));
                    serializedNode.linkDescriptions.Add(links[i].description);
                }
            }

            return(index);
        }
        // Deserialize this node and its links from the serialized data
        public void Deserialize(SearchResult.SerializableNode serializedNode, List <ReferenceNode> allNodes)
        {
            if (serializedNode.isUnityObject)
            {
                instanceId = serializedNode.instanceId;
            }
            else
            {
                instanceId = null;
            }

            description = serializedNode.description;

            if (serializedNode.links != null)
            {
                for (int i = 0; i < serializedNode.links.Count; i++)
                {
                    links.Add(new Link(allNodes[serializedNode.links[i]], serializedNode.linkDescriptions[i]));
                }
            }
        }