Skip to main content

QWR Utilities API Reference

This page provides a comprehensive API reference for the QWR Utilities package. It documents the key classes, interfaces, and methods available in the library.

Namespace: QWR.Utilities

The main namespace for QWR Utilities components.

MonoBehaviourSingleton<T>

Base class for creating singleton MonoBehaviours.

Properties

NameTypeDescription
InstanceTStatic instance of the singleton.
HasInstanceboolWhether the singleton instance exists.
DestroyDuplicateInstancesboolWhether to destroy duplicate instances.
DontDestroyOnLoadInstanceboolWhether to mark the instance with DontDestroyOnLoad.

Methods

NameReturn TypeParametersDescription
Awake()voidNoneInitializes the singleton instance.
OnDestroy()voidNoneCleans up the singleton instance.
OnDuplicateInstanceFound(T instance)voidinstance: The duplicate instanceCalled when a duplicate instance is found.

ScriptableSingleton<T>

Base class for creating singleton ScriptableObjects.

Properties

NameTypeDescription
InstanceTStatic instance of the singleton.
HasInstanceboolWhether the singleton instance exists.
ResourcePathstringThe path to load the ScriptableObject from Resources.

Methods

NameReturn TypeParametersDescription
OnEnable()voidNoneInitializes the singleton instance.
OnDisable()voidNoneCleans up the singleton instance.

PersistentSingleton<T>

Singleton that persists between scene loads.

Properties

NameTypeDescription
InstanceTStatic instance of the singleton.
HasInstanceboolWhether the singleton instance exists.

Methods

NameReturn TypeParametersDescription
Awake()voidNoneInitializes the singleton instance and marks it with DontDestroyOnLoad.
OnDestroy()voidNoneCleans up the singleton instance.

LazyStaticSingleton<T>

Non-MonoBehaviour singleton with lazy initialization.

Properties

NameTypeDescription
InstanceTStatic instance of the singleton.
HasInstanceboolWhether the singleton instance exists.

Methods

NameReturn TypeParametersDescription
Dispose()voidNoneDisposes of the singleton instance.

Namespace: QWR.Utilities.Logging

Contains components related to the logging system.

QWRLogger

Static class for enhanced logging.

Methods

NameReturn TypeParametersDescription
Log(string message)voidmessage: The message to logLogs a message at the Info level.
Log(string message, LogCategory category)voidmessage: The message to log, category: The log categoryLogs a message with a category at the Info level.
Log(string message, UnityEngine.Object context)voidmessage: The message to log, context: The context objectLogs a message with a context object at the Info level.
LogDebug(string message)voidmessage: The message to logLogs a message at the Debug level.
LogInfo(string message)voidmessage: The message to logLogs a message at the Info level.
LogWarning(string message)voidmessage: The message to logLogs a message at the Warning level.
LogError(string message)voidmessage: The message to logLogs a message at the Error level.
LogFatal(string message)voidmessage: The message to logLogs a message at the Fatal level.
LogIf(bool condition, string message)voidcondition: The condition to check, message: The message to logLogs a message only if the condition is true.
LogFormat(string format, params object[] args)voidformat: The format string, args: The format argumentsLogs a formatted message at the Info level.
LogFormat(LogCategory category, string format, params object[] args)voidcategory: The log category, format: The format string, args: The format argumentsLogs a formatted message with a category at the Info level.
LogPerformance(string operationName)QWRPerformanceMarkeroperationName: The name of the operationStarts a performance measurement.
LogPerformance(string operationName, LogCategory category)QWRPerformanceMarkeroperationName: The name of the operation, category: The log categoryStarts a performance measurement with a category.
LogPerformance(string operationName, float threshold)QWRPerformanceMarkeroperationName: The name of the operation, threshold: The time threshold in millisecondsStarts a performance measurement with a threshold.
BeginPerformanceMeasurement(string operationName)QWRPerformanceMarkeroperationName: The name of the operationBegins a manual performance measurement.
SetLogLevel(LogLevel level)voidlevel: The minimum log levelSets the minimum log level.
EnableCategory(LogCategory category)voidcategory: The category to enableEnables a log category.
DisableCategory(LogCategory category)voidcategory: The category to disableDisables a log category.
IsCategoryEnabled(LogCategory category)boolcategory: The category to checkChecks if a log category is enabled.
EnableLogging(bool enabled)voidenabled: Whether logging is enabledEnables or disables all logging.
EnableFileLogging(bool enabled)voidenabled: Whether file logging is enabledEnables or disables file logging.
SetLogFilePath(string path)voidpath: The file pathSets the log file path.
FlushLogFile()voidNoneFlushes the log file.
RegisterLogHandler(IQWRLogHandler handler)voidhandler: The log handler to registerRegisters a custom log handler.
UnregisterLogHandler(IQWRLogHandler handler)voidhandler: The log handler to unregisterUnregisters a custom log handler.

LogCategory

Represents a category for logs.

Properties

NameTypeDescription
NamestringThe name of the category.
IsEnabledboolWhether the category is enabled.

Methods

NameReturn TypeParametersDescription
ToString()stringNoneReturns the name of the category.

LogLevel

Enum representing log levels.

public enum LogLevel
{
Debug,
Info,
Warning,
Error,
Fatal,
None
}

QWRPerformanceMarker

Represents a performance measurement.

Properties

NameTypeDescription
OperationNamestringThe name of the operation being measured.
ElapsedMillisecondsfloatThe elapsed time in milliseconds.
IsRunningboolWhether the measurement is running.

Methods

NameReturn TypeParametersDescription
End()floatNoneEnds the measurement and returns the elapsed time.
Dispose()voidNoneEnds the measurement and logs the result.

IQWRLogHandler

Interface for custom log handlers.

public interface IQWRLogHandler
{
void HandleLog(LogLevel level, LogCategory category, string message, UnityEngine.Object context);
}

IQWRLogFormatter

Interface for custom log formatters.

public interface IQWRLogFormatter
{
string FormatLogMessage(LogLevel level, LogCategory category, string message);
}

Namespace: QWR.Utilities.Extensions

Contains extension methods for various types.

TransformExtensions

Extension methods for Transform.

Methods

NameReturn TypeParametersDescription
SetPositionX(this Transform transform, float x)voidtransform: The transform to modify, x: The X positionSets the X position of the transform.
SetPositionY(this Transform transform, float y)voidtransform: The transform to modify, y: The Y positionSets the Y position of the transform.
SetPositionZ(this Transform transform, float z)voidtransform: The transform to modify, z: The Z positionSets the Z position of the transform.
GetPositionX(this Transform transform)floattransform: The transform to queryGets the X position of the transform.
GetPositionY(this Transform transform)floattransform: The transform to queryGets the Y position of the transform.
GetPositionZ(this Transform transform)floattransform: The transform to queryGets the Z position of the transform.
SetLocalPositionX(this Transform transform, float x)voidtransform: The transform to modify, x: The local X positionSets the local X position of the transform.
SetLocalPositionY(this Transform transform, float y)voidtransform: The transform to modify, y: The local Y positionSets the local Y position of the transform.
SetLocalPositionZ(this Transform transform, float z)voidtransform: The transform to modify, z: The local Z positionSets the local Z position of the transform.
ResetLocal(this Transform transform)voidtransform: The transform to resetResets the local position, rotation, and scale to identity/one.
ResetPosition(this Transform transform)voidtransform: The transform to resetResets the position to zero.
ResetRotation(this Transform transform)voidtransform: The transform to resetResets the rotation to identity.
ResetScale(this Transform transform)voidtransform: The transform to resetResets the scale to one.
TransformPointUnscaled(this Transform transform, Vector3 position)Vector3transform: The transform to use, position: The local positionTransforms a point from local space to world space without applying scale.
InverseTransformPointUnscaled(this Transform transform, Vector3 position)Vector3transform: The transform to use, position: The world positionTransforms a point from world space to local space without applying scale.
LookAtWithUp(this Transform transform, Vector3 target, Vector3 up)voidtransform: The transform to modify, target: The target position, up: The up directionRotates the transform to look at a target with a specific up direction.
SetForwardDirection(this Transform transform, Vector3 direction)voidtransform: The transform to modify, direction: The forward directionSets the rotation to face a specific direction.
DestroyChildren(this Transform transform)voidtransform: The transform to modifyDestroys all children of the transform.
GetChildren(this Transform transform)Transform[]transform: The transform to queryGets all children of the transform.
FindChildByName(this Transform transform, string name, bool recursive = false)Transformtransform: The transform to search, name: The child name, recursive: Whether to search recursivelyFinds a child by name.
GetOrCreateChild(this Transform transform, string name)Transformtransform: The transform to modify, name: The child nameGets or creates a child with the specified name.
SetParentPreserveWorld(this Transform transform, Transform parent)voidtransform: The transform to modify, parent: The new parentSets the parent with world position/rotation preserved.
GetHierarchyPath(this Transform transform)stringtransform: The transform to queryGets the full hierarchy path of the transform.
GetRootParent(this Transform transform)Transformtransform: The transform to queryGets the root parent of the transform.

GameObjectExtensions

Extension methods for GameObject.

Methods

NameReturn TypeParametersDescription
GetOrAddComponent<T>(this GameObject gameObject)TgameObject: The GameObject to modifyGets a component or adds it if it doesn't exist.
TryGetComponent<T>(this GameObject gameObject, out T component)boolgameObject: The GameObject to query, component: The output componentTries to get a component.
HasComponent<T>(this GameObject gameObject)boolgameObject: The GameObject to queryChecks if the GameObject has a component.
GetComponentsInChildrenIncludingInactive<T>(this GameObject gameObject)T[]gameObject: The GameObject to queryGets components in children including inactive ones.
GetComponentInParent<T>(this GameObject gameObject, bool includeInactive = false)TgameObject: The GameObject to query, includeInactive: Whether to include inactive parentsGets a component in parent.
SetLayer(this GameObject gameObject, int layer)voidgameObject: The GameObject to modify, layer: The layer to setSets the layer of the GameObject.
SetLayerRecursively(this GameObject gameObject, int layer)voidgameObject: The GameObject to modify, layer: The layer to setSets the layer of the GameObject and all its children.
IsInLayerMask(this GameObject gameObject, LayerMask layerMask)boolgameObject: The GameObject to query, layerMask: The layer mask to checkChecks if the GameObject is in the layer mask.
CompareTag(this GameObject gameObject, string tag)boolgameObject: The GameObject to query, tag: The tag to checkChecks if the GameObject has the specified tag (null-safe).
GetChildren(this GameObject gameObject)GameObject[]gameObject: The GameObject to queryGets all children of the GameObject.
GetActiveChildren(this GameObject gameObject)GameObject[]gameObject: The GameObject to queryGets all active children of the GameObject.
DestroyChildren(this GameObject gameObject)voidgameObject: The GameObject to modifyDestroys all children of the GameObject.
InstantiateAsChild(this GameObject gameObject, GameObject prefab)GameObjectgameObject: The GameObject to modify, prefab: The prefab to instantiateInstantiates a prefab as a child of the GameObject.
GetOrCreateChild(this GameObject gameObject, string name)GameObjectgameObject: The GameObject to modify, name: The child nameGets or creates a child with the specified name.
GetFullPath(this GameObject gameObject)stringgameObject: The GameObject to queryGets the full path of the GameObject.

ComponentExtensions

Extension methods for Component.

Methods

NameReturn TypeParametersDescription
Enable(this Component component)voidcomponent: The Component to modifyEnables the Component.
Disable(this Component component)voidcomponent: The Component to modifyDisables the Component.
IsEnabled(this Component component)boolcomponent: The Component to queryChecks if the Component is enabled.
GetComponentInParentOrSelf<T>(this Component component)Tcomponent: The Component to queryGets a component in parent or self.
FindObjectsOfTypeIncludingInactive<T>()T[]NoneFinds all objects of type including inactive ones.
FindObjectsOfTypeWithInterface<T>()T[]NoneFinds all objects that implement an interface.

ListExtensions

Extension methods for List.

Methods

NameReturn TypeParametersDescription
Initialize<T>(this List<T> list, int count, Func<int, T> initializer)List<T>list: The list to initialize, count: The number of items, initializer: The initialization functionInitializes a list with values.
Shuffle<T>(this List<T> list)voidlist: The list to shuffleShuffles the list.
GetRandom<T>(this List<T> list)Tlist: The list to queryGets a random item from the list.
RemoveAndGet<T>(this List<T> list, int index)Tlist: The list to modify, index: The index to removeRemoves and returns the item at the specified index.
RemoveNulls<T>(this List<T> list) where T : classvoidlist: The list to modifyRemoves all null entries from the list.
AddRangeIf<T>(this List<T> list, IEnumerable<T> collection, Func<T, bool> predicate)voidlist: The list to modify, collection: The items to add, predicate: The conditionAdds items from a collection if they match a condition.
ForEach<T>(this List<T> list, Action<T, int> action)voidlist: The list to process, action: The action to performPerforms an action on each item with its index.
AddUnique<T>(this List<T> list, T item)boollist: The list to modify, item: The item to addAdds an item if it's not already in the list.
ContainsAll<T>(this List<T> list, IEnumerable<T> collection)boollist: The list to check, collection: The items to check forChecks if the list contains all items from a collection.
DistinctBy<T, TKey>(this IEnumerable<T> source, Func<T, TKey> keySelector)IEnumerable<T>source: The source collection, keySelector: The key selector functionReturns distinct elements by a key selector.

Namespace: QWR.Utilities.Data

Contains data structures and serialization helpers.

QWRObjectPool<T>

Generic object pool for MonoBehaviours.

Properties

NameTypeDescription
ActiveCountintThe number of active objects.
InactiveCountintThe number of inactive objects.
TotalCountintThe total number of objects.

Methods

NameReturn TypeParametersDescription
Get()TNoneGets an object from the pool.
Release(T obj)voidobj: The object to releaseReleases an object back to the pool.
Preload(int count)voidcount: The number of objects to preloadPreloads a number of objects.
Clear()voidNoneClears the pool.

QWRGenericPool<T>

Generic object pool for non-MonoBehaviours.

Properties

NameTypeDescription
ActiveCountintThe number of active objects.
InactiveCountintThe number of inactive objects.
TotalCountintThe total number of objects.

Methods

NameReturn TypeParametersDescription
Get()TNoneGets an object from the pool.
Release(T obj)voidobj: The object to releaseReleases an object back to the pool.
Preload(int count)voidcount: The number of objects to preloadPreloads a number of objects.
Clear()voidNoneClears the pool.

QWRPriorityQueue<T>

Generic priority queue.

Properties

NameTypeDescription
CountintThe number of items in the queue.

Methods

NameReturn TypeParametersDescription
Enqueue(T item, float priority)voiditem: The item to enqueue, priority: The priority valueAdds an item to the queue with the specified priority.
Dequeue()TNoneRemoves and returns the highest priority item.
Peek()TNoneReturns the highest priority item without removing it.
Contains(T item)boolitem: The item to checkChecks if the queue contains the specified item.
Clear()voidNoneClears the queue.

QWRObservableList<T>

List that raises events when modified.

Properties

NameTypeDescription
CountintThe number of items in the list.

Methods

NameReturn TypeParametersDescription
Add(T item)voiditem: The item to addAdds an item to the list.
Remove(T item)boolitem: The item to removeRemoves an item from the list.
Clear()voidNoneClears the list.
Contains(T item)boolitem: The item to checkChecks if the list contains the specified item.
IndexOf(T item)intitem: The item to findGets the index of the specified item.
Insert(int index, T item)voidindex: The index to insert at, item: The item to insertInserts an item at the specified index.
RemoveAt(int index)voidindex: The index to removeRemoves the item at the specified index.

Events

NameEvent TypeDescription
OnItemAddedAction<T>Triggered when an item is added.
OnItemRemovedAction<T>Triggered when an item is removed.
OnListClearedActionTriggered when the list is cleared.

QWRSerializableDictionary<TKey, TValue>

Dictionary that can be serialized by Unity.

Properties

NameTypeDescription
CountintThe number of key-value pairs in the dictionary.
KeysICollection<TKey>The keys in the dictionary.
ValuesICollection<TValue>The values in the dictionary.

Methods

NameReturn TypeParametersDescription
Add(TKey key, TValue value)voidkey: The key, value: The valueAdds a key-value pair to the dictionary.
Remove(TKey key)boolkey: The key to removeRemoves a key-value pair from the dictionary.
Clear()voidNoneClears the dictionary.
ContainsKey(TKey key)boolkey: The key to checkChecks if the dictionary contains the specified key.
TryGetValue(TKey key, out TValue value)boolkey: The key to find, value: The output valueTries to get the value for the specified key.

QWRWeightedList<T>

List where items have weights for random selection.

Properties

NameTypeDescription
CountintThe number of items in the list.
TotalWeightfloatThe total weight of all items.

Methods

NameReturn TypeParametersDescription
Add(T item, float weight)voiditem: The item to add, weight: The item's weightAdds an item with the specified weight.
Remove(T item)boolitem: The item to removeRemoves an item from the list.
Clear()voidNoneClears the list.
GetRandom()TNoneGets a random item based on weights.
GetRandomMultiple(int count)T[]count: The number of items to getGets multiple random items based on weights.
GetRandomExcluding(T excludedItem)TexcludedItem: The item to excludeGets a random item excluding the specified item.
UpdateWeight(T item, float newWeight)boolitem: The item to update, newWeight: The new weightUpdates the weight of an item.

QWRStateMachine<TState, TContext>

Generic state machine.

Properties

NameTypeDescription
CurrentStateTStateThe current state.
PreviousStateTStateThe previous state.
ContextTContextThe context object.

Methods

NameReturn TypeParametersDescription
RegisterState(TState state, Action enterAction, Action updateAction, Action exitAction)voidstate: The state to register, enterAction: The enter action, updateAction: The update action, exitAction: The exit actionRegisters a state with its actions.
SetState(TState newState)boolnewState: The new stateSets the current state.
Update()voidNoneUpdates the current state.

Namespace: QWR.Utilities.Math

Contains mathematical utilities and helpers.

QWRMath

Static class with math utilities.

Methods

NameReturn TypeParametersDescription
SmoothDamp(float current, float target, ref float velocity, float smoothTime)floatcurrent: Current value, target: Target value, velocity: Current velocity, smoothTime: Smoothing timeSmoothly interpolates between values.
SmoothDamp(Vector3 current, Vector3 target, ref Vector3 velocity, float smoothTime)Vector3current: Current value, target: Target value, velocity: Current velocity, smoothTime: Smoothing timeSmoothly interpolates between vectors.
CubicBezier(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t)Vector3p0, p1, p2, p3: Control points, t: Interpolation parameterCalculates a point on a cubic Bezier curve.
SignedAngle(Vector3 from, Vector3 to, Vector3 axis)floatfrom: From direction, to: To direction, axis: Rotation axisCalculates the signed angle between vectors.
RandomRange(int min, int max)intmin: Minimum value, max: Maximum valueReturns a random integer in the specified range.
RandomRange(float min, float max)floatmin: Minimum value, max: Maximum valueReturns a random float in the specified range.
RandomPointInSphere(float radius)Vector3radius: Sphere radiusReturns a random point inside a sphere.
RandomPointOnSphere(float radius)Vector3radius: Sphere radiusReturns a random point on a sphere.
EaseInOut(float start, float end, float t)floatstart: Start value, end: End value, t: Interpolation parameterApplies ease-in-out interpolation.
EaseBounce(float start, float end, float t)floatstart: Start value, end: End value, t: Interpolation parameterApplies bounce interpolation.
EaseElastic(float start, float end, float t)floatstart: Start value, end: End value, t: Interpolation parameterApplies elastic interpolation.

Interfaces

IQWRPoolable

Interface for poolable objects.

public interface IQWRPoolable
{
void OnGetFromPool();
void OnReleaseToPool();
}

IQWRState<TContext>

Interface for state machine states.

public interface IQWRState<TContext>
{
void OnEnter();
void OnUpdate();
void OnExit();
}

Next Steps

For more detailed information about specific components, check out the following pages: