void SendShotInputDataToServer(Vector3 hitPosition)
        {
            float[]         position        = { hitPosition.x, hitPosition.y, hitPosition.z };
            ShotInputPacket shotInputPacket = new ShotInputPacket();
            ShotInputData   shotInputData;

            shotInputData.hitPosition = position;

            shotInputPacket.Payload = shotInputData;
            PacketsManager.Instance.SendPacket(shotInputPacket, null, UdpNetworkManager.Instance.GetSenderID(), objectID, reliable: true);
        }
Exemplo n.º 2
0
        void OnDataReceivedByServer(ushort userPacketTypeIndex, uint senderID, Stream stream)
        {
            if (userPacketTypeIndex == (ushort)UserPacketType.Input)
            {
                InputPacket inputPacket = new InputPacket();

                inputPacket.Deserialize(stream);

                inputsByClientID[senderID].inputs.Add(inputPacket);
            }

            if (userPacketTypeIndex == (ushort)UserPacketType.ShotInput)
            {
                ShotInputPacket shotInputPacket = new ShotInputPacket();

                shotInputPacket.Deserialize(stream);

                using (var dicIterator = enemySpaceshipsByClientID.GetEnumerator())
                    while (dicIterator.MoveNext())
                    {
                        EnemySpaceship enemySpaceship = dicIterator.Current.Value;
                        Vector3        hitPos         = new Vector3(shotInputPacket.Payload.hitPosition[0],
                                                                    shotInputPacket.Payload.hitPosition[1],
                                                                    shotInputPacket.Payload.hitPosition[2]);

                        if (enemySpaceship.transform.position == hitPos)
                        {
                            NotificationPacket notificationPacket = new NotificationPacket();
                            NotificationData   notificationData;
                            uint receiverID = dicIterator.Current.Key;

                            notificationData.playerStatus = (uint)PlayerStatus.Dead;
                            notificationPacket.Payload    = notificationData;

                            PacketsManager.Instance.SendPacket(notificationPacket,
                                                               UdpConnectionManager.Instance.GetClientIP(receiverID),
                                                               senderID,
                                                               enemySpaceship.ObjectID,
                                                               reliable: true);
                        }
                    }
            }
        }