Пример #1
0
    private void OnReceive(byte[] message, int messageSize, BleSock.Player sender)
    {
        mReceiveBuffer.Clear();
        mReceiveBuffer.WriteBytes(message, 0, messageSize);
        mReceiveBuffer.Seek(0);

        switch (mReceiveBuffer.ReadByte())
        {
        case MSG_SPAWN:
            OnReceiveSpawn(sender);
            break;

        case MSG_SYNC:
            OnReceiveSync(sender);
            break;

        case MSG_SHOOT:
            OnReceiveShoot(sender);
            break;

        case MSG_DIE:
            OnReceiveDie(sender);
            break;

        case MSG_REVIVE:
            OnReceiveRevive(sender);
            break;
        }
    }
Пример #2
0
    private void OnReceiveDie(BleSock.Player sender)
    {
        var playerCharacter = mPlayerCharacters.Where(pc => pc.playerId == sender.PlayerId).FirstOrDefault();

        if (playerCharacter != null)
        {
            playerCharacter.Die();
        }

        int killerPlayerId = mReceiveBuffer.ReadInt32();
        int bulletId       = mReceiveBuffer.ReadInt32();

        if (killerPlayerId == mPeer.LocalPlayerId)
        {
            Log("{0}を倒した", sender.PlayerName);
        }

        var killerCharacter = mPlayerCharacters.Where(pc => pc.playerId == killerPlayerId).FirstOrDefault();

        if (killerCharacter != null)
        {
            killerCharacter.score += PlayerCharacter.KILL_SCORE;
        }

        var bullet = mBullets.Where(b => (b.playerId == killerPlayerId) && (b.bulletId == bulletId)).FirstOrDefault();

        if (bullet != null)
        {
            mBullets.Remove(bullet);
            Destroy(bullet.gameObject);
        }
    }
Пример #3
0
    private void OnReceiveRevive(BleSock.Player sender)
    {
        var playerCharacter = mPlayerCharacters.Where(pc => pc.playerId == sender.PlayerId).FirstOrDefault();

        if (playerCharacter != null)
        {
            playerCharacter.Spawn(ReadVector2());
        }
    }
Пример #4
0
    private void OnReceiveShoot(BleSock.Player sender)
    {
        var playerCharacter = mPlayerCharacters.Where(pc => pc.playerId == sender.PlayerId).FirstOrDefault();

        if (playerCharacter != null)
        {
            int     bulletId = mReceiveBuffer.ReadInt32();
            Vector2 position = ReadVector2();
            Vector2 velocity = ReadVector2();
            SpawnBullet(sender.PlayerId, bulletId, position, velocity, playerCharacter.baseImage.color);
        }
    }
Пример #5
0
    private void OnReceiveSync(BleSock.Player sender)
    {
        var playerCharacter = mPlayerCharacters.Where(pc => pc.playerId == sender.PlayerId).FirstOrDefault();

        if (playerCharacter != null)
        {
            playerCharacter.position     = ReadVector2();
            playerCharacter.velocity     = ReadVector2();
            playerCharacter.rotation     = ReadFloat();
            playerCharacter.accelerating = mReceiveBuffer.ReadBoolean();
        }
    }
Пример #6
0
    private void OnPlayerLeave(BleSock.Player player)
    {
        Log("{0} が離脱しました", player.PlayerName);

        var playerCharacter = mPlayerCharacters.Where(pc => pc.playerId == player.PlayerId).FirstOrDefault();

        if (playerCharacter != null)
        {
            mPlayerCharacters.Remove(playerCharacter);
            Destroy(playerCharacter.gameObject);
        }
    }
Пример #7
0
    private void OnReceiveSpawn(BleSock.Player sender)
    {
        var playerCharacter = Instantiate(playerCharacterOriginal, charactersRoot, false);

        playerCharacter.Setup(sender.PlayerId, sender.PlayerName, Color.HSVToRGB(ReadFloat(), 1, 1));
        playerCharacter.Spawn(ReadVector2());
        playerCharacter.velocity     = ReadVector2();
        playerCharacter.rotation     = ReadFloat();
        playerCharacter.accelerating = mReceiveBuffer.ReadBoolean();
        playerCharacter.alive        = mReceiveBuffer.ReadBoolean();
        playerCharacter.score        = mReceiveBuffer.ReadInt32();

        mPlayerCharacters.Add(playerCharacter);
    }
Пример #8
0
    private void OnReceive(byte[] message, int messageSize, BleSock.Player sender)
    {
        if (message[0] == 0)
        {
            message[0] = 1;

            try
            {
                mPeer.Send(message, message.Length, BleSock.Address.Others);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                Log("エラー");
                return;
            }
        }
        else
        {
            Log("計測が完了しました: {0} bytes/sec", (float)messageSize * 1000 / (Environment.TickCount - mStartTime));
            sizesDropdown.interactable = true;
            testButton.interactable    = true;
        }
    }
Пример #9
0
    private void OnPlayerJoin(BleSock.Player player)
    {
        Log("{0} が参加しました", player.PlayerName);

        SendSpawn(player.PlayerId);
    }