Ejemplo n.º 1
0
        public EcsComponentPool(int entitiesCapacity) : base(entitiesCapacity)
        {
            Items               = new T[512];
            _itemsCount         = 1;
            _recycledItems      = new int[512];
            _recycledItemsCount = 0;
            if (EcsComponentType <T> .IsAutoReset)
            {
                var autoResetMethod = typeof(T).GetMethod(nameof(IEcsAutoReset <T> .AutoReset));
#if DEBUG
                if (autoResetMethod == null)
                {
                    throw new Exception(
                              $"IEcsAutoReset<{typeof (T).Name}> explicit implementation not supported, use implicit instead.");
                }
#endif
                _autoReset = (AutoResetHandler)Delegate.CreateDelegate(
                    typeof(AutoResetHandler),
#if ENABLE_IL2CPP && !UNITY_EDITOR
                    _autoresetFakeInstance,
#else
                    null,
#endif
                    autoResetMethod);
            }
        }
Ejemplo n.º 2
0
        internal EcsPool(EcsWorld world, int id, int denseCapacity, int sparseCapacity)
        {
            _type               = typeof(T);
            _world              = world;
            _id                 = id;
            _denseItems         = new T[denseCapacity + 1];
            _sparseItems        = new int[sparseCapacity];
            _denseItemsCount    = 1;
            _recycledItems      = new int[512];
            _recycledItemsCount = 0;
            var isAutoReset = typeof(IEcsAutoReset <T>).IsAssignableFrom(_type);

#if DEBUG
            if (!isAutoReset && _type.GetInterface("IEcsAutoReset`1") != null)
            {
                throw new Exception($"IEcsAutoReset should have <{typeof (T).Name}> constraint for component \"{typeof (T).Name}\".");
            }
#endif
            if (isAutoReset)
            {
                var autoResetMethod = typeof(T).GetMethod(nameof(IEcsAutoReset <T> .AutoReset));
#if DEBUG
                if (autoResetMethod == null)
                {
                    throw new Exception(
                              $"IEcsAutoReset<{typeof (T).Name}> explicit implementation not supported, use implicit instead.");
                }
#endif
                _autoReset = (AutoResetHandler)Delegate.CreateDelegate(
                    typeof(AutoResetHandler),
#if ENABLE_IL2CPP && !UNITY_EDITOR
                    _autoresetFakeInstance,
#else
                    null,
#endif
                    autoResetMethod);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Sets custom AutoReset behaviour handler. If null - disable custom behaviour and use default.
 /// </summary>
 /// <param name="cb">Handler.</param>
 public void SetAutoReset(AutoResetHandler cb)
 {
     _autoReset = cb;
 }