示例#1
0
 public void ReturnInstance(T instance)
 {
     ReturnInstanceTask?.Invoke(instance);
     if (objectStack.Count < targetCount)
     {
         objectStack.Push(instance);
     }
     else
     {
         DisposeInstanceTask?.Invoke(instance);
     }
 }
示例#2
0
        public void CreateInstance(int count)
        {
            if (count == 0)
            {
                return;
            }

            this.targetCount += count;
            for (int i = 0; i < count; ++i)
            {
                T instance;
                if (CreateInstanceMethod != null)
                {
                    instance = CreateInstanceMethod();
                }
                else
                {
                    instance = default(T);
                }
                ReturnInstanceTask?.Invoke(instance);
                objectStack.Push(instance);
            }
        }