Info
- Extension methods on Unity and .NET types, namespace
Polis.Core.NativeUtils
- Check here before writing a helper
Highlights
- Vectors
WithX / WithY / WithZ, WithXZ - copy with one part changed
XZ - drop the Y axis
MultiplyElementWise, Abs, Clamp
- Color
WithA, WithRGB - copy with alpha / color changed
MultiplyRGB, HexStringToColor
- Transform
DestroyChildren, SortChildren
GetPath - hierarchy path for logs
ResetLocal, SetPositionRotationScale
- Bounds
TryGetBounds - combined bounds of renderers, false when there are none
EncapsulateOrInit - grow bounds in a loop without a first-item check
- RectTransform
SetToFillParent, SetAnchor, SetPivot
- GameObject / Component
GetOrAddComponent, SafeDestroy, SetAllActive
- Timing on MonoBehaviour
InvokeNextFrame, InvokeAfterTime, InvokeWhen
- Collections
IsNullOrEmpty, EmptyIfNull, TryGetFirst, IsIndexInRange
- Math
Remap, PositiveModulo, Approximately
DampFactor(speed, deltaTime) - frame rate independent lerp factor for smoothing
- Strings
RichText - "text".Bold().Color(Color.red)
Nicify, Truncate, Capitalize
- Units
ToByteSize - 512 KB, 74 MB, 1.2 GB
ToShortDuration - 25 s, 3 min, 2 h, rounded up
transform.position = transform.position.WithY(0f);
_image.color = _image.color.WithA(0.5f);
var t = value.Remap(0f, 10f, 0f, 1f);
this.InvokeNextFrame(Refresh);
Components
ColliderEvents - C# events for trigger and collision callbacks
TransformChangeMonitor - event when a transform changes
ParentSceneActiveObserver - reacts when its scene becomes active