Beispiel #1
0
    public void ReplicationReceive(P2PNetworkReader reader, bool initial_state)
    {
        if (P2PLogFilter.logPedantic)
        {
            Debug.Log(string.Format("ReplicationReceive called for {0} with guid {1}", base.name, this.GetGuidComponent.GetGuid()), this);
        }
        int num = reader.ReadInt32();

        if (num <= this.m_Revision && !initial_state)
        {
            return;
        }
        ReplicationComponent.s_DeserializedComponent = this;
        this.m_Revision                = num;
        this.m_LastReplicationTime     = Time.time;
        this.m_LastReplicationTimeReal = Time.realtimeSinceStartup;
        short num2 = reader.ReadInt16();

        if (this.m_OwnerPeer.GetHostId() != num2)
        {
            this.ReplOnChangedOwner(ReplTools.GetPeerById(num2));
            if (this.m_OwnerPeer == ReplTools.GetLocalPeer())
            {
                this.ReplRequestOwnership();
            }
        }
        this.ReplBlockChangeOwnership(!reader.ReadBoolean());
        for (int i = 0; i < this.GetReplBehaviours.Length; i++)
        {
            IReplicatedBehaviour replicatedBehaviour = this.GetReplBehaviours[i];
            if (replicatedBehaviour as UnityEngine.Object == null)
            {
                if (reader.ReadBoolean())
                {
                    ReplicationComponent.s_DeserializedComponent = null;
                    return;
                }
                this.m_ReplBehavioursFlag[i] = false;
            }
            else if (reader.ReadBoolean())
            {
                int uniqueIdForType = replicatedBehaviour.GetUniqueIdForType();
                int num3            = reader.ReadInt32();
                if (uniqueIdForType != num3)
                {
                    ReplicationComponent.s_DeserializedComponent = null;
                    return;
                }
                replicatedBehaviour.OnReplicationDeserialize(reader, initial_state);
                this.CallReplicationDeserialize_Gen(replicatedBehaviour, reader, initial_state);
                this.m_ReplBehavioursFlag[i] = true;
            }
            else
            {
                this.m_ReplBehavioursFlag[i] = false;
            }
        }
        for (int j = 0; j < this.GetReplBehaviours.Length; j++)
        {
            if (this.m_ReplBehavioursFlag[j])
            {
                IReplicatedBehaviour replicatedBehaviour2 = this.GetReplBehaviours[j];
                replicatedBehaviour2.OnReplicationResolve();
                this.CallReplicationResolve_Gen(replicatedBehaviour2);
            }
        }
        if (P2PConnection.s_Size > reader.Position && !initial_state)
        {
            Debug.LogError(string.Format("Didn't read whole buffer! (number of bytes unread: {0})", P2PConnection.s_Size - reader.Position), this);
        }
        ReplicationComponent.s_DeserializedComponent = null;
    }