コード例 #1
0
ファイル: NetworkService.cs プロジェクト: k0dep/pongo-pongo
        private void ParseMessage(byte[] data)
        {
            switch ((ClientMessages)data[0])
            {
            case ClientMessages.PlayerFound:
                var isAuthority = data[1] == 0xFF;
                Sender.Send(new StartRoomSessionMessage(isAuthority));
                break;

            case ClientMessages.WorldState:
                using (var stream = new MemoryStream(data))
                    using (var reader = new BinaryReader(stream))
                    {
                        reader.ReadByte();
                        var stateMessage = new WorldStateMessage
                        {
                            PartnerPosition = reader.ReadSingle(),
                            PartnetVelocity = reader.ReadSingle(),
                            BallPosition    = new Vector2(reader.ReadSingle(), reader.ReadSingle()),
                            BallVelocity    = new Vector2(reader.ReadSingle(), reader.ReadSingle())
                        };
                        Sender.Send(stateMessage);
                    }
                break;

            case ClientMessages.Platform:
                using (var stream = new MemoryStream(data))
                    using (var reader = new BinaryReader(stream))
                    {
                        reader.ReadByte();
                        var stateMessage = new PartnetPlatformMessage
                        {
                            PartnerPosition = reader.ReadSingle(),
                            PartnerVelocity = reader.ReadSingle()
                        };
                        Sender.Send(stateMessage);
                    }
                break;

            default:
                Debug.LogError($"Not known event {data[0]:X}");
                break;
            }
        }
コード例 #2
0
 private void HandlePartnerState(PartnetPlatformMessage obj)
 {
     Enemy.transform.localPosition = new Vector3(-obj.PartnerPosition, Enemy.transform.localPosition.y, Enemy.transform.localPosition.z);
     Enemy.GetComponent <Rigidbody2D>().velocity = new Vector2(-obj.PartnerVelocity, 0);
 }