Skip to content

API.Unity.Util Extensions

JuDelCo edited this page May 20, 2021 · 28 revisions

Note: Add first using Ju.Extensions; so you can use these extension methods.

LayerMask Extensions

For Unity GameObject, Collision and Collider classes.

bool IsInLayerMask(LayerMask layerMask);

Color & Color32

Allows implicit and explicit conversion of Color & Color32 structs to and from the Unity ones.

Observable Extensions

This method will use a BehaviourLinkHandler to subscribe the Behaviour to the Observable.

void Subscribe<T>(Behaviour actor, Action<T> action, bool alwaysActive = false);

Clock Constructors

Clock(Behaviour behaviour, bool alwaysActive = false);
Clock(float elapsedSeconds, Behaviour behaviour, bool alwaysActive = false);

Timer Constructor

Timer(float seconds, Action onCompleted, Behaviour behaviour, bool alwaysActive = false);

FrameTimer Constructor

FrameTimer(int frames, Action onCompleted, Behaviour behaviour, bool alwaysActive = false);

Conversion Cast Extensions

// Cast.This(string)
Color AsColor(Color defaultValue = default(UnityEngine.Color));
Color32 AsColor32(Color32 defaultValue = default(Color32));
Vector2 AsVector2(Vector2 defaultValue = default(Vector2));
Vector2Int AsVector2Int(Vector2Int defaultValue = default(Vector2Int));
Vector3 AsVector3(Vector3 defaultValue = default(Vector3));
Vector3Int AsVector3Int(Vector3Int defaultValue = default(Vector3Int));
Vector4 AsVector4(Vector4 defaultValue = default(Vector4));

// Cast.This(Color)
string AsString(bool prependHashChar = true, bool toUpper = true);

// Cast.This(Color32)
string AsString(bool prependHashChar = true, bool toUpper = true);

// Cast.This(Vector2)
string AsString();

// Cast.This(Vector2Int)
string AsString();

// Cast.This(Vector3)
string AsString();

// Cast.This(Vector3Int)
string AsString();

// Cast.This(Vector4)
string AsString();

DataTypeConverter Converters

From Type To Type
Color Color32
Color32 Color
Vector2Int Vector2
Vector3Int Vector3
Vector2 Vector2Int
Vector3 Vector3Int
Color string
Color32 string
Vector2 string
Vector2Int string
Vector3 string
Vector3Int string
Vector4 string
string Color
string Color32
string Vector2
string Vector2Int
string Vector3
string Vector3Int
string Vector4
Clone this wiki locally