Files
Dec2017-Script-Dump/UnityEngine.UI/UI/ObjectPool.cs
T
2026-06-04 11:42:34 +02:00

86 lines
2.0 KiB
C#

using System;
using System.Collections.Generic;
using UnityEngine.Events;
namespace UnityEngine.UI
{
// Token: 0x020000A2 RID: 162
internal class ObjectPool<T> where T : new()
{
// Token: 0x060005EA RID: 1514 RVA: 0x0001DA56 File Offset: 0x0001BE56
public ObjectPool(UnityAction<T> actionOnGet, UnityAction<T> actionOnRelease)
{
this.m_ActionOnGet = actionOnGet;
this.m_ActionOnRelease = actionOnRelease;
}
// Token: 0x17000195 RID: 405
// (get) Token: 0x060005EB RID: 1515 RVA: 0x0001DA78 File Offset: 0x0001BE78
// (set) Token: 0x060005EC RID: 1516 RVA: 0x0001DA92 File Offset: 0x0001BE92
public int countAll { get; private set; }
// Token: 0x17000196 RID: 406
// (get) Token: 0x060005ED RID: 1517 RVA: 0x0001DA9C File Offset: 0x0001BE9C
public int countActive
{
get
{
return this.countAll - this.countInactive;
}
}
// Token: 0x17000197 RID: 407
// (get) Token: 0x060005EE RID: 1518 RVA: 0x0001DAC0 File Offset: 0x0001BEC0
public int countInactive
{
get
{
return this.m_Stack.Count;
}
}
// Token: 0x060005EF RID: 1519 RVA: 0x0001DAE0 File Offset: 0x0001BEE0
public T Get()
{
T t;
if (this.m_Stack.Count == 0)
{
t = new T();
this.countAll++;
}
else
{
t = this.m_Stack.Pop();
}
if (this.m_ActionOnGet != null)
{
this.m_ActionOnGet(t);
}
return t;
}
// Token: 0x060005F0 RID: 1520 RVA: 0x0001DB48 File Offset: 0x0001BF48
public void Release(T element)
{
if (this.m_Stack.Count > 0 && object.ReferenceEquals(this.m_Stack.Peek(), element))
{
Debug.LogError("Internal error. Trying to destroy object that is already released to pool.");
}
if (this.m_ActionOnRelease != null)
{
this.m_ActionOnRelease(element);
}
this.m_Stack.Push(element);
}
// Token: 0x040002C2 RID: 706
private readonly Stack<T> m_Stack = new Stack<T>();
// Token: 0x040002C3 RID: 707
private readonly UnityAction<T> m_ActionOnGet;
// Token: 0x040002C4 RID: 708
private readonly UnityAction<T> m_ActionOnRelease;
}
}