Exemplo n.º 1
0
        /// <summary>
        /// Invokes all matching methods contained in nodes on the given network.
        /// </summary>
        /// <param name="publishedData">The data passed to the methods to be invoked.</param>
        /// <param name="publisher">Typically, the object that is invoking publish.</param>
        /// <param name="network">The network to publish to.</param>
        protected static void PublishToNetwork(object publishedData, object publisher, Tags tags, string network)
        {
            CommunicationNode current = null;

            if (!root.TryGetValue(network, out current))
            {
                return;
            }

            List <CommunicationNode> orphanList = null;

            //iterate over all nodes on the network
            do
            {
                //keep track of orphaned nodes (unity objects that have been deleted will register as null)
                if (current.NodeOwner == null)
                {
                    if (orphanList == null)
                    {
                        orphanList = new List <CommunicationNode>();
                    }

                    orphanList.Add(current);
                    continue;
                }

                //prevent sources from publishing to themselves
                if (current.allowPublishToSelf || current.NodeOwner != publisher)
                {
                    if (debugPrintAllActivity)
                    {
                        DebugLogger.Log("Publish is Invoking handler for : " + publishedData.GetType().Name + " on " + GetObjectName(current.NodeOwner) + " sent by " + GetObjectName(publisher));
                    }
                    bool result = current.InvokeMatchingCallback(publishedData, publisher, tags);
                    if (result)
                    {
                        debugPublishWasHandled = true;
                    }
                }

                current = current.next[network];
            } while(current != root[network]);

            if (orphanList != null)
            {
                //remove/clean up orphaned nodes
                for (int i = 0; i < orphanList.Count; ++i)
                {
                    RemoveNode(orphanList[i]);
                }
            }
        }