I have part of my game/simulation running managed code and part ECS. The managed part is only some UI with user interaction.
The UIManager (MonoBehaviour) listens for changes in the input controls (sliders, input fields, etc). These are parameters that my ECS part rely on for calculations, so any changes in the UI results in some change to the data in the ECS world.
Normally, and my first approach was to expose event Action<MyData> and then have the System register those events and then modify the ECS data when events gets Invoked.
I'm still kinda new to ECS so i've sought help here before, but i wanted to make sure that i'm not making it harder that it needs to be. These are the guides/suggestions i got so far (or rather how i interpreted it) and i would really like to know if i misunderstood something.
- The System that reads from the UIManager should be a SystemBase and not an ISystem
- I should not register for event callbacks in a System (i figure because we only want that system to do anything in its Update loop, and events would fire from the UIManager's OnUpdate since that obviously won't automatically correspond to the specific Systems Update loop.
- I should poll the UIManager from the Update in my System and somehow keep track of any changes to any data i read off the UIManager.
All my current code revolves around those three constraints (or two 1, 2+3). I even made a wrapper class for any data in my UIManager that keeps track of wether the current data has been read or not (so the System only needs to change the ECS data if the data in the UIManager changed).
Is this the right approach? Can i simplify this? Whenever changes happen in the UI i can live with a lag spike.