Exemplo n.º 1
0
        /// <inheritdoc />
        public virtual void TinySerialize(NetDataWriter writer, bool firstStateUpdate)
        {
            if (firstStateUpdate)
            {
                writer.Put(NetworkID);
            }

            if (!firstStateUpdate)
            {
                writer.Put(TinyNetStateSyncer.DirtyFlagToInt(_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))
                {
                    writer.Put(byteAccessor[propertiesName[i]].Get(this));
                }
                else if (type == typeof(sbyte))
                {
                    writer.Put(sbyteAccessor[propertiesName[i]].Get(this));
                }
                else if (type == typeof(short))
                {
                    writer.Put(shortAccessor[propertiesName[i]].Get(this));
                }
                else if (type == typeof(ushort))
                {
                    writer.Put(ushortAccessor[propertiesName[i]].Get(this));
                }
                else if (type == typeof(int))
                {
                    writer.Put(intAccessor[propertiesName[i]].Get(this));
                }
                else if (type == typeof(uint))
                {
                    writer.Put(uintAccessor[propertiesName[i]].Get(this));
                }
                else if (type == typeof(long))
                {
                    writer.Put(longAccessor[propertiesName[i]].Get(this));
                }
                else if (type == typeof(ulong))
                {
                    writer.Put(ulongAccessor[propertiesName[i]].Get(this));
                }
                else if (type == typeof(float))
                {
                    writer.Put(floatAccessor[propertiesName[i]].Get(this));
                }
                else if (type == typeof(double))
                {
                    writer.Put(doubleAccessor[propertiesName[i]].Get(this));
                }
                else if (type == typeof(bool))
                {
                    writer.Put(boolAccessor[propertiesName[i]].Get(this));
                }
                else if (type == typeof(string))
                {
                    writer.Put(stringAccessor[propertiesName[i]].Get(this));
                }
            }
        }