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
| Name | Type | Description |
|---|---|---|
Instance | T | Static instance of the singleton. |
HasInstance | bool | Whether the singleton instance exists. |
DestroyDuplicateInstances | bool | Whether to destroy duplicate instances. |
DontDestroyOnLoadInstance | bool | Whether to mark the instance with DontDestroyOnLoad. |
Methods
| Name | Return Type | Parameters | Description |
|---|---|---|---|
Awake() | void | None | Initializes the singleton instance. |
OnDestroy() | void | None | Cleans up the singleton instance. |
OnDuplicateInstanceFound(T instance) | void | instance: The duplicate instance | Called when a duplicate instance is found. |
ScriptableSingleton<T>
Base class for creating singleton ScriptableObjects.
Properties
| Name | Type | Description |
|---|---|---|
Instance | T | Static instance of the singleton. |
HasInstance | bool | Whether the singleton instance exists. |
ResourcePath | string | The path to load the ScriptableObject from Resources. |
Methods
| Name | Return Type | Parameters | Description |
|---|---|---|---|
OnEnable() | void | None | Initializes the singleton instance. |
OnDisable() | void | None | Cleans up the singleton instance. |
PersistentSingleton<T>
Singleton that persists between scene loads.
Properties
| Name | Type | Description |
|---|---|---|
Instance | T | Static instance of the singleton. |
HasInstance | bool | Whether the singleton instance exists. |
Methods
| Name | Return Type | Parameters | Description |
|---|---|---|---|
Awake() | void | None | Initializes the singleton instance and marks it with DontDestroyOnLoad. |
OnDestroy() | void | None | Cleans up the singleton instance. |
LazyStaticSingleton<T>
Non-MonoBehaviour singleton with lazy initialization.
Properties
| Name | Type | Description |
|---|---|---|
Instance | T | Static instance of the singleton. |
HasInstance | bool | Whether the singleton instance exists. |
Methods
| Name | Return Type | Parameters | Description |
|---|---|---|---|
Dispose() | void | None | Disposes of the singleton instance. |
Namespace: QWR.Utilities.Logging
Contains components related to the logging system.
QWRLogger
Static class for enhanced logging.
Methods
| Name | Return Type | Parameters | Description |
|---|---|---|---|
Log(string message) | void | message: The message to log | Logs a message at the Info level. |
Log(string message, LogCategory category) | void | message: The message to log, category: The log category | Logs a message with a category at the Info level. |
Log(string message, UnityEngine.Object context) | void | message: The message to log, context: The context object | Logs a message with a context object at the Info level. |
LogDebug(string message) | void | message: The message to log | Logs a message at the Debug level. |
LogInfo(string message) | void | message: The message to log | Logs a message at the Info level. |
LogWarning(string message) | void | message: The message to log | Logs a message at the Warning level. |
LogError(string message) | void | message: The message to log | Logs a message at the Error level. |
LogFatal(string message) | void | message: The message to log | Logs a message at the Fatal level. |
LogIf(bool condition, string message) | void | condition: The condition to check, message: The message to log | Logs a message only if the condition is true. |
LogFormat(string format, params object[] args) | void | format: The format string, args: The format arguments | Logs a formatted message at the Info level. |
LogFormat(LogCategory category, string format, params object[] args) | void | category: The log category, format: The format string, args: The format arguments | Logs a formatted message with a category at the Info level. |
LogPerformance(string operationName) | QWRPerformanceMarker | operationName: The name of the operation | Starts a performance measurement. |
LogPerformance(string operationName, LogCategory category) | QWRPerformanceMarker | operationName: The name of the operation, category: The log category | Starts a performance measurement with a category. |
LogPerformance(string operationName, float threshold) | QWRPerformanceMarker | operationName: The name of the operation, threshold: The time threshold in milliseconds | Starts a performance measurement with a threshold. |
BeginPerformanceMeasurement(string operationName) | QWRPerformanceMarker | operationName: The name of the operation | Begins a manual performance measurement. |
SetLogLevel(LogLevel level) | void | level: The minimum log level | Sets the minimum log level. |
EnableCategory(LogCategory category) | void | category: The category to enable | Enables a log category. |
DisableCategory(LogCategory category) | void | category: The category to disable | Disables a log category. |
IsCategoryEnabled(LogCategory category) | bool | category: The category to check | Checks if a log category is enabled. |
EnableLogging(bool enabled) | void | enabled: Whether logging is enabled | Enables or disables all logging. |
EnableFileLogging(bool enabled) | void | enabled: Whether file logging is enabled | Enables or disables file logging. |
SetLogFilePath(string path) | void | path: The file path | Sets the log file path. |
FlushLogFile() | void | None | Flushes the log file. |
RegisterLogHandler(IQWRLogHandler handler) | void | handler: The log handler to register | Registers a custom log handler. |
UnregisterLogHandler(IQWRLogHandler handler) | void | handler: The log handler to unregister | Unregisters a custom log handler. |
LogCategory
Represents a category for logs.
Properties
| Name | Type | Description |
|---|---|---|
Name | string | The name of the category. |
IsEnabled | bool | Whether the category is enabled. |
Methods
| Name | Return Type | Parameters | Description |
|---|---|---|---|
ToString() | string | None | Returns 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
| Name | Type | Description |
|---|---|---|
OperationName | string | The name of the operation being measured. |
ElapsedMilliseconds | float | The elapsed time in milliseconds. |
IsRunning | bool | Whether the measurement is running. |
Methods
| Name | Return Type | Parameters | Description |
|---|---|---|---|
End() | float | None | Ends the measurement and returns the elapsed time. |
Dispose() | void | None | Ends 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
| Name | Return Type | Parameters | Description |
|---|---|---|---|
SetPositionX(this Transform transform, float x) | void | transform: The transform to modify, x: The X position | Sets the X position of the transform. |
SetPositionY(this Transform transform, float y) | void | transform: The transform to modify, y: The Y position | Sets the Y position of the transform. |
SetPositionZ(this Transform transform, float z) | void | transform: The transform to modify, z: The Z position | Sets the Z position of the transform. |
GetPositionX(this Transform transform) | float | transform: The transform to query | Gets the X position of the transform. |
GetPositionY(this Transform transform) | float | transform: The transform to query | Gets the Y position of the transform. |
GetPositionZ(this Transform transform) | float | transform: The transform to query | Gets the Z position of the transform. |
SetLocalPositionX(this Transform transform, float x) | void | transform: The transform to modify, x: The local X position | Sets the local X position of the transform. |
SetLocalPositionY(this Transform transform, float y) | void | transform: The transform to modify, y: The local Y position | Sets the local Y position of the transform. |
SetLocalPositionZ(this Transform transform, float z) | void | transform: The transform to modify, z: The local Z position | Sets the local Z position of the transform. |
ResetLocal(this Transform transform) | void | transform: The transform to reset | Resets the local position, rotation, and scale to identity/one. |
ResetPosition(this Transform transform) | void | transform: The transform to reset | Resets the position to zero. |
ResetRotation(this Transform transform) | void | transform: The transform to reset | Resets the rotation to identity. |
ResetScale(this Transform transform) | void | transform: The transform to reset | Resets the scale to one. |
TransformPointUnscaled(this Transform transform, Vector3 position) | Vector3 | transform: The transform to use, position: The local position | Transforms a point from local space to world space without applying scale. |
InverseTransformPointUnscaled(this Transform transform, Vector3 position) | Vector3 | transform: The transform to use, position: The world position | Transforms a point from world space to local space without applying scale. |
LookAtWithUp(this Transform transform, Vector3 target, Vector3 up) | void | transform: The transform to modify, target: The target position, up: The up direction | Rotates the transform to look at a target with a specific up direction. |
SetForwardDirection(this Transform transform, Vector3 direction) | void | transform: The transform to modify, direction: The forward direction | Sets the rotation to face a specific direction. |
DestroyChildren(this Transform transform) | void | transform: The transform to modify | Destroys all children of the transform. |
GetChildren(this Transform transform) | Transform[] | transform: The transform to query | Gets all children of the transform. |
FindChildByName(this Transform transform, string name, bool recursive = false) | Transform | transform: The transform to search, name: The child name, recursive: Whether to search recursively | Finds a child by name. |
GetOrCreateChild(this Transform transform, string name) | Transform | transform: The transform to modify, name: The child name | Gets or creates a child with the specified name. |
SetParentPreserveWorld(this Transform transform, Transform parent) | void | transform: The transform to modify, parent: The new parent | Sets the parent with world position/rotation preserved. |
GetHierarchyPath(this Transform transform) | string | transform: The transform to query | Gets the full hierarchy path of the transform. |
GetRootParent(this Transform transform) | Transform | transform: The transform to query | Gets the root parent of the transform. |
GameObjectExtensions
Extension methods for GameObject.
Methods
| Name | Return Type | Parameters | Description |
|---|---|---|---|
GetOrAddComponent<T>(this GameObject gameObject) | T | gameObject: The GameObject to modify | Gets a component or adds it if it doesn't exist. |
TryGetComponent<T>(this GameObject gameObject, out T component) | bool | gameObject: The GameObject to query, component: The output component | Tries to get a component. |
HasComponent<T>(this GameObject gameObject) | bool | gameObject: The GameObject to query | Checks if the GameObject has a component. |
GetComponentsInChildrenIncludingInactive<T>(this GameObject gameObject) | T[] | gameObject: The GameObject to query | Gets components in children including inactive ones. |
GetComponentInParent<T>(this GameObject gameObject, bool includeInactive = false) | T | gameObject: The GameObject to query, includeInactive: Whether to include inactive parents | Gets a component in parent. |
SetLayer(this GameObject gameObject, int layer) | void | gameObject: The GameObject to modify, layer: The layer to set | Sets the layer of the GameObject. |
SetLayerRecursively(this GameObject gameObject, int layer) | void | gameObject: The GameObject to modify, layer: The layer to set | Sets the layer of the GameObject and all its children. |
IsInLayerMask(this GameObject gameObject, LayerMask layerMask) | bool | gameObject: The GameObject to query, layerMask: The layer mask to check | Checks if the GameObject is in the layer mask. |
CompareTag(this GameObject gameObject, string tag) | bool | gameObject: The GameObject to query, tag: The tag to check | Checks if the GameObject has the specified tag (null-safe). |
GetChildren(this GameObject gameObject) | GameObject[] | gameObject: The GameObject to query | Gets all children of the GameObject. |
GetActiveChildren(this GameObject gameObject) | GameObject[] | gameObject: The GameObject to query | Gets all active children of the GameObject. |
DestroyChildren(this GameObject gameObject) | void | gameObject: The GameObject to modify | Destroys all children of the GameObject. |
InstantiateAsChild(this GameObject gameObject, GameObject prefab) | GameObject | gameObject: The GameObject to modify, prefab: The prefab to instantiate | Instantiates a prefab as a child of the GameObject. |
GetOrCreateChild(this GameObject gameObject, string name) | GameObject | gameObject: The GameObject to modify, name: The child name | Gets or creates a child with the specified name. |
GetFullPath(this GameObject gameObject) | string | gameObject: The GameObject to query | Gets the full path of the GameObject. |
ComponentExtensions
Extension methods for Component.
Methods
| Name | Return Type | Parameters | Description |
|---|---|---|---|
Enable(this Component component) | void | component: The Component to modify | Enables the Component. |
Disable(this Component component) | void | component: The Component to modify | Disables the Component. |
IsEnabled(this Component component) | bool | component: The Component to query | Checks if the Component is enabled. |
GetComponentInParentOrSelf<T>(this Component component) | T | component: The Component to query | Gets a component in parent or self. |
FindObjectsOfTypeIncludingInactive<T>() | T[] | None | Finds all objects of type including inactive ones. |
FindObjectsOfTypeWithInterface<T>() | T[] | None | Finds all objects that implement an interface. |
ListExtensions
Extension methods for List.
Methods
| Name | Return Type | Parameters | Description |
|---|---|---|---|
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 function | Initializes a list with values. |
Shuffle<T>(this List<T> list) | void | list: The list to shuffle | Shuffles the list. |
GetRandom<T>(this List<T> list) | T | list: The list to query | Gets a random item from the list. |
RemoveAndGet<T>(this List<T> list, int index) | T | list: The list to modify, index: The index to remove | Removes and returns the item at the specified index. |
RemoveNulls<T>(this List<T> list) where T : class | void | list: The list to modify | Removes all null entries from the list. |
AddRangeIf<T>(this List<T> list, IEnumerable<T> collection, Func<T, bool> predicate) | void | list: The list to modify, collection: The items to add, predicate: The condition | Adds items from a collection if they match a condition. |
ForEach<T>(this List<T> list, Action<T, int> action) | void | list: The list to process, action: The action to perform | Performs an action on each item with its index. |
AddUnique<T>(this List<T> list, T item) | bool | list: The list to modify, item: The item to add | Adds an item if it's not already in the list. |
ContainsAll<T>(this List<T> list, IEnumerable<T> collection) | bool | list: The list to check, collection: The items to check for | Checks 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 function | Returns distinct elements by a key selector. |
Namespace: QWR.Utilities.Data
Contains data structures and serialization helpers.
QWRObjectPool<T>
Generic object pool for MonoBehaviours.
Properties
| Name | Type | Description |
|---|---|---|
ActiveCount | int | The number of active objects. |
InactiveCount | int | The number of inactive objects. |
TotalCount | int | The total number of objects. |
Methods
| Name | Return Type | Parameters | Description |
|---|---|---|---|
Get() | T | None | Gets an object from the pool. |
Release(T obj) | void | obj: The object to release | Releases an object back to the pool. |
Preload(int count) | void | count: The number of objects to preload | Preloads a number of objects. |
Clear() | void | None | Clears the pool. |
QWRGenericPool<T>
Generic object pool for non-MonoBehaviours.
Properties
| Name | Type | Description |
|---|---|---|
ActiveCount | int | The number of active objects. |
InactiveCount | int | The number of inactive objects. |
TotalCount | int | The total number of objects. |
Methods
| Name | Return Type | Parameters | Description |
|---|---|---|---|
Get() | T | None | Gets an object from the pool. |
Release(T obj) | void | obj: The object to release | Releases an object back to the pool. |
Preload(int count) | void | count: The number of objects to preload | Preloads a number of objects. |
Clear() | void | None | Clears the pool. |
QWRPriorityQueue<T>
Generic priority queue.
Properties
| Name | Type | Description |
|---|---|---|
Count | int | The number of items in the queue. |
Methods
| Name | Return Type | Parameters | Description |
|---|---|---|---|
Enqueue(T item, float priority) | void | item: The item to enqueue, priority: The priority value | Adds an item to the queue with the specified priority. |
Dequeue() | T | None | Removes and returns the highest priority item. |
Peek() | T | None | Returns the highest priority item without removing it. |
Contains(T item) | bool | item: The item to check | Checks if the queue contains the specified item. |
Clear() | void | None | Clears the queue. |
QWRObservableList<T>
List that raises events when modified.
Properties
| Name | Type | Description |
|---|---|---|
Count | int | The number of items in the list. |
Methods
| Name | Return Type | Parameters | Description |
|---|---|---|---|
Add(T item) | void | item: The item to add | Adds an item to the list. |
Remove(T item) | bool | item: The item to remove | Removes an item from the list. |
Clear() | void | None | Clears the list. |
Contains(T item) | bool | item: The item to check | Checks if the list contains the specified item. |
IndexOf(T item) | int | item: The item to find | Gets the index of the specified item. |
Insert(int index, T item) | void | index: The index to insert at, item: The item to insert | Inserts an item at the specified index. |
RemoveAt(int index) | void | index: The index to remove | Removes the item at the specified index. |
Events
| Name | Event Type | Description |
|---|---|---|
OnItemAdded | Action<T> | Triggered when an item is added. |
OnItemRemoved | Action<T> | Triggered when an item is removed. |
OnListCleared | Action | Triggered when the list is cleared. |
QWRSerializableDictionary<TKey, TValue>
Dictionary that can be serialized by Unity.
Properties
| Name | Type | Description |
|---|---|---|
Count | int | The number of key-value pairs in the dictionary. |
Keys | ICollection<TKey> | The keys in the dictionary. |
Values | ICollection<TValue> | The values in the dictionary. |
Methods
| Name | Return Type | Parameters | Description |
|---|---|---|---|
Add(TKey key, TValue value) | void | key: The key, value: The value | Adds a key-value pair to the dictionary. |
Remove(TKey key) | bool | key: The key to remove | Removes a key-value pair from the dictionary. |
Clear() | void | None | Clears the dictionary. |
ContainsKey(TKey key) | bool | key: The key to check | Checks if the dictionary contains the specified key. |
TryGetValue(TKey key, out TValue value) | bool | key: The key to find, value: The output value | Tries to get the value for the specified key. |
QWRWeightedList<T>
List where items have weights for random selection.
Properties
| Name | Type | Description |
|---|---|---|
Count | int | The number of items in the list. |
TotalWeight | float | The total weight of all items. |
Methods
| Name | Return Type | Parameters | Description |
|---|---|---|---|
Add(T item, float weight) | void | item: The item to add, weight: The item's weight | Adds an item with the specified weight. |
Remove(T item) | bool | item: The item to remove | Removes an item from the list. |
Clear() | void | None | Clears the list. |
GetRandom() | T | None | Gets a random item based on weights. |
GetRandomMultiple(int count) | T[] | count: The number of items to get | Gets multiple random items based on weights. |
GetRandomExcluding(T excludedItem) | T | excludedItem: The item to exclude | Gets a random item excluding the specified item. |
UpdateWeight(T item, float newWeight) | bool | item: The item to update, newWeight: The new weight | Updates the weight of an item. |
QWRStateMachine<TState, TContext>
Generic state machine.
Properties
| Name | Type | Description |
|---|---|---|
CurrentState | TState | The current state. |
PreviousState | TState | The previous state. |
Context | TContext | The context object. |
Methods
| Name | Return Type | Parameters | Description |
|---|---|---|---|
RegisterState(TState state, Action enterAction, Action updateAction, Action exitAction) | void | state: The state to register, enterAction: The enter action, updateAction: The update action, exitAction: The exit action | Registers a state with its actions. |
SetState(TState newState) | bool | newState: The new state | Sets the current state. |
Update() | void | None | Updates the current state. |
Namespace: QWR.Utilities.Math
Contains mathematical utilities and helpers.
QWRMath
Static class with math utilities.
Methods
| Name | Return Type | Parameters | Description |
|---|---|---|---|
SmoothDamp(float current, float target, ref float velocity, float smoothTime) | float | current: Current value, target: Target value, velocity: Current velocity, smoothTime: Smoothing time | Smoothly interpolates between values. |
SmoothDamp(Vector3 current, Vector3 target, ref Vector3 velocity, float smoothTime) | Vector3 | current: Current value, target: Target value, velocity: Current velocity, smoothTime: Smoothing time | Smoothly interpolates between vectors. |
CubicBezier(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t) | Vector3 | p0, p1, p2, p3: Control points, t: Interpolation parameter | Calculates a point on a cubic Bezier curve. |
SignedAngle(Vector3 from, Vector3 to, Vector3 axis) | float | from: From direction, to: To direction, axis: Rotation axis | Calculates the signed angle between vectors. |
RandomRange(int min, int max) | int | min: Minimum value, max: Maximum value | Returns a random integer in the specified range. |
RandomRange(float min, float max) | float | min: Minimum value, max: Maximum value | Returns a random float in the specified range. |
RandomPointInSphere(float radius) | Vector3 | radius: Sphere radius | Returns a random point inside a sphere. |
RandomPointOnSphere(float radius) | Vector3 | radius: Sphere radius | Returns a random point on a sphere. |
EaseInOut(float start, float end, float t) | float | start: Start value, end: End value, t: Interpolation parameter | Applies ease-in-out interpolation. |
EaseBounce(float start, float end, float t) | float | start: Start value, end: End value, t: Interpolation parameter | Applies bounce interpolation. |
EaseElastic(float start, float end, float t) | float | start: Start value, end: End value, t: Interpolation parameter | Applies 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:
- QWR Core API Reference: API reference for the QWR Core package
- Core Documentation: Comprehensive documentation for QWR Core features
- Utilities Documentation: Comprehensive documentation for QWR Utilities features