예제 #1
0
        /// <summary>
        /// Writes TransformSyncData into a writer.
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="syncData"></param>
        public static void WriteTransformSyncData(this NetworkWriter writer, TransformSyncData syncData)
        {
            //SyncProperties.
            SyncProperties sp = (SyncProperties)syncData.SyncProperties;

            writer.WriteByte(syncData.SyncProperties);
            //SequenceId.
            if (EnumContains.SyncPropertiesContains(sp, SyncProperties.Sequenced))
            {
                writer.WriteUInt32(syncData.SequenceId);
            }
            //Position.
            if (EnumContains.SyncPropertiesContains(sp, SyncProperties.Position))
            {
                writer.WriteVector3(syncData.Position);
            }
            //Rotation.
            if (EnumContains.SyncPropertiesContains(sp, SyncProperties.Rotation))
            {
                WriteCompressedQuaternion(writer, syncData.Rotation);
            }
            //Scale.
            if (EnumContains.SyncPropertiesContains(sp, SyncProperties.Scale))
            {
                writer.WriteVector3(syncData.Scale);
            }
            //Platform.
            if (EnumContains.SyncPropertiesContains(sp, SyncProperties.Platform))
            {
                writer.WriteUInt32(syncData.PlatformNetId);
            }
        }
예제 #2
0
        /// <summary>
        /// Converts reader data into a new TransformSyncData.
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public static TransformSyncData ReadTransformSyncData(this NetworkReader reader)
        {
            SyncProperties sp = (SyncProperties)reader.ReadByte();

            TransformSyncData syncData = new TransformSyncData();

            syncData.SyncProperties = (byte)sp;

            //SequenceId.
            if (EnumContains.SyncPropertiesContains(sp, SyncProperties.Sequenced))
            {
                syncData.SequenceId = reader.ReadUInt32();
            }
            //Position.
            if (EnumContains.SyncPropertiesContains(sp, SyncProperties.Position))
            {
                syncData.Position = reader.ReadVector3();
            }
            //Rotation.
            if (EnumContains.SyncPropertiesContains(sp, SyncProperties.Rotation))
            {
                syncData.Rotation = ReadCompressedQuaternion(reader);
            }
            //scale.
            if (EnumContains.SyncPropertiesContains(sp, SyncProperties.Scale))
            {
                syncData.Scale = reader.ReadVector3();
            }

            return(syncData);
        }
예제 #3
0
        /// <summary>
        /// Writes TransformSyncData into a writer.
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="syncData"></param>
        public static void WriteTransformSyncData(this NetworkWriter writer, TransformSyncData syncData)
        {
            //SyncProperties.
            SyncProperties sp = (SyncProperties)syncData.SyncProperties;

            writer.WriteByte(syncData.SyncProperties);

            //NetworkIdentity.
            //Get compression level for netIdentity.
            if (EnumContains.SyncPropertiesContains(sp, SyncProperties.Id1))
            {
                writer.WriteByte((byte)syncData.NetworkIdentity);
            }
            else if (EnumContains.SyncPropertiesContains(sp, SyncProperties.Id2))
            {
                writer.WriteUInt16((ushort)syncData.NetworkIdentity);
            }
            else
            {
                writer.WriteUInt32(syncData.NetworkIdentity);
            }
            //ComponentIndex.
            writer.WriteByte(syncData.ComponentIndex);

            //Position.
            if (EnumContains.SyncPropertiesContains(sp, SyncProperties.Position))
            {
                if (EnumContains.SyncPropertiesContains(sp, SyncProperties.CompressSmall))
                {
                    WriteCompressedVector3(writer, syncData.Position);
                }
                else
                {
                    writer.WriteVector3(syncData.Position);
                }
            }
            //Rotation.
            if (EnumContains.SyncPropertiesContains(sp, SyncProperties.Rotation))
            {
                writer.WriteUInt32(Quaternions.CompressQuaternion(syncData.Rotation));
            }
            //Scale.
            if (EnumContains.SyncPropertiesContains(sp, SyncProperties.Scale))
            {
                if (EnumContains.SyncPropertiesContains(sp, SyncProperties.CompressSmall))
                {
                    WriteCompressedVector3(writer, syncData.Scale);
                }
                else
                {
                    writer.WriteVector3(syncData.Scale);
                }
            }
            //Platform.
            if (EnumContains.SyncPropertiesContains(sp, SyncProperties.Platform))
            {
                writer.WriteUInt32(syncData.PlatformNetId);
            }
        }
예제 #4
0
        /// <summary>
        /// Converts reader data into a new TransformSyncData.
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public static TransformSyncData ReadTransformSyncData(this NetworkReader reader)
        {
            TransformSyncData syncData = new TransformSyncData();

            //Sync properties.
            SyncProperties sp = (SyncProperties)reader.ReadByte();

            syncData.SyncProperties = (byte)sp;

            //NetworkIdentity.
            if (EnumContains.SyncPropertiesContains(sp, SyncProperties.Id1))
            {
                syncData.NetworkIdentity = reader.ReadByte();
            }
            else if (EnumContains.SyncPropertiesContains(sp, SyncProperties.Id2))
            {
                syncData.NetworkIdentity = reader.ReadUInt16();
            }
            else
            {
                syncData.NetworkIdentity = reader.ReadUInt32();
            }
            //ComponentIndex.
            syncData.ComponentIndex = reader.ReadByte();

            //Position.
            if (EnumContains.SyncPropertiesContains(sp, SyncProperties.Position))
            {
                if (EnumContains.SyncPropertiesContains(sp, SyncProperties.CompressSmall))
                {
                    syncData.Position = ReadCompressedVector3(reader);
                }
                else
                {
                    syncData.Position = reader.ReadVector3();
                }
            }
            //Rotation.
            if (EnumContains.SyncPropertiesContains(sp, SyncProperties.Rotation))
            {
                syncData.Rotation = Quaternions.DecompressQuaternion(reader.ReadUInt32());
            }
            //scale.
            if (EnumContains.SyncPropertiesContains(sp, SyncProperties.Scale))
            {
                if (EnumContains.SyncPropertiesContains(sp, SyncProperties.CompressSmall))
                {
                    syncData.Scale = ReadCompressedVector3(reader);
                }
                else
                {
                    syncData.Scale = reader.ReadVector3();
                }
            }
            //Platformed.
            if (EnumContains.SyncPropertiesContains(sp, SyncProperties.Platform))
            {
                syncData.PlatformNetId = reader.ReadUInt32();
            }

            return(syncData);
        }