Unity Networking - “NetworkExtensions” and making it easier to deal with
I’m working on an asset to help make Unity network all around easier for the common man. Here’s a preview of some of the static functions I’ve made to help with that.
Generic object types
In this picture you’ll notice generic object types that can be passed. The generic types have to extend Unity’s MessageBase class (T : MessageBase in enforced, but the collapsing is hiding it). To use those generic functions, you need to map the class Type to a MsgType short in an abstract dictionary you are required to implement (though you can leave it empty or NotImplementedException if you don’t intend to use those functions). The advantage is that you could say what MsgType a class refers to and then not have to say what type you are sending every time you call the method.
Channel Id mappings and overrides
You’ll also notice “channelIdOverride = -1″. If you set this to a 0 or greater value, it will override the default channel it sends the message on. Just like with the generic type function, there are abstract dictionary<short, int>s where you can specify what MsgType you want to map to what channel. If you don’t provide an override and you also don’t have an entry in the dictionary, it defaults to channel 0 which is the default reliable channel. That is also Unity’s default functionality as well.
Things this asset has that are not default
So far the big win here is an easy to use implementation of Client -> Client and Client -> All Clients. Unity doesn’t offer that by default since all messages need to go through the server with UNet. They still do in my implementation, but behind the scenes I’ve rerouted those messages from the server to where you want them to go in an easy way.
I also provide a unique and easily accessible Player Id for all players. This can be used to send people messages (as you can see here you need a player id to send to specific players) or to disconnect individual players.
Things to come
Easy to use object spawning, including being able to request objects to spawn from a client. By default, only the server can spawn objects.
Comments?











