Cyclops Manager Promises - PrimeSonic/PrimeSonicSubnauticaMods GitHub Wiki

You can think of the CyclopsManager as a pseudo-component that follows some of the ideas of of Unity's MonoBehaviors while ultimately being stripped down to the absolute bare essentials of a simple class.


With that in mind, the CyclopsManager makes the following promises of itself and any Auxiliary Cyclops Manager that you register through it.

1. Cyclops Managers and Cyclops SubRoot instances share a 1:1 relationship

  • Each Cyclops SubRoot has 1 and only 1 CyclopsManager
  • Each Cyclops SubRoot will have 1 and only 1 of each type of Auxiliary Cyclops Manager registered by an external mod

2. Cyclops Managers can be found using the SubRoot instance itself

Given a SubRoot cyclops instance, any manager can be found like this.

MyManager mgr = MCUServices.Find.AuxCyclopsManager<MyManager>(cyclops);

3. Cyclops Managers can be found even without a specific SubRoot reference

If you need to access all of your Cyclops Managers without a SubRoot reference, you can use this.

IEnumerable<MyManager> mgrs = AllAuxCyclopsManagers<MyManager>();
foreach (MyManager mgr in mgrs)
{....}

This pattern can be very powerful if one component needs to connect with others in the same Cyclops but one of them is missing a reference to the SubRoot.

4. You can tailor an Auxiliary Cyclops Managers to your needs

Registering your AuxCyclopsManager requires only that you provide a method that, given a SubRoot instance, returns your IAuxCyclopsManager.
The interface requires very little, so you can use any class you want as your IAuxCyclopsManager.
What happens inside that method is up to you as long as it returns the IAuxCyclopsManager instance.
And once you Find it, there's nothing tell you what you can or can't do with it.

Your AuxCyclopsManager can be whatever you want it to be that suites your needs best.

As of version 4.0.5 of MoreCyclopsUpgrades, Auxiliary Cyclops Managers are added to the collection on demand when they are first requested by a call into MCUServices.Find.AuxCyclopsManager.


And that's really it.
Cyclops Managers are very simple while offering a quick and powerful way to locate them on demand.
If your mod includes CyclopsChargers, UpgradeHandler, and MonoBehaviors that somehow need to all interact with each other, a Cyclops Manager could be the glue that links them all together.

⚠️ **GitHub.com Fallback** ⚠️