Example #1
0
        public void SetValue(IList array, int index)
        {
            if (array == null)
            {
                return;
            }

            if (array.Count > index)
            {
                var value = array[index];

                if (value == null)
                {
                    if (isUnityObject)
                    {
                        return;
                    }
                    else
                    {
                        value = array[index] = TypePoolManager.Create(elementType);
                    }
                }

                PoolUtility.InitializeFields(value, setters);
            }
        }
Example #2
0
        protected PoolBase(object reference, Type type, Constructor constructor, Destructor destructor, int startSize, bool initialize)
        {
            PoolUtility.InitializeJanitor();

            this.reference   = reference;
            this.constructor = constructor ?? Construct;
            this.destructor  = destructor ?? Destroy;
            this.startSize   = startSize;

            Type            = type;
            isPoolable      = reference is IPoolable;
            hashedInstances = new HashSet <object>();

            if (ApplicationUtility.IsMultiThreaded)
            {
                updater = new AsyncPoolUpdater();
            }
            else
            {
                updater = new SyncPoolUpdater();
            }

            if (initialize)
            {
                Initialize();
            }
        }
Example #3
0
        protected void Initialize()
        {
            updater.Initializer = PoolUtility.GetPoolInitializer(reference);

            while (Size < startSize)
            {
                Enqueue(CreateInstance(), false);
            }
        }
Example #4
0
        public void SetValue(object instance)
        {
            if (instance == null)
            {
                return;
            }

            var array = (IList)field.GetValue(instance);

            if (array == null)
            {
                if (type.IsArray)
                {
                    array = Array.CreateInstance(elementType, setters.Count);
                }
                else
                {
                    array = (IList)Activator.CreateInstance(type);
                }

                field.SetValue(instance, array);
            }

            if (array.Count != setters.Count)
            {
                if (type.IsArray)
                {
                    array = Array.CreateInstance(elementType, setters.Count);
                    field.SetValue(instance, array);
                }
                else if (!array.IsFixedSize)
                {
                    PoolUtility.Resize(array, elementType, setters.Count);
                }
                else
                {
                    return;
                }
            }

            for (int i = 0; i < setters.Count; i++)
            {
                setters[i].SetValue(array, i);
            }
        }
Example #5
0
        public void SetValue(object instance)
        {
            if (instance == null)
            {
                return;
            }

            var value = field.GetValue(instance);

            if (value == null)
            {
                if (isUnityObject)
                {
                    return;
                }
                else
                {
                    field.SetValue(instance, value = TypePoolManager.Create(type));
                }
            }

            PoolUtility.InitializeFields(value, setters);
        }
Example #6
0
 public void InitializeFields(object instance)
 {
     PoolUtility.InitializeFields(instance, setters);
 }
Example #7
0
 void OnDestroy()
 {
     PoolUtility.ClearAllPools();
 }