// Copyright (c) Le Loc Tai . All rights reserved. Do not redistribute. using System; using UnityEngine; namespace LeTai.Common { public static class SpanUtils { public static Vector4 ToVector4(ReadOnlySpan span) { return new Vector4(span[0], span[1], span[2], span[3]); } public static SpanWriter WriterFor(Span span) => new(span); } public ref struct SpanWriter { readonly Span _span; int _nextIndex; public SpanWriter(Span span) { _span = span; _nextIndex = 0; } public void Reset() => _nextIndex = 0; public void Write(T value) { _span[_nextIndex++] = value; } public void FillRest(T value = default) { if (_nextIndex == _span.Length) return; _span[_nextIndex..].Fill(value); _nextIndex = _span.Length; } } }