Пример #1
0
    // New item spawned message. Instantiating the item object.
    private void HandleItem(ISFSObject dt)
    {
        ISFSObject       item       = dt.GetSFSObject("item");
        int              id         = item.GetInt("id");
        string           itemType   = item.GetUtfString("type");
        NetworkTransform ntransform = NetworkTransform.FromSFSObject(item);

        PlayerManager.Instance.SpawnItem(id, ntransform, itemType);
    }
Пример #2
0
    // Server rejected transform message - force the local player object to what server said
    private void HandleNoTransform(ISFSObject dt)
    {
        int userId = dt.GetInt("id");
        NetworkTransform ntransform = NetworkTransform.FromSFSObject(dt);

        if (userId == smartFox.MySelf.Id)
        {
            // Movement restricted!
            // Update transform of the local object
            ntransform.Update(PlayerManager.Instance.GetPlayerObject().transform);
        }
    }
Пример #3
0
    // Updating transform of the remote player from server
    private void HandleTransform(ISFSObject dt)
    {
        int userId = dt.GetInt("id");
        NetworkTransform ntransform = NetworkTransform.FromSFSObject(dt);

        if (userId != smartFox.MySelf.Id)
        {
            // Update transform of the remote user object

            NetworkTransformReceiver recipient = PlayerManager.Instance.GetRecipient(userId);
            if (recipient != null)
            {
                recipient.ReceiveTransform(ntransform);
            }
        }
    }
Пример #4
0
    // Instantiating player (our local FPS model, or remote 3rd person model)
    private void HandleInstantiatePlayer(ISFSObject dt)
    {
        ISFSObject       playerData = dt.GetSFSObject("player");
        int              userId     = playerData.GetInt("id");
        int              score      = playerData.GetInt("score");
        NetworkTransform ntransform = NetworkTransform.FromSFSObject(playerData);

        User   user = smartFox.UserManager.GetUserById(userId);
        string name = user.Name;

        if (userId == smartFox.MySelf.Id)
        {
            PlayerManager.Instance.SpawnPlayer(ntransform, name, score);
        }
        else
        {
            PlayerManager.Instance.SpawnEnemy(userId, ntransform, name, score);
        }
    }