using System; using MoonTools.ECS.Collections; namespace MoonTools.ECS; public class MessageStorage : IDisposable { private NativeArray Messages; private bool IsDisposed; public MessageStorage(int elementSize) { Messages = new NativeArray(elementSize); } public void Add(in T message) where T : unmanaged { Messages.Append(message); } public bool Some() { return Messages.Count > 0; } public ReadOnlySpan All() where T : unmanaged { return Messages.ToSpan(); } public T First() where T : unmanaged { return Messages.Get(0); } public void Clear() { Messages.Clear(); } protected virtual void Dispose(bool disposing) { if (!IsDisposed) { Messages.Dispose(); IsDisposed = true; } } // ~MessageStorage() // { // // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method // Dispose(disposing: false); // } public void Dispose() { // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method Dispose(disposing: true); GC.SuppressFinalize(this); } }