Hello folks,
I have an inheritance system for the game I’m developing that is intended for single player. I now want to move it to multiplayer. The problem is that I have to extend NetworkBehaviour
at some point, but I don’t want all of my hierarchy to be networked.
Here is my current system:
(abstract class) MeshedObject : MonoBehaviour //contains static methods for creating meshes of certain shapes. Contains a reference to the object which holds the mesh color scheme. Contains abstract methods for getting sorting layer and how to use the color scheme. Uses Start and Update to set initial values.
(abstract class) Unit : MeshedObject //the base class for all military units in the game, which are all made with simple meshes. Contains basic ideas such as health, contains virtual functions to take damage and die. Holds static prefabs for its child units and an init function to load those.
(abstract class) TargetingUnit : Unit //the base class for all units that use targeting. Contains a GameObject[] target variable. Contains a virtual targeting function and way of getting a random target, virtual layer mask calculation functions. Uses Start and Update. This should be networked.
(abstract class) MeshedEffect : MeshedObject //the base class for simple game effects which also use meshes. I do not want these networked. Contains overrides for some of the MeshedObject specifications. Contains a "constructor" for setting a parent and such.
//these are the only "root" classes, other classes which extend these not shown.
Here is a possible solution to the networking problem:
(static class) MeshHandler //contains the static mesh-getting functions
(interface) IMeshedObject //contains the "variables" previously in MeshedObject but as interface get/sets.
(abstract class) Unit : NetworkBehaviour, IMeshedObject
(abstract class) TargetingUnit : Unit
(abstract class) MeshedEffect : MonoBehaviour, IMeshedObject
However, there is the problem that the IMeshedObject can’t use Start and Update to initialize the “variables” anymore, I have to trust the implementing classes to do that. Can this be solved?
–
I’m not an expert on C# inheritance and am looking for advice on how I should implement this.
Thanks for any input,
Nomenokes