WEKIT-ECS / MIRAGE-XR

MirageXR is a reference implementation of an XR training system. MirageXR enables experts and learners to share experience via XR and wearables using ghost tracks, realtime feedback, and anchored instruction.
Other
27 stars 4 forks source link

i5 Services or RootObject managers? #1899

Open fwild opened 2 months ago

BenediktHensen commented 1 month ago

Pros of services:

Cons of services:

Services encourage modular, abstracted code where the developer is very concious about all added dependencies to other code or to scene elements. Personally, I quite like this as it means that an architecture with a clear separation between data, application logic and the scene can develop. This way, the application logic layer has well-defined interaction points to read and act on elements in the scene. Unity's components, and thereby, also managers, blur this a lot more as they are already part of the scene and tied to GameObjects. With these MonoBehaviour components, it is more tempting to just quickly reference GameObjects and other components to get the necessary data to realize a functionality without considering whether it would be better to first organize information into an abstracted overarching data model that then drives the logic. However, achieving a well-separated architecture where no corners are cut, is a constant effort and is especially difficult to do in an existing project that already relies a lot on components.

My proposal is to not fully ban the use of one of the two approaches but instead have a clear guide on when to use which. I would suggest the following distinction:

cawke commented 3 weeks ago

in fact, in the current implementation there is almost no difference between i5.Service and RootObject, and almost all the advantages described above can be applied to RootObject.

if the current managers are renamed into services, implement the basic interface; they can also be used in i5.Service.

about MonoBehaviour in managers. Managers should not inherit from MonoBehaviour and use their base events. Now this is present only because we do not have a manager for working with Addressables to obtain the prefabs we need and the need to test various implementations of managers for different platforms in the editor. Also, inheritance from MonoBehaviour can be done for the purpose of Profiling the performance of an individual manager, but this is for the future.

i5.Service has a real advantage in terms of testing, since some managers may have links to other managers (which services in i5.Service will also have).

I would be happy with an intermediate option using i5.Service, which stores the managers currently implemented. The idea is that we work with a manager that works with services, stores some data and notifies everyone subscribed to it about data changes (mainly needed for future work with ui). We will also need a manager to work with various implementations of services for certain platforms, providing another level of abstraction.

but you need to understand that for this you will need to implement a manager for working with Addressables (which will still need to be done in the future).

Do we need to transfer RootObject to i5.Service now? Considering the small amount of time that I can now devote to the project and the number of our tasks, I think not. It is easier to transfer as managers those several services that currently use i5.Service.

current initialization of the root object image

current initialization of the i5.Service image