using System; using Unity.Collections; using UnityEngine; namespace LanLib.UpdateManager.Jobs.Internal { public class UpdateJobData : IDisposable where TData : struct where TDataProvider : IInitialJobDataProvider { public UnsafeNativeList Data => _data; public ref UnsafeNativeList DataRef => ref _data; public UnsafeNativeList Backup => _backup; public int Length => _data.Length; public TData this[int index] => _backup[index]; protected UnsafeNativeList _data = new UnsafeNativeList(Allocator.Persistent); protected UnsafeNativeList _backup = new UnsafeNativeList(Allocator.Persistent); public virtual void EnsureCapacity(int newSize) { _data.EnsureCapacity(newSize); } public virtual void Add(TDataProvider dataProvider, int index) { Debug.Assert(_data.Length == index, "[UpdateJobData] FIXME: added index doesn't match data size"); _data.Add(dataProvider.InitialJobData); } public virtual void RemoveAtSwapBack(int index) { _data.RemoveAtSwapBack(index); } public virtual void Dispose() { _data.Dispose(); _backup.Dispose(); } public void BackupData() { _backup.CopyFrom(_data); } public void TrimExcess() { _data.TrimExcess(); _backup.TrimExcess(); } } }