scripts
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ProBuilder2.Common
|
||||
{
|
||||
// Token: 0x02000035 RID: 53
|
||||
public class pb_ObjectPool<T> where T : global::UnityEngine.Object, new()
|
||||
{
|
||||
// Token: 0x060001A7 RID: 423 RVA: 0x00016988 File Offset: 0x00014D88
|
||||
public pb_ObjectPool(int initialSize, int desiredSize, Func<T> constructor, Action<T> destructor)
|
||||
{
|
||||
this.constructor = constructor;
|
||||
Action<T> action;
|
||||
if (destructor == null)
|
||||
{
|
||||
action = new Action<T>(pb_ObjectPool<T>.DestroyObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
action = destructor;
|
||||
}
|
||||
this.destructor = action;
|
||||
this.desiredSize = desiredSize;
|
||||
int num = 0;
|
||||
while (num < initialSize && num < desiredSize)
|
||||
{
|
||||
this.pool.Enqueue((constructor == null) ? new T() : constructor());
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060001A8 RID: 424 RVA: 0x00016A24 File Offset: 0x00014E24
|
||||
public T Get()
|
||||
{
|
||||
T t = ((this.pool.Count <= 0) ? ((T)((object)null)) : ((T)((object)this.pool.Dequeue())));
|
||||
if (t == null)
|
||||
{
|
||||
t = ((this.constructor != null) ? this.constructor() : new T());
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
// Token: 0x060001A9 RID: 425 RVA: 0x00016A91 File Offset: 0x00014E91
|
||||
public void Put(T obj)
|
||||
{
|
||||
if (this.pool.Count < this.desiredSize)
|
||||
{
|
||||
this.pool.Enqueue(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
global::UnityEngine.Object.DestroyImmediate(obj);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060001AA RID: 426 RVA: 0x00016ACC File Offset: 0x00014ECC
|
||||
public void Empty()
|
||||
{
|
||||
int count = this.pool.Count;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (this.destructor != null)
|
||||
{
|
||||
this.destructor((T)((object)this.pool.Dequeue()));
|
||||
}
|
||||
else
|
||||
{
|
||||
pb_ObjectPool<T>.DestroyObject((T)((object)this.pool.Dequeue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060001AB RID: 427 RVA: 0x00016B37 File Offset: 0x00014F37
|
||||
private static void DestroyObject(T obj)
|
||||
{
|
||||
global::UnityEngine.Object.DestroyImmediate(obj);
|
||||
}
|
||||
|
||||
// Token: 0x060001AC RID: 428 RVA: 0x00016B44 File Offset: 0x00014F44
|
||||
private void OnDestroy()
|
||||
{
|
||||
this.Empty();
|
||||
}
|
||||
|
||||
// Token: 0x04000147 RID: 327
|
||||
public int desiredSize;
|
||||
|
||||
// Token: 0x04000148 RID: 328
|
||||
public Func<T> constructor;
|
||||
|
||||
// Token: 0x04000149 RID: 329
|
||||
public Action<T> destructor;
|
||||
|
||||
// Token: 0x0400014A RID: 330
|
||||
private Queue pool = new Queue();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user