Unity extensions

June 19, 2026 ยท View on GitHub

Extension methods for Unity types in FronkonGames.GameWork.Foundation. Import the namespace and call methods on the extended type.

See also: System extensions.


GameObjects and components

ClassHighlights
GameObjectExtensionsSafeDestroy, DestroyAfter, GetAllChildren, ChangeMaterial, SetLayer
ComponentExtensionsComponent lookup and batch helpers
MonoBehaviourExtensionsSafeStartCoroutine, RestartCoroutine, DontDestroyOnLoad, ResolveComponentFromChildrenIfNull
UnityObjectExtensionsUnityEngine.Object utilities
TryGetExtensionsSafe TryGetComponent patterns
using FronkonGames.GameWork.Foundation;

projectile.SafeDestroy();

enemy.DestroyAfter(3.0f);

Transforms

TransformExtensions, the largest Unity extension file.

AreaExamples
HierarchyGetPath, FindChildRecursive, DestroyChildren, GetAllChildren
PositionSetX/Y/Z, SetLocalXYZ, TranslateXYZ, ResetWorld/Local
ScaleSetScaleXYZ, ScaleByXYZ, FlipX/Y/Z, ResetScale
RotationRotateAroundX/Y/Z, SetRotationY, ResetRotation
RectTransformResetRect, ExpandFullscreen (via RectTransformExtensions)
player.transform.SetY(groundHeight);
turretHead.SetLocalRotationY(yawAngle);

Vectors and quaternions

ClassHighlights
Vector2ExtensionsRotate, 2D math helpers
Vector3Extensions3D vector utilities
Vector4Extensions4D vector helpers
Vector2IntExtensionsInteger grid coordinates
Vector3IntExtensions3D integer vectors
VectorConversionExtensionsCast between vector types
QuaternionExtensionsNearlyEquals, AngleTo, IsIdentity, Normalized
QuaternionConversionExtensionsQuaternion/type conversions
Matrix4x4ExtensionsDecomposeTRS, extract position, rotation, scale
Vector2 aim = direction.Rotate(Mathf.PI * 0.25f);

matrix.DecomposeTRS(out Vector3 pos, out Quaternion rot, out Vector3 scale);

Colors, sprites, and textures

ClassHighlights
ColorExtensionsHSV, hex, HDR (GetHdrIntensity, AdjustHdrIntensity, AtHdrIntensity), tint/shade/tone
Color32ExtensionsCreateTexture, equality checks
SpriteExtensionsGetPixels32, GetRect, IsFullyTransparent
Texture2DExtensionsTexture manipulation
ImageExtensionsUI Image helpers
MaterialExtensionsMaterial property shortcuts
Color hdr = baseColor.AtHdrIntensity(2.0f);
Color parsed = "#FF8800".FromHex();

Physics and spatial

ClassHighlights
ColliderExtensionsCollider bounds and queries
RigidbodyExtensionsRigidbody velocity and forces
RaycastHitExtensionsHit info helpers
LayerMaskExtensionsIsInLayerMask, layer utilities
BoundsExtensionsBounds math
BoundsIntExtensionsInteger bounds
CameraExtensionsCamera frustum and screen helpers

UI and layout

ClassHighlights
RectTransformExtensionsMargins, size, ExpandFullscreen, ToWorldBounds
RectExtensionsWithRoundedCoordinates, CutVertically, AddHorizontalPadding, AlignMiddleVertically
RectLineIntersectionHelperGetLineIntersections, line/rect crossing points
ButtonExtensionsUI button helpers
ScrollRectExtensionsScroll view utilities
CanvasGroupExtensionsSetActive with alpha and interactable control
Rect padded = panelRect.AddHorizontalPadding(8.0f);

LineIntersectionResult hit = bounds.GetLineIntersections(segmentStart, segmentEnd);

Audio

ClassHighlights
AudioExtensionsToDecibel, ToLinear, amplitude/decibel conversion
AudioSourceExtensionsSetPitch, SetVolume with random ranges
AudioMixerExtensionsMixer parameter helpers
float db = linearAmplitude.ToDecibel();
float linear = (-6.0f).ToLinear();

Animation, particles, and rendering

ClassHighlights
AnimatorExtensionsAnimator state helpers
ParticleSystemExtensionsParticle control
RendererExtensionsRenderer material access
MeshExtensionsMesh data utilities
MeshFilterExtensionsMeshFilter helpers

Async and events

ClassHighlights
AsyncOperationExtensionsAsyncOperation await helpers
AwaitableExtensionsUnity 6 Awaitable โ†’ Task conversion
UnityEventExtensionsEvent wiring utilities

Collections and flags

ClassHighlights
CollectionExtensionsAddIfMissing
ReadOnlyCollectionExtensionsIndexOf on IReadOnlyCollection<T>
EnumFlagsExtensionsFlags enum helpers

Misc

ClassHighlights
TailwindTailwind-style spacing and sizing shortcuts for UI layout

Tests

Unit tests live under Test/Extensions.