This is a collection of project agnostic utilities and extensions for Unity.
They are implemented using PropertyDrawers for these specific types without a general editor that would inject itself everywhere. This makes this compatible and does not interfere with other custom editors.
Couple<T1, T2>andTriple<T1, T2, T3>tuplesMap<TKey, TValue>dictionaryMinMax<T>range, withClamp,Lerp,InverseLerp,Random, andContainsmethods forMinMax<float>and, where applicable, also forMinMax<Vector2>andMinMax<Vector3>.MinMaxSliderattribute to drawMinMaxas a sliderOptionalValue<T>boolean enabled toggle wrapped around a valueInterfaceReference<T>allows serializing objects that implement an interface
AutoSetupattribute that tries to wire component references automatically
.With,.Add, and.Rotatemodifications, e.g.Vector3 v = transform.forward.With(y: 0f);- Component wise
MulandDiv SqrDistsemantic shorthandVector3.XY,Vector3.XZ, andVector2.X0Y,Vector2.XY0swizzling
Abs,Round,Max,Clamp, andRandomthat operate on a single vectorMinandMaxthat operate on two vectorsMaxandSumthat iterate over the components of a single vectorMinMaxthat returns an ordered pair
ICollection.IsValidIndexas guard against ArrayIndexOutOfBounds exceptionsIDictionary.GetOrCreateKeyValuePair.Deconstruct
Overlap*,Check*,*Cast, andContainsmethods that take*Collideras a parameterToWorldSpace*extension methods forBoxCollider,SphereCollider, andCapsuleColliderContainsextension methods forBoxCollider,SphereCollider, andCapsuleCollider- Layer to LayerMask conversion
IsInStateextension method forAnimatorreturns whether the animator is in the specified state.GetTriggerextension method forAnimatorthat wrapsAnimator.GetBooland can be used as a semantic companion toAnimator.SetTrigger.
HasComponentGetOrAddComponentTryGetComponentInParentTryGetComponentInChildrenGetComponentsInOnlyChildrenGetComponentsInOnlyCousinsSetPositionAndRotationthat takes aTransformas parameter.
RevertIdenticalTransformOverridesreverts unused overrides to local position and rotation to reduce prefab and scene file size and noise.HasIdenticalTransformOverridesreturns whether RevertIdenticalTransformOverrides has something to revert.
InputActionMap.SetEnabledthat callsEnableorDisabledepending on the parameter.
SetActiveforVisualElementthat mimicsGameObject.SetActive.
AspectRatioContainerthat maintains a configured aspect ratio.
- Each is a lightweight struct that contains a
positionand arotationfield. Similar to Unity'sTransformbut without scale, parent, children, component, and other overhead. - They contain the same data, but are semantically different, as they encode the space in which they are to be interpreted.
- Various
TransformXXXandInverseTransformXXXmethods are provided to convert objects between spaces. WorldPoseandLocalPosecan be implicitly created fromTransformandRigidbody. When implicit conversions from other custom types are added,WorldPoseandLocalPosecan be used as general purpose parameter that reduce the amount of overloads needed.
- Constructed from a calculation and validation function, it caches the result of the calculation and recalculates it only when the validation function returns false.
- Similar to
Lazy<T>but with an additionalIsStillValidfunction that allows updating the cached value when necessary.
EnumValuesiterator, e.g.foreach(var value in Utils.EnumValues<SomeEnum>())ReturnValueAndLogErrorutility for lean switch expressions
Vector4field in one line (likeVector3andQuaternionfields).- Prevent clipping of MinMaxSlider Handles at edges by added padding.