Beispiel #1
0
        internal void ReceiveMessage(SocketEndpoint sendingEndpoint, BinaryReader reader)
        {
            ShortID typeID = reader.ReadShortID();

            if (typeID == SynchronizedSceneChangeTypeGlobalShaderProperty)
            {
                ReadGlobalShaderProperties(reader);
            }
            else
            {
                if (shouldClearScene)
                {
                    ClearScene();
                    shouldClearScene = false;
                }

                IComponentBroadcasterService componentService;
                if (componentBroadcasterServices.TryGetValue(typeID, out componentService))
                {
                    short id = reader.ReadInt16();
                    ComponentBroadcasterChangeType changeType = (ComponentBroadcasterChangeType)reader.ReadByte();

                    switch (changeType)
                    {
                    case ComponentBroadcasterChangeType.Created:
                    {
                        GameObject mirror = GetOrCreateMirror(id);
                        componentService.Create(mirror);
                    }
                    break;

                    case ComponentBroadcasterChangeType.Updated:
                    {
                        GameObject mirror = GetOrCreateMirror(id);
                        componentService.Read(sendingEndpoint, reader, mirror);
                    }
                    break;

                    case ComponentBroadcasterChangeType.Destroyed:
                    {
                        GameObject mirror = FindGameObjectWithId(id);
                        if (mirror != null)
                        {
                            componentService.Destroy(mirror);
                        }
                    }
                    break;
                    }
                }
            }
        }
Beispiel #2
0
        internal void LerpReceiveMessage(BinaryReader reader, float lerpVal)
        {
            ShortID typeID = reader.ReadShortID();

            IComponentBroadcasterService componentService;

            if (componentBroadcasterServices.TryGetValue(typeID, out componentService))
            {
                short id = reader.ReadInt16();
                ComponentBroadcasterChangeType changeType = (ComponentBroadcasterChangeType)reader.ReadByte();
                if (changeType == ComponentBroadcasterChangeType.Updated)
                {
                    GameObject mirror;
                    if (objectMirrors.TryGetValue(id, out mirror))
                    {
                        componentService.LerpRead(reader, mirror, lerpVal);
                    }
                }
            }
        }
 /// <summary>
 /// Writes <see cref="TransformObserver"/> information to a network message for sending to other devices
 /// </summary>
 /// <param name="message">network message to send</param>
 /// <param name="TransformObserver">transform that has changed</param>
 /// <param name="changeType">type of changed that occurred for the specified component</param>
 public void WriteHeader(BinaryWriter message, TransformObserver TransformObserver, ComponentBroadcasterChangeType changeType = ComponentBroadcasterChangeType.Updated)
 {
     StateSynchronizationSceneManager.Instance.WriteSynchronizeCommandHeader(message);
     message.Write(GetID().Value);
     message.Write(TransformObserver.Id);
     message.Write((byte)changeType);
 }