Advertisement

Best Practices for coding in multiplayer networking game

Started by April 12, 2020 09:53 AM
1 comment, last by hplus0603 4 years, 8 months ago

Hi, I am trying to find a way to make my code neater, example

Photon.Instantiate() (Instantiate the game object in the network)

GameObject.Instantiate() (normal instantiation)

Let's say a script is using photon.Instantiate but I wanted to test the script in a non network environment, so I have to add a bool to check if is in network. Is there other proper method for this rather than keep adding boolean check for each networked function call if I wanted to test in a non network environment.

Sure you can. You can wrap the Photon interface in an interface.

public interface INetworking {
  GameObject GameObjectInstantiate();
  Network NetworkInstantiate();
  ...
};

Then you implement this interface twice, once for “Photon as back end” and once for “testing framework as back end.”

Then you pass this INetworking interface along to all the objects and scripts that need it. Or, if you're lazy, assign it to a singleton/global, from which all your scripts would read it.

enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement