Exemplo n.º 1
0
        /// <inheritdoc />
        public virtual void TinyDeserialize(NetDataReader reader, bool firstStateUpdate)
        {
            if (firstStateUpdate)
            {
                NetworkID = reader.GetInt();
            }

            if (!firstStateUpdate)
            {
                int dFlag = reader.GetInt();

                TinyNetStateSyncer.IntToDirtyFlag(dFlag, _dirtyFlag);
            }

            Type type;
            int  maxSyncVar = propertiesName.Length;

            for (int i = 0; i < maxSyncVar; i++)
            {
                if (!firstStateUpdate && _dirtyFlag[i] == false)
                {
                    continue;
                }

                type = propertiesTypes[i];

                if (type == typeof(byte))
                {
                    byteAccessor[propertiesName[i]].Set(this, reader.GetByte());
                }
                else if (type == typeof(sbyte))
                {
                    sbyteAccessor[propertiesName[i]].Set(this, reader.GetSByte());
                }
                else if (type == typeof(short))
                {
                    shortAccessor[propertiesName[i]].Set(this, reader.GetShort());
                }
                else if (type == typeof(ushort))
                {
                    ushortAccessor[propertiesName[i]].Set(this, reader.GetUShort());
                }
                else if (type == typeof(int))
                {
                    intAccessor[propertiesName[i]].Set(this, reader.GetInt());
                }
                else if (type == typeof(uint))
                {
                    uintAccessor[propertiesName[i]].Set(this, reader.GetUInt());
                }
                else if (type == typeof(long))
                {
                    longAccessor[propertiesName[i]].Set(this, reader.GetLong());
                }
                else if (type == typeof(ulong))
                {
                    ulongAccessor[propertiesName[i]].Set(this, reader.GetULong());
                }
                else if (type == typeof(float))
                {
                    floatAccessor[propertiesName[i]].Set(this, reader.GetFloat());
                }
                else if (type == typeof(double))
                {
                    doubleAccessor[propertiesName[i]].Set(this, reader.GetDouble());
                }
                else if (type == typeof(bool))
                {
                    boolAccessor[propertiesName[i]].Set(this, reader.GetBool());
                }
                else if (type == typeof(string))
                {
                    stringAccessor[propertiesName[i]].Set(this, reader.GetString());
                }
            }
        }