I have recently decided to break my very large character class into multiple smaller classes. An example of these smaller classes can be seen in the picture above. The main class for a character is now c_Manager. This class is initialized by the level loader and is used by all characters including player. It then initializes a series on sub-classes that control all aspects of a character from inventory to model. The problem I am running into is that many of the sub-classes need to communicate with each other (such as c_Controller needs data from c_Status to determine the speed the player should be moving, or c_Model needs data from c_Controller to determine the animation to play) , and I have been unable to find a clean/efficient way to do this.
This is an example of how the c_Manager class is set up:
public class c_Manager : MonoBehaviour {
c_Controller controller;
c_Status status;
c_Model model;
void Start () {
controller = new c_Controller(somedata);
status = new c_Status(somedata);
model = new c_Model(somedata);
}
void Update () {
controller.Update();
status.Update();
model.Update();
}
}
And one of the sub-classes showing where I need the data:
public class c_Controller{
public c_Controller(var somedata) {
// INITIALIZE
}
void Update () {
-> I NEED DATA FROM THE OTHER SUB-CLASSES HERE! <-
}
}
I am sure there is a very simple solution to this, but I come from a C only background and some of the Object Oriented logic can stump me pretty hard.
~Thanks, Malarkey
