Unity-Technologies / com.unity.netcode.gameobjects

Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.
MIT License
2.15k stars 435 forks source link

Can we spawn clients in different positions based on a property they have? #97

Closed IoannisKaragiannis closed 6 years ago

IoannisKaragiannis commented 6 years ago

Hi,

Description

I want to spawn two clients in different positions. Client-A has a particular property (e.g.: a boolean that is true), while Client-B doesn't. Is there an easy way to modify the HandleApproval() method to take into account this extra information and spawn the clients properly?

Code

    private void HandleApproval(byte[] data, uint clientId, Action<uint, bool, Vector3, Quaternion> callback)
    {
        callback(clientId, true, new Vector3(0,0,0), Quaternion.identity);
    }

Ideally what I want to achieve is something like the following:

private void HandleApproval(byte[] data, uint clientId, Action<uint, bool, Vector3, Quaternion> callback, bool hasProperty)
{
    if (hasProperty)
    {
        callback(clientId, true, new Vector3(0, 0, 0), Quaternion.identity);
    }
    else
    {
        callback(clientId, true, new Vector3(2, 0, 2), Quaternion.identity);
    }
}

Thanks

Your Environment

TwoTenPvP commented 6 years ago

If the property is in the form of data, sure. Example: If it's the first player, give him x position. If it's the second, give him another. But if you are talking about a property on something like a MonoBehaviour on the actual game object? No. The object is not yet instantiated. The object gets instantiated when you invoke the callback.

Just use the delegate for ConnectionApproval.

IoannisKaragiannis commented 6 years ago

Ok I see. Then I cannot really do what I want. Thanks for your response. Have a nice summer!