Show / Hide Table of Contents

Class ModUtility

A few utility functions that are often useful for mods.

Inheritance
Object
ModUtility
Namespace: Modding
Assembly: Assembly-CSharp.dll
Syntax
public static class ModUtility

Methods

CopyComponent<T>(T, GameObject)

Creates a copy of the given component on the destination game object.

Adds a component of the same type to the destination game object and then copies its field's values as described in CopyComponentValues.

Declaration
public static T CopyComponent<T>(T original, GameObject destination)
    where T : Component
Parameters
Type Name Description
T original

Original component.

UnityEngine.GameObject destination

Destination game object.

Returns
Type Description
T

The newly-created copied component.

Type Parameters
Name Description
T

Type of the component to copy.

See Also
CopyComponentValues<T>(T, T)

CopyComponentValues<T>(T, T)

Copies the values of fields of one component onto another one.

All values of all public fields and private fields marked with the SerializeField attribute are directly copied.

This is somewhat similar to the copy Unity does when instantiating objects but it doesn't attempt to also modify references to other components on the same game object or the game object itself etc.

This means this won't always copy all components entirely correctly but it is still often useful. It is always possible to copy or adjust more values by hand after calling this method.

Declaration
public static T CopyComponentValues<T>(T original, T destination)
    where T : Component
Parameters
Type Name Description
T original

Original component.

T destination

Destination of the copy.

Returns
Type Description
T

The destination.

Type Parameters
Name Description
T

Type of the component to copy.

GetWindowId()

Returns an ID that is guaranteed to be unique among the IDs supplied by this function to all callers.

Can be used as a window ID for Unity's Legacy GUI system to avoid conflicts with other mods.

Declaration
public static int GetWindowId()
Returns
Type Description
Int32
Back to top Generated by DocFX