public void CopyFromOtherWriterUnAlignedBig()
        {
            var value1 = (ulong)UnityEngine.Random.Range(0, 20000);
            var value2 = (ulong)UnityEngine.Random.Range(0, 20000);
            var value3 = (ulong)UnityEngine.Random.Range(0, 20000);
            var value4 = (ulong)UnityEngine.Random.Range(0, 20000);
            var value5 = (ulong)UnityEngine.Random.Range(0, 20000);

            otherWriter.Write(value1, 46);
            otherWriter.Write(value2, 47);
            otherWriter.Write(value3, 48);
            otherWriter.Write(value4, 49);
            otherWriter.Write(value5, 50);

            writer.WriteUInt64(5);
            writer.Write(1, 3);
            writer.WriteByte(171);

            writer.CopyFromWriter(otherWriter, 0, 240);

            var segment = writer.ToArraySegment();

            reader.Reset(segment);

            Assert.That(reader.ReadUInt64(), Is.EqualTo(5ul));
            Assert.That(reader.Read(3), Is.EqualTo(1));
            Assert.That(reader.ReadByte(), Is.EqualTo(171));
            Assert.That(reader.Read(46), Is.EqualTo(value1), "Random value 1 not correct");
            Assert.That(reader.Read(47), Is.EqualTo(value2), "Random value 2 not correct");
            Assert.That(reader.Read(48), Is.EqualTo(value3), "Random value 3 not correct");
            Assert.That(reader.Read(49), Is.EqualTo(value4), "Random value 4 not correct");
            Assert.That(reader.Read(50), Is.EqualTo(value5), "Random value 5 not correct");
        }
Beispiel #2
0
        public static void Serialize(this NetworkWriter writer, UpdateTileMessage.NetMessage message)
        {
            writer.WriteUInt(message.MatrixSyncNetID);
            foreach (var delayedData in message.Changes)
            {
                writer.WriteBool(true);
                writer.WriteVector3Int(delayedData.Position);
                writer.WriteInt((int)delayedData.TileType);
                writer.WriteInt((int)delayedData.layerType);
                writer.WriteString(delayedData.TileName);

                if (delayedData.Colour != Color.white)
                {
                    writer.WriteByte((byte)EnumOperation.Colour);
                    writer.WriteColor(delayedData.Colour);
                }

                if (delayedData.TransformMatrix != Matrix4x4.identity)
                {
                    writer.WriteByte((byte)EnumOperation.Matrix4x4);
                    writer.WriteMatrix4x4(delayedData.TransformMatrix);
                }
                writer.WriteByte((byte)EnumOperation.NoMoreData);
            }
            writer.WriteBool(false);
        }
Beispiel #3
0
    public override void Serialize(NetworkWriter writer)
    {
        base.Serialize(writer);
        // indicate unknown component if client requested it
        if (ComponentType == null)
        {
            writer.WriteUInt16(UNKNOWN_COMPONENT_TYPE_ID);
        }
        else
        {
            writer.WriteUInt16(componentTypeToComponentID[ComponentType]);
        }
        writer.WriteByte(interactionTypeToInteractionID[InteractionType]);
        //server determines processor object if client specified unknown component
        if (ComponentType != null)
        {
            writer.WriteUInt32(ProcessorObject);
        }
        writer.WriteByte((byte)Intent);

        if (InteractionType == typeof(PositionalHandApply))
        {
            writer.WriteUInt32(TargetObject);
            writer.WriteVector2(TargetVector);
            writer.WriteInt32((int)TargetBodyPart);
        }
        else if (InteractionType == typeof(HandApply))
        {
            writer.WriteUInt32(TargetObject);
            writer.WriteInt32((int)TargetBodyPart);
            writer.WriteBoolean(IsAltUsed);
        }
        else if (InteractionType == typeof(AimApply))
        {
            writer.WriteVector2(TargetVector);
            writer.WriteBoolean(MouseButtonState == MouseButtonState.PRESS);
        }
        else if (InteractionType == typeof(MouseDrop))
        {
            writer.WriteUInt32(TargetObject);
            writer.WriteUInt32(UsedObject);
        }
        else if (InteractionType == typeof(InventoryApply))
        {
            writer.WriteUInt32(UsedObject);
            writer.WriteUInt32(Storage);
            writer.WriteInt32(SlotIndex);
            writer.WriteInt32((int)NamedSlot);
            writer.WriteBoolean(IsAltUsed);
        }
        else if (InteractionType == typeof(TileApply))
        {
            writer.WriteVector2(TargetVector);
        }
        else if (InteractionType == typeof(TileMouseDrop))
        {
            writer.WriteUInt32(UsedObject);
            writer.WriteVector2(TargetVector);
        }
    }
Beispiel #4
0
        public void TestWriteMisaligned()
        {
            var outNetworkBuffer = new NetworkBuffer();
            var outNetworkWriter = new NetworkWriter(outNetworkBuffer);

            outNetworkWriter.WriteBit(true);
            outNetworkWriter.WriteBit(false);
            // now the stream is misalligned,  lets write some bytes
            outNetworkWriter.WriteByte(244);
            outNetworkWriter.WriteByte(123);
            outNetworkWriter.WriteInt16(-5457);
            outNetworkWriter.WriteUInt64(4773753249);
            outNetworkWriter.WriteUInt64Packed(5435285812313212);
            outNetworkWriter.WriteInt64Packed(-5435285812313212);
            outNetworkWriter.WriteBit(true);
            outNetworkWriter.WriteByte(1);
            outNetworkWriter.WriteByte(0);

            var outBuffer = outNetworkBuffer.GetBuffer();

            var inNetworkBuffer = new NetworkBuffer(outBuffer);
            var inNetworkReader = new NetworkReader(inNetworkBuffer);

            Assert.That(inNetworkReader.ReadBit(), Is.True);
            Assert.That(inNetworkReader.ReadBit(), Is.False);
            Assert.That(inNetworkReader.ReadByte(), Is.EqualTo(244));
            Assert.That(inNetworkReader.ReadByte(), Is.EqualTo(123));
            Assert.That(inNetworkReader.ReadInt16(), Is.EqualTo(-5457));
            Assert.That(inNetworkReader.ReadUInt64(), Is.EqualTo(4773753249));
            Assert.That(inNetworkReader.ReadUInt64Packed(), Is.EqualTo(5435285812313212));
            Assert.That(inNetworkReader.ReadInt64Packed(), Is.EqualTo(-5435285812313212));
            Assert.That(inNetworkReader.ReadBit(), Is.True);
            Assert.That(inNetworkReader.ReadByte(), Is.EqualTo(1));
            Assert.That(inNetworkReader.ReadByte(), Is.EqualTo(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);
            }
        }
Beispiel #6
0
 public void Serialize(ref byte value)
 {
     if (IsReading)
     {
         value = m_Reader.ReadByteDirect();
     }
     else
     {
         m_Writer.WriteByte(value);
     }
 }
    public override void Serialize(NetworkWriter writer)
    {
        base.Serialize(writer);
        writer.WriteUInt16(componentTypeToComponentID[ComponentType]);
        writer.WriteByte(interactionTypeToInteractionID[InteractionType]);
        writer.WriteUInt32(ProcessorObject);
        writer.WriteByte((byte)Intent);

        if (InteractionType == typeof(PositionalHandApply))
        {
            writer.WriteUInt32(TargetObject);
            writer.WriteVector2(TargetVector);
            writer.WriteInt32((int)TargetBodyPart);
        }
        else if (InteractionType == typeof(HandApply))
        {
            writer.WriteUInt32(TargetObject);
            writer.WriteInt32((int)TargetBodyPart);
            writer.WriteBoolean(IsAltUsed);
        }
        else if (InteractionType == typeof(AimApply))
        {
            writer.WriteVector2(TargetVector);
            writer.WriteBoolean(MouseButtonState == MouseButtonState.PRESS);
        }
        else if (InteractionType == typeof(MouseDrop))
        {
            writer.WriteUInt32(TargetObject);
            writer.WriteUInt32(UsedObject);
        }
        else if (InteractionType == typeof(InventoryApply))
        {
            writer.WriteUInt32(UsedObject);
            writer.WriteUInt32(Storage);
            writer.WriteInt32(SlotIndex);
            writer.WriteInt32((int)NamedSlot);
            writer.WriteBoolean(IsAltUsed);
        }
        else if (InteractionType == typeof(TileApply))
        {
            writer.WriteVector2(TargetVector);
            writer.WriteByte((byte)TileInteractionIndex);
        }
        else if (InteractionType == typeof(TileMouseDrop))
        {
            writer.WriteUInt32(UsedObject);
            writer.WriteVector2(TargetVector);
            writer.WriteByte((byte)TileInteractionIndex);
        }
    }
Beispiel #8
0
        public void TestToArray()
        {
            // write 2 bytes
            writer.WriteByte(1);
            writer.WriteByte(2);

            // .ToArray() length is 2?
            Assert.That(writer.ToArray().Length, Is.EqualTo(2));

            // set position back by one
            writer.Position = 1;

            // Changing the position should not alter the size of the data
            Assert.That(writer.ToArray().Length, Is.EqualTo(2));
        }
Beispiel #9
0
    public void Serialize(ref NetworkWriter writer, IEntityReferenceSerializer refSerializer)
    {
        writer.WriteString("objectiveName", objectiveName);

        writer.WriteByte("status", (byte)status);
        writer.WriteFloatQ("captured", captured, 2);
    }
Beispiel #10
0
        public void OnSerializeDelta(NetworkWriter writer)
        {
            // write all the queued up changes
            writer.WritePackedUInt32((uint)_changes.Count);

            for (var i = 0; i < _changes.Count; i++)
            {
                var change = _changes[i];
                writer.WriteByte((byte)change.Operation);

                switch (change.Operation)
                {
                case Operation.OP_ADD:
                    writer.Write(change.Item);
                    break;

                case Operation.OP_CLEAR:
                    break;

                case Operation.OP_REMOVEAT:
                    writer.WritePackedUInt32((uint)change.Index);
                    break;

                case Operation.OP_INSERT:
                case Operation.OP_SET:
                    writer.WritePackedUInt32((uint)change.Index);
                    writer.Write(change.Item);
                    break;
                }
            }
        }
Beispiel #11
0
 public static void WritePickable(this NetworkWriter writer, Pickable pickable)
 {
     // This code will not work, if the pickable can be modified at runtime. Consider
     // adding a bool flag to check if the pickable can be edited at runtime and then
     // transmit all modified values.
     if (pickable == null)
     {
         writer.WriteByte(0);
         writer.WriteUInt16(0);
     }
     else
     {
         writer.WriteByte((byte)pickable.PickableType);
         writer.WriteUInt16(pickable.Id);
     }
 }
Beispiel #12
0
        public void OnSerializeDelta(NetworkWriter writer)
        {
            // write all the queued up changes
            writer.WritePackedUInt32((uint)changes.Count);

            for (int i = 0; i < changes.Count; i++)
            {
                Change change = changes[i];
                writer.WriteByte((byte)change.operation);

                switch (change.operation)
                {
                case Operation.OP_ADD:
                    writer.Write(change.item);
                    break;

                case Operation.OP_CLEAR:
                    break;

                case Operation.OP_REMOVE:
                    writer.Write(change.item);
                    break;
                }
            }
        }
Beispiel #13
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);
            }
        }
Beispiel #14
0
 public void Serialize(ref NetworkWriter writer, IEntityReferenceSerializer refSerializer)
 {
     writer.WriteInt32("tick", checkTick);
     writer.WriteInt32("renderTick", renderTick);
     writer.WriteFloatQ("moveYaw", moveYaw, 0);
     writer.WriteFloatQ("moveMagnitude", moveMagnitude, 2);
     writer.WriteFloat("lookYaw", lookYaw);
     writer.WriteFloat("lookPitch", lookPitch);
     writer.WriteBoolean("jump", jump);
     writer.WriteBoolean("boost", boost);
     writer.WriteBoolean("sprint", sprint);
     writer.WriteBoolean("primaryFire", primaryFire);
     writer.WriteBoolean("secondaryFire", secondaryFire);
     writer.WriteBoolean("abilityA", abilityA);
     writer.WriteBoolean("reload", reload);
     writer.WriteBoolean("melee", melee);
     writer.WriteBoolean("use", use);
     writer.WriteByte("emote", (byte)emote);
     //VR controls
     writer.WriteVector3Q("rightControllerPos", rightControllerPos, 2);
     writer.WriteVector3Q("leftControllerPos", leftControllerPos, 2);
     writer.WriteVector3Q("headsetPos", headsetPos, 2);
     writer.WriteQuaternion("rightControllerRot", rightControllerRot);
     writer.WriteQuaternion("leftControllerRot", leftControllerRot);
     writer.WriteQuaternion("headsetRot", headsetRot);
 }
Beispiel #15
0
        public override bool OnSerialize(NetworkWriter writer, bool initialState)
        {
            if (initialState)
            {
                writer.WriteByte(_owner.Id);
                writer.WriteByte(_unit.CategoryId);
                writer.WriteInt32(_unit.Id);
                writer.WriteSingle(FinalHeading);
            }
            else
            {
                writer.WriteSingle(FinalHeading);
                writer.WriteByte((byte)_units.Count);
            }

            return(true);
        }
Beispiel #16
0
 public override void Serialize(NetworkWriter _writer)
 {
     base.Serialize(_writer);
     _writer.WriteInt32(callbackId);
     _writer.WriteByte((byte)status);
     _writer.WriteString(MsgType.FullName);
     message.Serialize(_writer);
 }
Beispiel #17
0
        public static void WriteWorldObjectData(this NetworkWriter writer, WorldObjectData data)
        {
            writer.WriteInt32((int)data.ObjectType);
            writer.WriteUInt32(data.Key);
            writer.WriteBoolean(data.Instantiated);

            //Ïsland type.
            if (data is IslandObjectData od)
            {
                writer.WriteByte((byte)od.TreeState);
            }

            //Tree type.
            if (data is TreeObjectData op)
            {
                writer.WriteByte((byte)op.TreeState);
            }
        }
Beispiel #18
0
 public static void WriteServerConfig(this NetworkWriter writer, ServerConfig config)
 {
     writer.WriteString(config.gameName);
     writer.WriteByte((byte)config.motdMode);
     if (config.motdMode == Server.ServerMOTDMode.TextOnly)
     {
         writer.WriteString(config.motdText);
     }
 }
Beispiel #19
0
        public void MakeNextBatch_OnlyAcceptsFreshWriter()
        {
            batcher.AddMessage(new ArraySegment <byte>(new byte[] { 0x01 }));

            writer.WriteByte(0);
            Assert.Throws <ArgumentException>(() => {
                batcher.MakeNextBatch(writer);
            });
        }
Beispiel #20
0
    public void Serialize(ref SerializeContext context, ref NetworkWriter writer)
    {
        var behaviour = context.entityManager.GetComponentObject <CapturePoint>(context.entity);

        writer.WriteString("objectiveName", behaviour.objectiveName);

        writer.WriteByte("status", (byte)behaviour.status);
        writer.WriteFloatQ("captured", behaviour.captured, 2);
    }
Beispiel #21
0
        public override bool OnSerialize(NetworkWriter writer, bool initialState)
        {
            bool canSend = false;

            if (initialState)
            {
                writer.WriteByte(Owner.Id);
                writer.WriteByte(Unit.CategoryId);
                writer.WriteInt32(Unit.Id);
                canSend = true;
            }
            else
            {
                // TODO
            }

            return(canSend);
        }
        /// <summary>
        /// Writes a compressed Vector3 to the writer.
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="ca"></param>
        /// <param name="v"></param>
        private static void WriteCompressedVector3(NetworkWriter writer, Vector3 v)
        {
            CompressedAxes ca = CompressedAxes.None;
            //If can compress X.
            float absX = Mathf.Abs(v.x);

            if (absX <= MAX_COMPRESSION_VALUE)
            {
                ca |= (Mathf.Sign(v.x) > 0f) ? CompressedAxes.XPositive : CompressedAxes.XNegative;
            }
            //If can compress Y.
            float absY = Mathf.Abs(v.y);

            if (absY <= MAX_COMPRESSION_VALUE)
            {
                ca |= (Mathf.Sign(v.y) > 0f) ? CompressedAxes.YPositive : CompressedAxes.YNegative;
            }
            //If can compress Z.
            float absZ = Mathf.Abs(v.z);

            if (absZ <= MAX_COMPRESSION_VALUE)
            {
                ca |= (Mathf.Sign(v.z) > 0f) ? CompressedAxes.ZPositive : CompressedAxes.ZNegative;
            }

            //Write compresed axes.
            writer.WriteByte((byte)ca);
            //X
            if (EnumContains.CompressedAxesContains(ca, CompressedAxes.XNegative) || EnumContains.CompressedAxesContains(ca, CompressedAxes.XPositive))
            {
                writer.WriteUInt16((ushort)Mathf.Round(absX * 100f));
            }
            else
            {
                writer.WriteSingle(v.x);
            }
            //Y
            if (EnumContains.CompressedAxesContains(ca, CompressedAxes.YNegative) || EnumContains.CompressedAxesContains(ca, CompressedAxes.YPositive))
            {
                writer.WriteUInt16((ushort)Mathf.Round(absY * 100f));
            }
            else
            {
                writer.WriteSingle(v.y);
            }
            //Z
            if (EnumContains.CompressedAxesContains(ca, CompressedAxes.ZNegative) || EnumContains.CompressedAxesContains(ca, CompressedAxes.ZPositive))
            {
                writer.WriteUInt16((ushort)Mathf.Round(absZ * 100f));
            }
            else
            {
                writer.WriteSingle(v.z);
            }
        }
Beispiel #23
0
        public static void WriteAnimatorUpdate(this NetworkWriter writer, AnimatorUpdate au)
        {
            //Component index.
            writer.WriteByte(au.ComponentIndex);

            //Write compressed network identity.
            //byte.
            if (au.NetworkIdentity <= byte.MaxValue)
            {
                writer.WriteByte(1);
                writer.WriteByte((byte)au.NetworkIdentity);
            }
            //ushort.
            else if (au.NetworkIdentity <= ushort.MaxValue)
            {
                writer.WriteByte(2);
                writer.WriteUInt16((ushort)au.NetworkIdentity);
            }
            //Full value.
            else
            {
                writer.WriteByte(4);
                writer.WriteUInt32(au.NetworkIdentity);
            }

            //Animation data.
            //Compress data length.
            if (au.Data.Length <= byte.MaxValue)
            {
                writer.WriteByte(1);
                writer.WriteByte((byte)au.Data.Length);
            }
            else if (au.Data.Length <= ushort.MaxValue)
            {
                writer.WriteByte(2);
                writer.WriteUInt16((ushort)au.Data.Length);
            }
            else
            {
                writer.WriteByte(4);
                writer.WriteInt32(au.Data.Length);
            }
            if (au.Data.Length > 0)
            {
                writer.WriteBytes(au.Data, 0, au.Data.Length);
            }
        }
 public void Serialize(ref SerializeContext context, ref NetworkWriter networkWriter)
 {
     networkWriter.WriteInt32("tick", checkTick);
     networkWriter.WriteInt32("renderTick", renderTick);
     networkWriter.WriteFloatQ("moveYaw", moveYaw, 0);
     networkWriter.WriteFloatQ("moveMagnitude", moveMagnitude, 2);
     networkWriter.WriteFloat("lookYaw", lookYaw);
     networkWriter.WriteFloat("lookPitch", lookPitch);
     networkWriter.WriteUInt32("buttons", buttons.flags);
     networkWriter.WriteByte("emote", (byte)emote);
 }
Beispiel #25
0
        // Make custom writer(private)
        private static void MakeCustomSyncWriter(NetworkIdentity behaviorOwner, Type targetType, Action <NetworkWriter> customSyncObject, Action <NetworkWriter> customSyncVar, NetworkWriter owner, NetworkWriter observer)
        {
            byte             behaviorDirty = 0;
            NetworkBehaviour behaviour     = null;

            // Get NetworkBehaviors index (behaviorDirty use index)
            for (int i = 0; i < behaviorOwner.NetworkBehaviours.Length; i++)
            {
                if (behaviorOwner.NetworkBehaviours[i].GetType() == targetType)
                {
                    behaviour     = behaviorOwner.NetworkBehaviours[i];
                    behaviorDirty = (byte)i;
                    break;
                }
            }

            // Write target NetworkBehavior's dirty
            owner.WriteByte(behaviorDirty);

            // Write init position
            int position = owner.Position;

            owner.WriteInt32(0);
            int position2 = owner.Position;

            // Write custom sync data
            if (customSyncObject != null)
            {
                customSyncObject.Invoke(owner);
            }
            else
            {
                behaviour.SerializeObjectsDelta(owner);
            }

            // Write custom syncvar
            customSyncVar?.Invoke(owner);

            // Write syncdata position data
            int position3 = owner.Position;

            owner.Position = position;
            owner.WriteInt32(position3 - position2);
            owner.Position = position3;

            // Copy owner to observer
            if (behaviour.syncMode != SyncMode.Observers)
            {
                ArraySegment <byte> arraySegment = owner.ToArraySegment();
                observer.WriteBytes(arraySegment.Array, position, owner.Position - position);
            }
        }
Beispiel #26
0
 public static void WriteItem(this NetworkWriter writer, Skill skill)
 {
     if (skill is BasicAttack basicAttack)
     {
         writer.WriteByte(BASICATTACK);
         writer.WriteInt32(basicAttack.damage);
     }
     else if (skill is BasicHeal basicHeal)
     {
         writer.WriteByte(BASICHEAL);
         writer.WriteInt32(basicHeal.heal);
     }
     else if (skill is Fireball fireball)
     {
         writer.WriteByte(BASICFIREBALL);
         writer.Write <Effect>(fireball.effect);
         writer.WriteInt32(fireball.fireDamage);
         writer.WriteInt32(fireball.damage);
     }
     writer.WriteString(skill.name);
     writer.WriteString(skill.description);
 }
Beispiel #27
0
        /// <summary>
        /// Writes a compressed quaternion to a writer.
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="rotation"></param>
        public static void WriteCompressedQuaternion(NetworkWriter writer, Quaternion rotation)
        {
            byte  largest;
            short a, b, c;

            Quaternions.CompressQuaternion(rotation, out largest, out a, out b, out c);
            writer.WriteByte(largest);
            if (!Quaternions.UseLargestOnly(largest))
            {
                writer.WriteInt16(a);
                writer.WriteInt16(b);
                writer.WriteInt16(c);
            }
        }
        public override bool OnSerialize(NetworkWriter writer, bool initialState)
        {
            bool dataWritten = base.OnSerialize(writer, initialState);

            if (initialState)
            {
                writer.WriteByte((byte)this.levelPhase.CurrentState);
                dataWritten = true;
            }

            dataWritten |= ((LevelPhaseState)this.levelPhase.CurrentStateObject).OnSerialize(writer, initialState);

            return(dataWritten);
        }
Beispiel #29
0
 public void Serialize(ref SerializeContext context, ref NetworkWriter writer)
 {
     writer.WriteInt32("tick", tick);
     writer.WriteVector3Q("velocity", velocity, 2);
     writer.WriteInt32("action", (int)action);
     writer.WriteInt32("actionStartTick", actionStartTick);
     writer.WriteInt32("phase", (int)locoState);
     writer.WriteInt32("phaseStartTick", locoStartTick);
     writer.WriteVector3Q("position", position, 2);
     writer.WriteInt32("jumpCount", jumpCount);
     writer.WriteBoolean("sprint", sprinting == 1);
     writer.WriteByte("cameraProfile", (byte)cameraProfile);
     writer.WriteInt32("damageTick", damageTick);
     writer.WriteVector3Q("damageDirection", damageDirection);
 }
        public void DeserializeDeltaReadsNetIdAndComponentIndex()
        {
            NetworkWriter writer = new NetworkWriter();

            writer.WriteUInt(serverComponent.netId);
            writer.WriteByte((byte)serverComponent.ComponentIndex);
            NetworkReader reader = new NetworkReader(writer.ToArraySegment());

            SyncVarNetworkBehaviour <EmptyBehaviour> field = new SyncVarNetworkBehaviour <EmptyBehaviour>(null);

            // avoid 'not initialized' exception
            field.OnDirty = () => {};

            field.OnDeserializeDelta(reader);
            Assert.That(field.Value, Is.EqualTo(serverComponent));
        }