Skip to content

Utilities ‐ Extension Methods

Wagner GFX edited this page Dec 9, 2024 · 1 revision

A small collection of helper methods to solve common problems in Unity's native classes and objects.

Unlike other plugins, this one has no namespace by design, since they are expected to extend common classes all around the codebase.

MonoBehaviour

AssertObjectField

Easily validates an empty serialized field of type Object and issues a basic warning. Use this function during OnValidate().

UnityObject

Simple object validation and file checking functions.

IsValid

Returns true when an object is not null or named "null". As, there are situations where a property or parameter may be filled with a "null" default object.

IsNull

Simply the inverse of IsValid.

IsAssetFile

Check if the object is an existing file in the project.

IsAssetFolder

Check if the object is an existing folder in the project.

IsAssetFileOrFolder

Check if the object represents any file or folder in the project.

IsPrefabAsset

Check if the object is a prefab file in the project.

Vector

Useful detection and conversion methods for float based Vector2 and Vector3 classes.

CollapseAxisToSign

Converts the individual axis values of any vector to a simple 1, 0 or -1. The result is NOT normalized.

Use the optional epsilon parameter to control how precise the function will evaluate small numbers. The default is absolute precision.

IsCardinal

Return true when a vector value represents one of the cardinal direction constants, except for zero and one.

ClosestCardinalDirection

Returns the closest cardinal direction constant of the supplied vector.

Clone this wiki locally