I’m creating a wrapper for network traffic, in an authoritative server setup, to send compact byte arrays exclusively. I’ve got my custom class serializable using protobuf-net… except for NetworkViewIDs, which I was planning on using to associate particular GameObjects across clients. I don’t need all the features of NetworkViewID – I think all I need is the ability to associate GameObjects across different clients (so when the server tells them gameObjectA moved, they all know which object to move), so here’s what I was trying.
The problem with NetworkViewID is that I can’t seem to break it down into the few primitives I need for serialization and then reconstruct them into a new NetworkViewID on the receiving side. The only way I’m aware of creating a new NetworkViewID is to use Network.AllocateViewID but I can’t create a NetworkViewID with the ID of my choosing or change the ID after creating one with Network.AllocateViewID so I simply can’t pass a NetworkViewID to a client.
So I went looking to see if I could serialize NetworkViewID… I found BitStream.Serialize and got optimistic. But it seems that BitStream.Serialize is only useful inside OnSerializeNetworkView. I don’t think it’s possible to use it to convert NetworkViewID into a bitstream or byte array and vice versa whenever I want.
So it’s looking like I’ll have to make an alternative to NetworkViewID. Are there any resources I can read about optimal ways to allocate the view ids? Since I won’t be relying on Unity’s NetworkViewID, I figure I can just have the server allocate them all and if I need to specify an owner the server can do that too (with Unity’s NetworkViewID, the intended owner has to allocate the viewID and then tell the server). If I simplify it like this, do I just have the server increment an int for viewID allocation? Or is this an oversimplification? Think my brain is a little fried right now. Would it be worth it to just write my own socket at this point?