示例#1
0
        /// <inheritdoc />
        public void Send(EntityMovementMessageContext context)
        {
            //When they call this, they intend to send a movement update to the connection associated
            //with the NetworkEntityGuid provided so we lookup the session associated with it
            //as well as the interest list and movement data for each individual entry int he internest
            //collection to build the movement packet.
            if (!SessionMappable.ContainsKey(context.EntityGuid))
            {
                throw new InvalidOperationException($"Tried to send movement update to Session with Guid: {context.EntityGuid} but none existed.");
            }

            //it's possible they aren't interested or have an empty interest so they may have no collection.
            if (!GuidToInterestCollectionMappable.ContainsKey(context.EntityGuid))
            {
                return;
            }

            EntityAssociatedData <IMovementData>[] movementBlocks = BuildMovementBlocks(context.EntityGuid);

            //it is possible that no movement data needs to be sent, because none is ddirty so we need to check
            if (movementBlocks.Length == 0)
            {
                return;
            }

            MovementDataUpdateEventPayload movementUpdateEvent = new MovementDataUpdateEventPayload(movementBlocks);

            SessionMappable[context.EntityGuid].SendMessage(movementUpdateEvent);
        }
示例#2
0
        public void Test_Can_Serializer_MovementPacket_With_PathMovementData()
        {
            //arrange
            Unity3DProtobufPayloadRegister payloadRegister = new Unity3DProtobufPayloadRegister();

            payloadRegister.RegisterDefaults();
            payloadRegister.Register();
            GladNet.ProtobufNetGladNetSerializerAdapter gladnetProtobuf = new ProtobufNetGladNetSerializerAdapter(PrefixStyle.Fixed32);

            //act
            MovementDataUpdateEventPayload payload = new MovementDataUpdateEventPayload(new EntityAssociatedData <IMovementData>[]
            {
                new EntityAssociatedData <IMovementData>(new NetworkEntityGuid(55), new PathBasedMovementData(new Vector3[]
                {
                    new Vector3(1, 2, 3),
                    new Vector3(2, 3, 4)
                }, 55)),
            });

            byte[] serialize = gladnetProtobuf.Serialize(payload);

            //assert
            Assert.NotNull(serialize);
            Assert.IsNotEmpty(serialize);
        }