Wednesday, December 3, 2014

CSG Post 5: Managing Networks Like a Boss

I have worked on projects before involving networked play however I have agreed not to talk about it. Luckily Scoundrels of Yen does involve network play So I can talk about all the things I learned then now and also the things I've learned now now. Its important to note that I have only have extensive experience with RPC method based games. I would love to do a state sync based game but currently that type of project has not arisen.

One thing that I learned from doing networked unity programming is the value of keeping your code organized. Before learning networking I would always format my scripts however I so pleased. This was important early on for experimenting with different code formats but as coding became more and more complicated an organized structure of where certain methods were located became more and more relevant. If you aren't familiar with RPC Methods, the way it works is that you First create a method beginning with [RPC], put and functionality that you need into the method. Then use NetworkView.RPC(); to pass in the string name of the method you want to call crossed the network. Followed by the rpcmode and any parameters of the method. This winds up needing quite a lot of methods. For any piece of data that you want to transfer crossed the internet you now need a RPC method for it as well as a Public Method that triggers the call crossed the network. Because of the large amount of methods I adopted a system where there is a summary at the top of the script followed by any getter setter properties or methods.(I prefer properties). Followed by any methods built into unity. Followed by private methods, Followed by public methods. Followed by RPC Methods if any are needed. Followed by Ienumerators.

bool variables/constants;
bool GettersSetters;
void UnityMethods();
private void PrivateMethods();
public void PublicMethods();
[RPC]void RPCMethods();
Ienumerator IEnumerator();

Ive stuck to this structure for a while now and I really like knowing what section to look in depending on what type of method a certain functionality uses. Eventually I would help to define the Raid+ tech reqs using these standards and I am very glad I made that decision.

No comments:

Post a Comment