コード例 #1
0
        protected virtual void HandleClientUpdateSyncField(LiteNetLibMessageHandler messageHandler)
        {
            // Field updated at owner-client, if this is server then multicast message to other clients
            if (!IsServer)
            {
                return;
            }
            NetDataReader         reader = messageHandler.reader;
            LiteNetLibElementInfo info   = LiteNetLibElementInfo.DeserializeInfo(reader);
            LiteNetLibIdentity    identity;

            if (Assets.TryGetSpawnedObject(info.objectId, out identity))
            {
                LiteNetLibSyncField syncField = identity.Behaviours[info.behaviourIndex].GetSyncField(info);
                // Sync field at server also have to be client multicast to allow it to multicast to other clients
                if (syncField != null && syncField.syncMode == LiteNetLibSyncField.SyncMode.ClientMulticast)
                {
                    // If this is not host, set data then pass to other clients because host already set data
                    if (!identity.IsOwnerClient)
                    {
                        syncField.Deserialize(reader, false);
                    }
                    // Send to other clients
                    foreach (long connectionId in GetConnectionIds())
                    {
                        if (identity.IsSubscribedOrOwning(connectionId))
                        {
                            syncField.SendUpdate(false, connectionId);
                        }
                    }
                }
            }
        }
コード例 #2
0
 internal LiteNetLibSyncField ProcessSyncField(LiteNetLibSyncField syncField, NetDataReader reader, bool isInitial)
 {
     if (syncField == null)
     {
         return(null);
     }
     syncField.Deserialize(reader, isInitial);
     return(syncField);
 }
コード例 #3
0
        internal LiteNetLibSyncField ProcessSyncField(LiteNetLibElementInfo info, NetDataReader reader, bool isInitial)
        {
            LiteNetLibSyncField syncField = GetSyncField(info);

            if (syncField == null)
            {
                if (Manager.LogError)
                {
                    Debug.LogError("[" + name + "] [" + TypeName + "] cannot process sync field, fieldId [" + info.elementId + "] not found.");
                }
                return(null);
            }
            syncField.Deserialize(reader, isInitial);
            return(syncField);
        }
コード例 #4
0
        protected virtual void HandleClientUpdateSyncField(LiteNetLibMessageHandler messageHandler)
        {
            // Field updated at owner-client, if this is server then multicast message to other clients
            if (!IsServer)
            {
                return;
            }
            NetDataReader         reader = messageHandler.reader;
            LiteNetLibElementInfo info   = LiteNetLibElementInfo.DeserializeInfo(reader);
            LiteNetLibIdentity    identity;

            if (Assets.TryGetSpawnedObject(info.objectId, out identity))
            {
                LiteNetLibSyncField syncField = identity.GetSyncField(info);
                // Sync field at server also have to be client multicast to allow it to multicast to other clients
                if (syncField != null && syncField.syncMode == LiteNetLibSyncField.SyncMode.ClientMulticast)
                {
                    // If this is server but it is not host, set data (deserialize) then pass to other clients
                    // If this is host don't set data because it's already did (in LiteNetLibSyncField class)
                    if (!identity.IsOwnerClient)
                    {
                        syncField.Deserialize(reader, false);
                    }
                    // Send to other clients
                    foreach (long connectionId in GetConnectionIds())
                    {
                        // Don't send the update to owner client because it was updated before send update to server
                        if (connectionId == messageHandler.connectionId)
                        {
                            continue;
                        }
                        // Send update to clients except owner client
                        if (identity.IsSubscribedOrOwning(connectionId))
                        {
                            syncField.SendUpdate(false, connectionId);
                        }
                    }
                }
            }
        }