Skip to content

Finding Auxiliary Cyclops Managers

PrimeSonic edited this page Jul 25, 2019 · 1 revision

Finding Auxiliary Cyclops Managers

After you've registered your auxiliary manager and the Cyclops has loaded, you can now proceed to Find it. This process is almost exactly the same as it is for finding UpgradeHandlers, with an added option we'll look at as we go.

The Find services offer you two methods for finding your auxiliary manager.

Finding a manager for a given Cyclops

/// <summary>
/// Gets the typed <see cref="IAuxCyclopsManager"/> at the specified Cyclops sub with the given <seealso cref="IAuxCyclopsManager.Name"/>.
/// </summary>
/// <typeparam name="T">The class you created that implements <see cref="IAuxCyclopsManager"/>.</typeparam>
/// <param name="cyclops">The cyclops to search in.</param>
/// <returns>A type casted <see cref="IAuxCyclopsManager"/> if found; Otherwise returns null if not found.</returns>
/// <seealso cref="CreateAuxCyclopsManager"/>
T AuxCyclopsManager<T>(SubRoot cyclops) where T : class, IAuxCyclopsManager;

In these examples, T is a Generic Parameter that you will replace with your auxiliary manager's Type.
Calling this method will return the auxiliary manager associated to the cyclops instance you're looking at.

// Assuming you have a reference to the Cyclops SubRoot instance
SubRoot cyclops;

// You can fetch the manager for that Cyclops
MyAuxManager mgr = MCUServices.Find.AuxCyclopsManager<MyAuxManager>(cyclops));

Remember: your auxiliary manager's Initialize method will only be invoked once by MoreCyclopsUpgrades and only the first time that your mod requests that auxiliary manager using Find.AuxCyclopsManager or Find.AllAuxCyclopsManagers to locate it.

Finding managers without a Cyclops

/// <summary>
/// Gets all typed <see cref="IAuxCyclopsManager"/>s across all Cyclops subs with the given <seealso cref="IAuxCyclopsManager.Name"/>.
/// </summary>
/// <typeparam name="T">The class you created that implements <see cref="IAuxCyclopsManager"/>.</typeparam>
/// <returns>A type casted enumeration of all <see cref="IAuxCyclopsManager"/>s found across all Cyclops subs, identified by name.</returns>
IEnumerable<T> AllAuxCyclopsManagers<T>() where T : class, IAuxCyclopsManager;

Calling this method will let you iterate over all your auxiliary managers across all Cyclops instances in the game world.

IEnumerable<MyAuxManager> myManagers = MCUServices.Find.AllAuxCyclopsManagers<MyAuxManager>();
foreach (MyAuxManager mgr in myManagers)
{
}

Reasons you might want to use this:

  • You need to execute code across all Cyclops instances
  • Your Buildable component inside the Cyclops isn't able to locate the SubRoot in its parent components. See Origin Story
Clone this wiki locally