Exemple #1
0
        void OnDataReceivedByClient(ushort userPacketTypeIndex, uint senderID, Stream stream)
        {
            if (senderID == UdpNetworkManager.Instance.GetSenderID())
            {
                return;
            }

            if (userPacketTypeIndex == (uint)UserPacketType.Transform)
            {
                AddSpaceshipToClient(senderID);

                TransformPacket transformPacket = new TransformPacket();

                transformPacket.Deserialize(stream);

                EnemySpaceshipTransformData enemySpaceshipTransformData = otherClientsTransformsByID[senderID];

                if (enemySpaceshipTransformData.lastTransform == null ||
                    transformPacket.Payload.inputSequenceID > enemySpaceshipTransformData.lastTransform.Payload.inputSequenceID)
                {
                    enemySpaceshipTransformData.previousTransform = enemySpaceshipTransformData.lastTransform;
                    enemySpaceshipTransformData.lastTransform     = transformPacket;
                    otherClientsTransformsByID[senderID]          = enemySpaceshipTransformData;
                }
            }

            if (userPacketTypeIndex == (uint)UserPacketType.Notification)
            {
                NotificationPacket notificationPacket = new NotificationPacket();

                notificationPacket.Deserialize(stream);

                if (notificationPacket.Payload.playerStatus == (uint)PlayerStatus.Dead)
                {
                    spaceshipController.Die();
                }
            }
        }
Exemple #2
0
        void UpdateOtherClients()
        {
            using (var dicIterator = otherClientsTransformsByID.GetEnumerator())
                while (dicIterator.MoveNext())
                {
                    EnemySpaceshipTransformData enemySpaceshipTransformData = dicIterator.Current.Value;

                    if (enemySpaceshipTransformData.previousTransform != null)
                    {
                        EnemySpaceship enemySpaceship         = enemySpaceshipTransformData.spaceship;
                        float[]        lastPositionValues     = enemySpaceshipTransformData.lastTransform.Payload.position;
                        float[]        previousPositionValues = enemySpaceshipTransformData.previousTransform.Payload.position;
                        Vector3        lastPosition           = new Vector3(lastPositionValues[0], lastPositionValues[1], lastPositionValues[2]);
                        Vector3        previousPosition       = new Vector3(previousPositionValues[0], previousPositionValues[1], previousPositionValues[2]);

                        if ((lastPosition - enemySpaceship.transform.position).sqrMagnitude > NeglibiglePosDiffSqrMagnitude)
                        {
                            Vector3 direction = (lastPosition - previousPosition).normalized;
                            enemySpaceship.Move(direction);
                        }
                    }
                }
        }