Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
ObjectPool< T >.Item< T > Class Template Reference
Inheritance diagram for ObjectPool< T >.Item< T >:
ObjectPool< T >.IItem

Public Member Functions

void Create (int _max, int _addsPerUpdate=10)
 
Get (Component parent)
 
Get ()
 
void Update ()
 
Create ()
 
Item< T > SetMold (Component _mold)
 
override string ToString ()
 
void Update ()
 

Public Attributes

Stack< T > pools
 
int max
 
int addsPerUpdate
 
Action< T > onCreate
 
Component mold
 

Detailed Description

Type Constraints
T :new() 

Definition at line 12 of file ObjectPool.cs.

Member Function Documentation

◆ Create() [1/2]

T ObjectPool< T >.Item< T >.Create ( )
inline

Definition at line 65 of file ObjectPool.cs.

66 {
67 T val;
68 if ((bool)mold)
69 {
70 val = Util.Instantiate(mold, Instance).GetComponent<T>();
71 (val as Component).SetActive(enable: false);
72 }
73 else
74 {
75 val = new T();
76 }
77 if (onCreate != null)
78 {
79 onCreate(val);
80 }
81 return val;
82 }
Component mold
Definition: ObjectPool.cs:22
Action< T > onCreate
Definition: ObjectPool.cs:20
static ObjectPool Instance
Definition: ObjectPool.cs:96
Definition: Util.cs:10
static Transform Instantiate(string path, Component parent=null)
Definition: Util.cs:67

References ObjectPool< T >.Instance, ObjectPool< T >.Item< T >.mold, ObjectPool< T >.Item< T >.onCreate, and Util.

Referenced by ObjectPool< T >.Item< T >.Get(), and ObjectPool< T >.Item< T >.Update().

◆ Create() [2/2]

void ObjectPool< T >.Item< T >.Create ( int  _max,
int  _addsPerUpdate = 10 
)
inline

Definition at line 24 of file ObjectPool.cs.

25 {
26 max = _max;
27 addsPerUpdate = _addsPerUpdate;
28 pools = new Stack<T>(_max);
29 }
Stack< T > pools
Definition: ObjectPool.cs:14

References ObjectPool< T >.Item< T >.addsPerUpdate, ObjectPool< T >.Item< T >.max, and ObjectPool< T >.Item< T >.pools.

◆ Get() [1/2]

T ObjectPool< T >.Item< T >.Get ( )
inline

Definition at line 40 of file ObjectPool.cs.

41 {
42 if ((bool)mold)
43 {
44 Debug.LogError("tried to Get component");
45 }
46 if (pools.Count > 0)
47 {
48 return pools.Pop();
49 }
50 return Create();
51 }

References ObjectPool< T >.Item< T >.Create(), Debug, ObjectPool< T >.Item< T >.mold, and ObjectPool< T >.Item< T >.pools.

◆ Get() [2/2]

T ObjectPool< T >.Item< T >.Get ( Component  parent)
inline

Definition at line 31 of file ObjectPool.cs.

32 {
33 T obj = ((pools.Count > 0) ? pools.Pop() : Create());
34 Component obj2 = obj as Component;
35 obj2.transform.SetParent(parent.transform, worldPositionStays: false);
36 obj2.SetActive(enable: true);
37 return obj;
38 }

References ObjectPool< T >.Item< T >.Create(), and ObjectPool< T >.Item< T >.pools.

◆ SetMold()

Item< T > ObjectPool< T >.Item< T >.SetMold ( Component  _mold)
inline

Definition at line 84 of file ObjectPool.cs.

85 {
86 mold = _mold;
87 return this;
88 }

References ObjectPool< T >.Item< T >.mold.

◆ ToString()

override string ObjectPool< T >.Item< T >.ToString ( )
inline

Definition at line 90 of file ObjectPool.cs.

91 {
92 return typeof(T).Name + ":" + pools.Count;
93 }

References ObjectPool< T >.Item< T >.pools.

◆ Update()

void ObjectPool< T >.Item< T >.Update ( )
inline

Implements ObjectPool< T >.IItem.

Definition at line 53 of file ObjectPool.cs.

54 {
55 for (int i = 0; i < addsPerUpdate; i++)
56 {
57 if (pools.Count >= max)
58 {
59 break;
60 }
61 pools.Push(Create());
62 }
63 }

References ObjectPool< T >.Item< T >.addsPerUpdate, ObjectPool< T >.Item< T >.Create(), ObjectPool< T >.Item< T >.max, and ObjectPool< T >.Item< T >.pools.

Member Data Documentation

◆ addsPerUpdate

int ObjectPool< T >.Item< T >.addsPerUpdate

◆ max

int ObjectPool< T >.Item< T >.max

◆ mold

◆ onCreate

Action<T> ObjectPool< T >.Item< T >.onCreate

Definition at line 20 of file ObjectPool.cs.

Referenced by ObjectPool< T >.Item< T >.Create().

◆ pools


The documentation for this class was generated from the following file: