Class KeyedComponentHelper
- Namespace
- MonkeyLoader.Resonite
- Assembly
- MonkeyLoader.Resonite.Core.dll
Contains extension methods to deal with keyed FrooxEngine.Components in FrooxEngine.Worlds.
public static class KeyedComponentHelper
- Inheritance
-
KeyedComponentHelper
- Inherited Members
Methods
GetKeyedComponentOrCreate<T>(Slot, string, Action<T>?, int, bool, bool)
public static T GetKeyedComponentOrCreate<T>(this Slot slot, string key, Action<T>? onCreated = null, int version = 0, bool replaceExisting = false, bool updateExisting = false) where T : Component, new()
Parameters
slotSlotThe slot to attach the
Tcomponent to when necessary.keystringThe unique key (to) associate(d) with the
Tcomponent.onCreatedAction<T>The optional configuration action to call when the
Tcomponent had to be created, or when its saved version is lower than the givenversionnumber.versionintThe version number to associate with the
Tcomponent after this call.replaceExistingboolWhether to replace a different component associated with the given
keywith this one.updateExistingboolWhether to call
onCreatedeven if theTcomponent already exists.
If the givenversionnumber is greater than zero and the saved version is lower, this will always be done.
Returns
- T
The existing or newly created
Tcomponent.
Type Parameters
TThe type of the component to get or create.
Remarks
This behavior was adapted from GetComponentOrAttach<T>(Predicate<T>).
Consider that these component-associations will be saved with the FrooxEngine.World. Make sure that this is really necessary for what you're attempting to do.
Exceptions
- InvalidOperationException
When an incompatible component is associated with the given
keyandreplaceExistingwas false.
TryGetKeyedComponentOrCreate<T>(Slot, string, out T?, Action<T>?, int, bool, bool)
public static bool TryGetKeyedComponentOrCreate<T>(this Slot slot, string key, out T? component, Action<T>? onCreated = null, int version = 0, bool replaceExisting = false, bool updateExisting = false) where T : Component, new()
Parameters
slotSlotThe slot to attach the
Tcomponent to when necessary.keystringThe unique key (to) associate(d) with the
Tcomponent.componentTThe
Tcomponent associated with the givenkeyif this call returns true; otherwise, null when an incompatible component is associated with it andreplaceExistingwas false.onCreatedAction<T>The optional configuration action to call when the
Tcomponent had to be created, or when its saved version is lower than the givenversionnumber.versionintThe version number to associate with the
Tcomponent after this call.replaceExistingboolWhether to replace a different component associated with the given
keywith this one.updateExistingboolWhether to call
onCreatedeven if theTcomponent already exists.
If the givenversionnumber is greater than zero and the saved version is lower, this will always be done.
Returns
Type Parameters
TThe type of the component to get or create.
Remarks
This behavior was adapted from GetComponentOrAttach<T>(Predicate<T>).
Consider that these component-associations will be saved with the FrooxEngine.World. Make sure that this is really necessary for what you're attempting to do.