RoR2-ChensHelpers

Contains simple and useful helpers for RoR2 mod creators to use. Mainly caters to Chen's mods.

View on GitHub

ChensHelpers

Chen.Helpers.UnityHelpers.Extensions

Extensions.GetOrAddComponent<T>(GameObject, Action<T>) Method

An extension that allows fetching or adding a component.
This overload contains post-processing logic of the component.
Only used for cleaner code. Otherwise it is equivalent to assigning values after this method call.

public static T GetOrAddComponent<T>(this GameObject gameObject, System.Action<T> action)
    where T : Component;

Type parameters

T
A Unity Component

Parameters

gameObject UnityEngine.GameObject
The GameObject to fetch from or add to

action System.Action<T>
Post-Processor code

Returns

T
The component specified as T