コード例 #1
0
 public void Send(NetworkId objectid, ushort componentid, ReferenceCountedSceneGraphMessage message)
 {
     message.objectid    = objectid;
     message.componentid = componentid;
     scene.Send(message.buffer);
 }
コード例 #2
0
        /// <summary>
        /// This checks all connections for messages and fans them out into the individual recieve queues
        /// </summary>
        public void ReceiveConnectionMessages()
        {
            ReferenceCountedMessage m;

            foreach (var c in connections)
            {
                do
                {
                    m = c.Receive();
                    if (m != null)
                    {
                        try
                        {
                            var sgbmessage = new ReferenceCountedSceneGraphMessage(m);
                            foreach (var item in objectProperties)
                            {
                                // Checks if the Unity object has been destroyed. When Unity objects are destroyed, the managed reference can remain around, but the object is invalid. Unity overrides the truth check to indicate this.

                                if (item.Key is UnityEngine.Object)
                                {
                                    if (!(item.Key as UnityEngine.Object))
                                    {
                                        actions.Add(() =>
                                        {
                                            try
                                            {
                                                objectProperties.Remove(item.Key);
                                            }
                                            catch (KeyNotFoundException)
                                            {
                                            }
                                        });
                                        continue;
                                    }
                                }

                                if (item.Key.Id == sgbmessage.objectid)
                                {
                                    INetworkComponent component = null;

                                    try
                                    {
                                        component = item.Value.components[sgbmessage.componentid];
                                    }
                                    catch (KeyNotFoundException)
                                    {
                                        continue;
                                    }

                                    try
                                    {
                                        Profiler.BeginSample("Component Message Processing " + component.ToString());
                                        component.ProcessMessage(sgbmessage);
                                    }
                                    catch (MissingReferenceException e)
                                    {
                                        if (component is UnityEngine.Object)
                                        {
                                            if (!(component as UnityEngine.Object))
                                            {
                                                item.Value.components.Remove(sgbmessage.componentid);
                                                return;
                                            }
                                        }

                                        throw e;
                                    }
                                    finally
                                    {
                                        Profiler.EndSample();
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Debug.LogException(e); // because otherwise this will not be visible to the main thread
                        }
                        finally
                        {
                            m.Release();
                        }
                    }
                    else
                    {
                        break;
                    }
                } while (true);
            }
        }
コード例 #3
0
        /// <summary>
        /// This checks all connections for messages and fans them out into the individual recieve queues
        /// </summary>
        public void ReceiveConnectionMessages()
        {
            ReferenceCountedMessage m;

            foreach (var c in connections)
            {
                do
                {
                    m = c.Receive();
                    if (m != null)
                    {
                        try
                        {
                            var sgbmessage = new ReferenceCountedSceneGraphMessage(m);

                            matching.Clear();
                            foreach (var item in objectProperties)
                            {
                                if (item.Key.Id == sgbmessage.objectid)
                                {
                                    matching.Add(item.Value);
                                }
                            }

                            foreach (var item in matching)
                            {
                                INetworkComponent component = null;

                                try
                                {
                                    component = item.components[sgbmessage.componentid];
                                }
                                catch (KeyNotFoundException)
                                {
                                    continue;
                                }

                                try
                                {
                                    //     Profiler.BeginSample("Component Message Processing " + component.ToString());
                                    component.ProcessMessage(sgbmessage);
                                }
                                catch (MissingReferenceException e)
                                {
                                    if (component is UnityEngine.Object)
                                    {
                                        if (!(component as UnityEngine.Object))
                                        {
                                            item.components.Remove(sgbmessage.componentid);
                                            return;
                                        }
                                    }

                                    throw e;
                                }
                                // finally
                                // {
                                //     Profiler.EndSample();
                                // }
                            }
                        }
                        catch (Exception e)
                        {
                            Debug.LogException(e); // because otherwise this will not be visible to the main thread
                        }
                        finally
                        {
                            m.Release();
                        }
                    }
                    else
                    {
                        break;
                    }
                } while (true);
            }
        }
コード例 #4
0
 public void Send(ReferenceCountedSceneGraphMessage message)
 {
     message.objectid    = networkObject.Id;
     message.componentid = componentId;
     scene.Send(message.buffer);
 }