Ejemplo n.º 1
0
        internal void OnDeserializeAllSafely(NetworkBehaviour[] components, NetworkReader reader, bool initialState)
        {
            foreach (NetworkBehaviour comp in components)
            {
                // extract data length and data safely, untouched by user code
                // -> returns empty array if length is 0, so .Length is always the proper length
                byte[] bytes = reader.ReadBytesAndSize();
                if (LogFilter.logDebug)
                {
                    Debug.Log("OnDeserializeSafely extracted: " + comp.name + " component=" + comp.GetType() + " sceneId=" + m_SceneId + " length=" + bytes.Length);
                }

                // call OnDeserialize with a temporary reader, so that the
                // original one can't be messed with. we also wrap it in a
                // try-catch block so there's no way to mess up another
                // component's deserialization
                try
                {
                    comp.OnDeserialize(new NetworkReader(bytes), initialState);
                }
                catch (Exception e)
                {
                    // show a detailed error and let the user know what went wrong
                    Debug.LogError("OnDeserialize failed for: object=" + name + " component=" + comp.GetType() + " sceneId=" + m_SceneId + " length=" + bytes.Length + ". Possible Reasons:\n  * Do " + comp.GetType() + "'s OnSerialize and OnDeserialize calls write the same amount of data(" + bytes.Length + " bytes)? \n  * Was there an exception in " + comp.GetType() + "'s OnSerialize/OnDeserialize code?\n  * Are the server and client the exact same project?\n  * Maybe this OnDeserialize call was meant for another GameObject? The sceneIds can easily get out of sync if the Hierarchy was modified only in the client OR the server. Try rebuilding both.\n\n" + e.ToString());
                }
            }
        }
Ejemplo n.º 2
0
 internal bool HandleFragment(NetworkReader reader)
 {
     if (reader.ReadByte() == 0)
     {
         if (!readingFragment)
         {
             fragmentBuffer.SeekZero();
             readingFragment = true;
         }
         byte[] array = reader.ReadBytesAndSize();
         fragmentBuffer.WriteBytes(array, (ushort)array.Length);
         return(false);
     }
     readingFragment = false;
     return(true);
 }
Ejemplo n.º 3
0
        internal bool HandleFragment(NetworkReader reader)
        {
            int state = reader.ReadByte();

            if (state == 0)
            {
                if (readingFragment == false)
                {
                    fragmentBuffer.SeekZero();
                    readingFragment = true;
                }

                byte[] data = reader.ReadBytesAndSize();
                fragmentBuffer.WriteBytes(data, (ushort)data.Length);
                return(false);
            }
            else
            {
                readingFragment = false;
                return(true);
            }
        }
Ejemplo n.º 4
0
        internal bool HandleFragment(NetworkReader reader)
        {
            bool result;

            if (reader.ReadByte() == 0)
            {
                if (!this.readingFragment)
                {
                    this.fragmentBuffer.SeekZero();
                    this.readingFragment = true;
                }
                byte[] array = reader.ReadBytesAndSize();
                this.fragmentBuffer.WriteBytes(array, (ushort)array.Length);
                result = false;
            }
            else
            {
                this.readingFragment = false;
                result = true;
            }
            return(result);
        }