#if DISABLE_DEBUG #undef DEBUG #endif using System.Runtime.CompilerServices; namespace DCFApixels.DragonECS.Core { #region IEcsWorldComponent public interface IEcsWorldComponent { void Init(ref T component, EcsWorld world); void OnDestroy(ref T component, EcsWorld world); } public static class EcsWorldComponentHandler { public static readonly IEcsWorldComponent instance; public static readonly bool isHasHandler; static EcsWorldComponentHandler() { T def = default; if (def is IEcsWorldComponent intrf) { isHasHandler = true; instance = intrf; } else { isHasHandler = false; instance = new DummyHandler(); } } private class DummyHandler : IEcsWorldComponent { [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Init(ref T component, EcsWorld world) { } public void OnDestroy(ref T component, EcsWorld world) { } } } #endregion #region IEcsComponentReset public interface IEcsComponentLifecycle { void Enable(ref T component); void Disable(ref T component); } public static class EcsComponentLifecycleHandler { public static readonly IEcsComponentLifecycle instance; public static readonly bool isHasHandler; static EcsComponentLifecycleHandler() { T def = default; if (def is IEcsComponentLifecycle intrf) { isHasHandler = true; instance = intrf; } else { isHasHandler = false; instance = new DummyHandler(); } } private sealed class DummyHandler : IEcsComponentLifecycle { [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enable(ref T component) { component = default; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Disable(ref T component) { component = default; } } } #endregion #region IEcsComponentCopy public interface IEcsComponentCopy { void Copy(ref T from, ref T to); } public static class EcsComponentCopyHandler { public static readonly IEcsComponentCopy instance; public static readonly bool isHasHandler; static EcsComponentCopyHandler() { T def = default; if (def is IEcsComponentCopy intrf) { isHasHandler = true; instance = intrf; } else { isHasHandler = false; instance = new DummyHandler(); } } private sealed class DummyHandler : IEcsComponentCopy { [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Copy(ref T from, ref T to) { to = from; } } } #endregion }