Table of Contents

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)

Gets or creates a keyed T component, based on the situation and parameters.

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

slot Slot

The slot to attach the T component to when necessary.

key string

The unique key (to) associate(d) with the T component.

onCreated Action<T>

The optional configuration action to call when the T component had to be created, or when its saved version is lower than the given version number.

version int

The version number to associate with the T component after this call.

replaceExisting bool

Whether to replace a different component associated with the given key with this one.

updateExisting bool

Whether to call onCreated even if the T component already exists.
If the given version number is greater than zero and the saved version is lower, this will always be done.

Returns

T

The existing or newly created T component.

Type Parameters

T

The 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 key and replaceExisting was false.

TryGetKeyedComponentOrCreate<T>(Slot, string, out T?, Action<T>?, int, bool, bool)

Tries to get or create a keyed T component, based on the situation and parameters.

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

slot Slot

The slot to attach the T component to when necessary.

key string

The unique key (to) associate(d) with the T component.

component T

The T component associated with the given key if this call returns true; otherwise, null when an incompatible component is associated with it and replaceExisting was false.

onCreated Action<T>

The optional configuration action to call when the T component had to be created, or when its saved version is lower than the given version number.

version int

The version number to associate with the T component after this call.

replaceExisting bool

Whether to replace a different component associated with the given key with this one.

updateExisting bool

Whether to call onCreated even if the T component already exists.
If the given version number is greater than zero and the saved version is lower, this will always be done.

Returns

bool

true if the keyed T component was found or created; otherwise, false.

Type Parameters

T

The 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.