Esempio n. 1
0
        private void Start()
        {
            #region SimpleObjectPool
            var pool = new SimpleObjectPool <Fish>(() => new Fish(), initCount: 50);

            pool.CurCount.LogInfo();

            var fish = pool.Allocate();

            pool.CurCount.LogInfo();

            pool.Recycle(fish);

            pool.CurCount.LogInfo();
            #endregion



            #region SafeObjectPool

            SafeObjectPool <Bullet> .Instance.Init(50, 25);

            var bullet = Bullet.Allocate();

            SafeObjectPool <Bullet> .Instance.CurCount.LogInfo();

            bullet.Recycle2Cache();

            SafeObjectPool <Bullet> .Instance.CurCount.LogInfo();

            #endregion
        }
Esempio n. 2
0
        void updateGroupsComponentAddedOrRemoved(IEntity entity, int index, IComponent component)
        {
            var groups = _groupsForIndex[index];

            if (groups != null)
            {
                var events = mGroupChangedListSimpleObjectPool.Allocate();

                var tEntity = (TEntity)entity;

                for (int i = 0; i < groups.Count; i++)
                {
                    events.Add(groups[i].HandleEntity(tEntity));
                }

                for (int i = 0; i < events.Count; i++)
                {
                    var groupChangedEvent = events[i];
                    if (groupChangedEvent != null)
                    {
                        groupChangedEvent(
                            groups[i], tEntity, index, component
                            );
                    }
                }

                mGroupChangedListSimpleObjectPool.Recycle(events);
            }
        }
Esempio n. 3
0
        private static void MenuClicked()
        {
            var fishPool = new SimpleObjectPool <Fish>(() => new Fish(), null, 100);

            Debug.LogFormat("fishPool.CurCount : {0}", fishPool.CurCount);

            var fishOne = fishPool.Allocate();

            Debug.LogFormat("fishPool.CurCount : {0}", fishPool.CurCount);

            fishPool.Recycle(fishOne);
            Debug.LogFormat("fishPool.CurCount : {0}", fishPool.CurCount);

            for (int i = 0; i < 10; i++)
            {
                fishPool.Allocate();
            }
            Debug.LogFormat("fishPool.CurCount : {0}", fishPool.CurCount);
        }