示例#1
0
    private void MultiplayerSpawnEnemy(int id, EnemyBehavior behavior)
    {
        if (behavior == null)
        {
            return;
        }
        Transform   enemyTransform = behavior.transform;
        Rigidbody2D rigidbody      = behavior.GetComponent <Rigidbody2D>();

        using (RTData data = RTData.Get())
        {
            Vector2 pos     = enemyTransform.position;
            Signs   posSign = SignsExt.GetSign(pos);
            Vector2 vel     = rigidbody.velocity;
            Signs   velSign = SignsExt.GetSign(vel);
            data.SetInt(1, id);
            data.SetVector2(3, pos);
            data.SetInt(4, (int)posSign);
            data.SetFloat(5, enemyTransform.rotation.eulerAngles.z);
            data.SetVector2(6, vel);
            data.SetInt(7, (int)velSign);
            gameSparksManager.RTSession.SendData(
                MultiplayerCodes.ENEMY_SPAWN.Int(),
                GameSparksRT.DeliveryIntent.RELIABLE,
                data
                );
        }
    }
示例#2
0
    private void UpdatePlayers(RTPacket packet)
    {
        CheckPeers(packet, (index) =>
        {
            Transform playerTransform   = m_players[index].transform;
            Rigidbody2D playerRigidBody = m_players[index].GetComponent <Rigidbody2D>();
            Quaternion playerRot        = playerTransform.rotation;
            Vector3 playerAngles        = playerRot.eulerAngles;

            // Referenced from PlayerController.SendTransformUpdates()
            Vector3 newPos = packet.Data.GetVector3(1).Value;
            Signs sign     = (Signs)packet.Data.GetInt(2);
            newPos         = SignsExt.Vector3Sign(newPos, sign);

            float newRot   = packet.Data.GetFloat(3).Value;
            Vector2 newVel = packet.Data.GetVector2(4).Value;
            newVel         = SignsExt.Vector2Sign(newVel, (Signs)packet.Data.GetInt(5));

            playerTransform.position = newPos;
            playerRigidBody.velocity = newVel;
            playerAngles.z           = newRot;
            playerRot.eulerAngles    = playerAngles;

            playerTransform.rotation = playerRot;
        });
    }
示例#3
0
    IEnumerator SendTransformUpdates()
    {
        // To be safe
        if (!_transform)
        {
            _transform = transform;
        }
        if (!_rigidbody)
        {
            _rigidbody = GetComponent <Rigidbody2D>();
        }

        while (true)
        {
            using (RTData data = RTData.Get())
            {
                Vector3 pos = _transform.position;
                Vector2 vel = _rigidbody.velocity;
                data.SetVector3(1, pos);
                Signs posSign = SignsExt.GetSign(pos);
                data.SetInt(2, (int)posSign);
                data.SetFloat(3, _transform.eulerAngles.z);
                data.SetVector2(4, vel);
                data.SetInt(5, (int)SignsExt.GetSign(vel));
                _gameSparksManager.RTSession.SendData(
                    MultiplayerCodes.PLAYER_POSITION.Int(),
                    GameSparksRT.DeliveryIntent.UNRELIABLE_SEQUENCED,
                    data
                    );
            }
            yield return(new WaitForSeconds(UpdateRate));
        }
    }
示例#4
0
    private void UpdateEnemiesSpawn(RTPacket packet)
    {
        RTData data = packet.Data;

        int     id       = data.GetInt(1).Value;
        Vector2 position = data.GetVector2(3).Value;

        position = SignsExt.Vector2Sign(position, (Signs)data.GetInt(4).Value);
        float   rotation = data.GetFloat(5).Value;
        Vector2 velocity = data.GetVector2(6).Value;

        velocity = SignsExt.Vector3Sign(velocity, (Signs)data.GetInt(7).Value);

        m_enemyGenerator.GenerateEnemy(id, position, rotation, velocity, true);
    }