Skip to content

Commit 7e0b7f8

Browse files
- Updated gitignore
1 parent ffc69b0 commit 7e0b7f8

File tree

10 files changed

+240
-21
lines changed

10 files changed

+240
-21
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
[Tt]emp/
33
[Bb]uild/
44
[Bb]uilds/
5-
UnityProject/OutbreakVR/obj*
5+
ObjectPoolingSystem/Assets/AssetStoreTools
6+
ObjectPoolingSystem/Assets/AssetStoreTools.meta
7+
ObjectPoolingSystem/Assets/Build.meta
8+
ObjectPoolingSystem/obj
9+
ObjectPoolingSystem/ProjectSettings
610

711
# Visual Studio cache directory
812
.vs/

ObjectPoolingSystem/Assets/ObjectPoolingSystem/Example/Example.unity

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,10 +878,12 @@ MonoBehaviour:
878878
m_Script: {fileID: 11500000, guid: da89bcd93fc273746bd20282b19588a7, type: 3}
879879
m_Name:
880880
m_EditorClassIdentifier:
881+
m_ParentGameObj: {fileID: 1677428070}
881882
m_ReusablePrefab: {fileID: 7179380614175905809, guid: a20b93238c63a7946ba07d349101f51f,
882883
type: 3}
883884
m_txtMonoPooledCount: {fileID: 1502079641}
884885
m_txtMonoActiveCount: {fileID: 1205044387}
886+
m_iMonoObjPoolStartSize: 8
885887
m_txtNonMonoPooledCount: {fileID: 987091287}
886888
m_txtNonMonoActiveCount: {fileID: 1924762842}
887889
m_iNonMonoPooledStartCount: 6
@@ -1035,7 +1037,7 @@ Light:
10351037
m_BounceIntensity: 1
10361038
m_ColorTemperature: 6570
10371039
m_UseColorTemperature: 0
1038-
m_BoundingSphereOverride: {x: 4.5905e-41, y: 0, z: 0, w: 0}
1040+
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
10391041
m_UseBoundingSphereOverride: 0
10401042
m_ShadowRadius: 0
10411043
m_ShadowAngle: 0
@@ -1245,6 +1247,7 @@ RectTransform:
12451247
- {fileID: 391384159}
12461248
- {fileID: 1098582363}
12471249
- {fileID: 953137723}
1250+
- {fileID: 1677428071}
12481251
m_Father: {fileID: 1068106881}
12491252
m_RootOrder: 0
12501253
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -2505,6 +2508,66 @@ CanvasRenderer:
25052508
m_PrefabAsset: {fileID: 0}
25062509
m_GameObject: {fileID: 1651973203}
25072510
m_CullTransparentMesh: 0
2511+
--- !u!1 &1677428070
2512+
GameObject:
2513+
m_ObjectHideFlags: 0
2514+
m_CorrespondingSourceObject: {fileID: 0}
2515+
m_PrefabInstance: {fileID: 0}
2516+
m_PrefabAsset: {fileID: 0}
2517+
serializedVersion: 6
2518+
m_Component:
2519+
- component: {fileID: 1677428071}
2520+
- component: {fileID: 1677428072}
2521+
m_Layer: 0
2522+
m_Name: Parent
2523+
m_TagString: Untagged
2524+
m_Icon: {fileID: 0}
2525+
m_NavMeshLayer: 0
2526+
m_StaticEditorFlags: 0
2527+
m_IsActive: 1
2528+
--- !u!224 &1677428071
2529+
RectTransform:
2530+
m_ObjectHideFlags: 0
2531+
m_CorrespondingSourceObject: {fileID: 0}
2532+
m_PrefabInstance: {fileID: 0}
2533+
m_PrefabAsset: {fileID: 0}
2534+
m_GameObject: {fileID: 1677428070}
2535+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
2536+
m_LocalPosition: {x: 0, y: 0, z: 0}
2537+
m_LocalScale: {x: 1, y: 1, z: 1}
2538+
m_Children: []
2539+
m_Father: {fileID: 981676340}
2540+
m_RootOrder: 3
2541+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
2542+
m_AnchorMin: {x: 0.5, y: 0}
2543+
m_AnchorMax: {x: 0.5, y: 0}
2544+
m_AnchoredPosition: {x: -0.0024872, y: -21.7}
2545+
m_SizeDelta: {x: 532.31, y: 50}
2546+
m_Pivot: {x: 0.5, y: 0.5}
2547+
--- !u!114 &1677428072
2548+
MonoBehaviour:
2549+
m_ObjectHideFlags: 0
2550+
m_CorrespondingSourceObject: {fileID: 0}
2551+
m_PrefabInstance: {fileID: 0}
2552+
m_PrefabAsset: {fileID: 0}
2553+
m_GameObject: {fileID: 1677428070}
2554+
m_Enabled: 1
2555+
m_EditorHideFlags: 0
2556+
m_Script: {fileID: 11500000, guid: 8a8695521f0d02e499659fee002a26c2, type: 3}
2557+
m_Name:
2558+
m_EditorClassIdentifier:
2559+
m_Padding:
2560+
m_Left: 0
2561+
m_Right: 0
2562+
m_Top: 0
2563+
m_Bottom: 0
2564+
m_ChildAlignment: 0
2565+
m_StartCorner: 0
2566+
m_StartAxis: 0
2567+
m_CellSize: {x: 20, y: 20}
2568+
m_Spacing: {x: 0, y: 0}
2569+
m_Constraint: 0
2570+
m_ConstraintCount: 2
25082571
--- !u!1 &1729660489
25092572
GameObject:
25102573
m_ObjectHideFlags: 0

ObjectPoolingSystem/Assets/ObjectPoolingSystem/Example/Mono/TestMonoReusableObject.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
using System.Collections;
22
using System.Collections.Generic;
33
using UnityEngine;
4+
using UnityEngine.UI;
45

56
public class TestMonoReusableObject : MonoBehaviour, IReusable
67
{
8+
public Text m_txtObjNumber = null;
9+
710
public void onRetrievedFromPool()
811
{
912
gameObject.SetActive(true);

ObjectPoolingSystem/Assets/ObjectPoolingSystem/Example/Mono/TestReusableObject.prefab

Lines changed: 126 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,82 @@
11
%YAML 1.1
22
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!1 &4923542134477278753
4+
GameObject:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
serializedVersion: 6
10+
m_Component:
11+
- component: {fileID: 4923542134477278752}
12+
- component: {fileID: 4923542134477278758}
13+
- component: {fileID: 4923542134477278759}
14+
m_Layer: 0
15+
m_Name: Text
16+
m_TagString: Untagged
17+
m_Icon: {fileID: 0}
18+
m_NavMeshLayer: 0
19+
m_StaticEditorFlags: 0
20+
m_IsActive: 1
21+
--- !u!224 &4923542134477278752
22+
RectTransform:
23+
m_ObjectHideFlags: 0
24+
m_CorrespondingSourceObject: {fileID: 0}
25+
m_PrefabInstance: {fileID: 0}
26+
m_PrefabAsset: {fileID: 0}
27+
m_GameObject: {fileID: 4923542134477278753}
28+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
29+
m_LocalPosition: {x: 0, y: 0, z: 0}
30+
m_LocalScale: {x: 1, y: 1, z: 1}
31+
m_Children: []
32+
m_Father: {fileID: 4923542134778947503}
33+
m_RootOrder: 0
34+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
35+
m_AnchorMin: {x: 0, y: 0}
36+
m_AnchorMax: {x: 1, y: 1}
37+
m_AnchoredPosition: {x: 0, y: 0}
38+
m_SizeDelta: {x: 0, y: 0}
39+
m_Pivot: {x: 0.5, y: 0.5}
40+
--- !u!222 &4923542134477278758
41+
CanvasRenderer:
42+
m_ObjectHideFlags: 0
43+
m_CorrespondingSourceObject: {fileID: 0}
44+
m_PrefabInstance: {fileID: 0}
45+
m_PrefabAsset: {fileID: 0}
46+
m_GameObject: {fileID: 4923542134477278753}
47+
m_CullTransparentMesh: 0
48+
--- !u!114 &4923542134477278759
49+
MonoBehaviour:
50+
m_ObjectHideFlags: 0
51+
m_CorrespondingSourceObject: {fileID: 0}
52+
m_PrefabInstance: {fileID: 0}
53+
m_PrefabAsset: {fileID: 0}
54+
m_GameObject: {fileID: 4923542134477278753}
55+
m_Enabled: 1
56+
m_EditorHideFlags: 0
57+
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
58+
m_Name:
59+
m_EditorClassIdentifier:
60+
m_Material: {fileID: 0}
61+
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
62+
m_RaycastTarget: 1
63+
m_OnCullStateChanged:
64+
m_PersistentCalls:
65+
m_Calls: []
66+
m_FontData:
67+
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
68+
m_FontSize: 10
69+
m_FontStyle: 0
70+
m_BestFit: 0
71+
m_MinSize: 1
72+
m_MaxSize: 40
73+
m_Alignment: 4
74+
m_AlignByGeometry: 0
75+
m_RichText: 1
76+
m_HorizontalOverflow: 0
77+
m_VerticalOverflow: 0
78+
m_LineSpacing: 1
79+
m_Text: 1
380
--- !u!1 &7179380614175905811
481
GameObject:
582
m_ObjectHideFlags: 0
@@ -8,17 +85,19 @@ GameObject:
885
m_PrefabAsset: {fileID: 0}
986
serializedVersion: 6
1087
m_Component:
11-
- component: {fileID: 7179380614175905810}
88+
- component: {fileID: 4923542134778947503}
89+
- component: {fileID: 4923542134778947501}
1290
- component: {fileID: 7179380614175905809}
91+
- component: {fileID: 4923542134778947502}
1392
m_Layer: 0
1493
m_Name: TestReusableObject
1594
m_TagString: Untagged
1695
m_Icon: {fileID: 0}
1796
m_NavMeshLayer: 0
1897
m_StaticEditorFlags: 0
1998
m_IsActive: 1
20-
--- !u!4 &7179380614175905810
21-
Transform:
99+
--- !u!224 &4923542134778947503
100+
RectTransform:
22101
m_ObjectHideFlags: 0
23102
m_CorrespondingSourceObject: {fileID: 0}
24103
m_PrefabInstance: {fileID: 0}
@@ -27,10 +106,24 @@ Transform:
27106
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
28107
m_LocalPosition: {x: 0, y: 0, z: 0}
29108
m_LocalScale: {x: 1, y: 1, z: 1}
30-
m_Children: []
109+
m_Children:
110+
- {fileID: 4923542134477278752}
31111
m_Father: {fileID: 0}
32112
m_RootOrder: 0
33113
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
114+
m_AnchorMin: {x: 0, y: 0}
115+
m_AnchorMax: {x: 0, y: 0}
116+
m_AnchoredPosition: {x: 0, y: 0}
117+
m_SizeDelta: {x: 0, y: 0}
118+
m_Pivot: {x: 0.5, y: 0.5}
119+
--- !u!222 &4923542134778947501
120+
CanvasRenderer:
121+
m_ObjectHideFlags: 0
122+
m_CorrespondingSourceObject: {fileID: 0}
123+
m_PrefabInstance: {fileID: 0}
124+
m_PrefabAsset: {fileID: 0}
125+
m_GameObject: {fileID: 7179380614175905811}
126+
m_CullTransparentMesh: 0
34127
--- !u!114 &7179380614175905809
35128
MonoBehaviour:
36129
m_ObjectHideFlags: 0
@@ -43,3 +136,32 @@ MonoBehaviour:
43136
m_Script: {fileID: 11500000, guid: c4adee23f3328254894b3b69bcb72d41, type: 3}
44137
m_Name:
45138
m_EditorClassIdentifier:
139+
m_txtObjNumber: {fileID: 4923542134477278759}
140+
--- !u!114 &4923542134778947502
141+
MonoBehaviour:
142+
m_ObjectHideFlags: 0
143+
m_CorrespondingSourceObject: {fileID: 0}
144+
m_PrefabInstance: {fileID: 0}
145+
m_PrefabAsset: {fileID: 0}
146+
m_GameObject: {fileID: 7179380614175905811}
147+
m_Enabled: 1
148+
m_EditorHideFlags: 0
149+
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
150+
m_Name:
151+
m_EditorClassIdentifier:
152+
m_Material: {fileID: 0}
153+
m_Color: {r: 0.11605263, g: 1, b: 0, a: 1}
154+
m_RaycastTarget: 1
155+
m_OnCullStateChanged:
156+
m_PersistentCalls:
157+
m_Calls: []
158+
m_Sprite: {fileID: 10907, guid: 0000000000000000f000000000000000, type: 0}
159+
m_Type: 1
160+
m_PreserveAspect: 0
161+
m_FillCenter: 1
162+
m_FillMethod: 4
163+
m_FillAmount: 1
164+
m_FillClockwise: 1
165+
m_FillOrigin: 0
166+
m_UseSpriteMesh: 0
167+
m_PixelsPerUnitMultiplier: 1
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
using System.Collections;
22
using System.Collections.Generic;
33
using UnityEngine;
4+
using ns_YourNamespace;
45

5-
namespace ns_YourNamespace
6-
{
76
public class TestNonMonoPool : ObjectPool<TestNonMonoReusableObject>
87
{
98
public TestNonMonoPool(int a_iStartSize = 0)
10-
: base(typeof(TestNonMonoReusableObject).ToString(), a_iStartSize)
9+
: base(a_iStartSize)
1110
{
1211
}
1312
}
14-
}

ObjectPoolingSystem/Assets/ObjectPoolingSystem/Example/TestPoolManager.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
public class TestPoolManager : MonoBehaviour
77
{
88
#region MONO
9+
10+
[SerializeField]
11+
private GameObject m_ParentGameObj = null;
12+
913
[SerializeField]
1014
private TestMonoReusableObject m_ReusablePrefab = null;
1115

@@ -29,6 +33,7 @@ public void monoReturnAll()
2933
public void monoGetObjectFromPool()
3034
{
3135
TestMonoReusableObject l_ReusableObject = m_MonoObjectPool.getObject();
36+
l_ReusableObject.m_txtObjNumber.text = (m_MonoObjectPool.getActiveList().Count - 1).ToString();
3237
updateCount();
3338
}
3439

@@ -84,7 +89,7 @@ public void nonmonoGetObjectFromPool()
8489
public void nonmonoReturnObjectToPool()
8590
{
8691
List<TestNonMonoReusableObject> l_lstNonMonoReusable = m_NonMonoObjectPool.getActiveList();
87-
TestNonMonoReusableObject l_NonMonoReusableObject = l_lstNonMonoReusable.Count > 0 ? l_lstNonMonoReusable[0] : null;
92+
TestNonMonoReusableObject l_NonMonoReusableObject = l_lstNonMonoReusable.Count > 0 ? l_lstNonMonoReusable[l_lstNonMonoReusable.Count - 1] : null;
8893
if (l_NonMonoReusableObject == null)
8994
{
9095
Debug.LogError("TestManager::ReturnObjectToPool:: Active object list is empty. Count == 0");
@@ -105,7 +110,7 @@ public void nonmonoReturnObjectToPool()
105110

106111
void Awake()
107112
{
108-
m_MonoObjectPool = new MonoObjectPool<TestMonoReusableObject>(m_ReusablePrefab, gameObject, m_iMonoObjPoolStartSize);
113+
m_MonoObjectPool = new MonoObjectPool<TestMonoReusableObject>(m_ReusablePrefab, m_ParentGameObj, m_iMonoObjPoolStartSize);
109114
m_NonMonoObjectPool = new TestNonMonoPool(m_iNonMonoPooledStartCount);
110115

111116
updateCount();

ObjectPoolingSystem/Assets/ObjectPoolingSystem/Readme.txt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1-
FretBuzzObjectPool
2-
3-
This asset will be used to get and return objects from and to the pool providing reusability and automatic creation of the object if the pool is empty.
4-
You can use this asset for reusability of your objects.
1+
//Created by Rohan Fernandez
2+
//Contact fretbuzz31f@gmail.com for any details.
3+
4+
Object Pooling System
5+
6+
-Instantiation of gameobjects or creating objects require time to create and processing each time.
7+
-Using an object pool you can reuse the objects.
8+
-This asset will be used to get and return objects from and to the pool.
9+
-On creating the pool for the first time you can set the size of the pool, so that the pool is instantiated with the total amount of object you require at max. This prevents from instantiating/creating objects after that.
10+
-You can specialize the pool to act specifically for different types of objects, a MonoObjectPool is included in this asset for pooling of GameObjects(MonoBehaviour).
11+
-Gameobjects managed by the MonoObjectPool can be set to have a specific parent gameobject.
12+
-You can use this asset for reusability of your objects and automatic creation of the object if the pool is empty.
13+
-If the pool is empty and you call getObject(), the pool will automatically create an object.
14+
-One completed using an object return the object back into the pool.
515

616

717
-------- ObjectPool<T>

ObjectPoolingSystem/Assets/ObjectPoolingSystem/Scripts/ObjectPool/IReusable.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
using System.Collections.Generic;
33
using UnityEngine;
44

5+
/// <summary>
6+
/// Interface to be implemented on the type to be managed by an object pool
7+
/// This interface informs the object when it is retrieved from the pool or returned back into the pool
8+
/// </summary>
59
public interface IReusable
610
{
711
void onReturnedToPool();

ObjectPoolingSystem/Assets/ObjectPoolingSystem/Scripts/ObjectPool/MonoObjectPool.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
using System.Collections.Generic;
33
using UnityEngine;
44

5+
/// <summary>
6+
/// Specialized pooled class for objects of type MonoBehaviour,
7+
/// because creation requires instantiation in Unity instead of using new, adding an object to the heap
8+
/// </summary>
9+
/// <typeparam name="T"></typeparam>
510
public class MonoObjectPool<T> : ObjectPool<T> where T : MonoBehaviour, IReusable
611
{
712
/// <summary>
@@ -21,7 +26,7 @@ public class MonoObjectPool<T> : ObjectPool<T> where T : MonoBehaviour, IReusabl
2126
/// <param name="a_Prefab"></param>
2227
/// <param name="a_iStartPoolCapacity"></param>
2328
public MonoObjectPool(T a_Prefab, GameObject a_Parent, int a_iStartSize = 0)
24-
: base(typeof(T).ToString())
29+
: base()
2530
{
2631
m_goPrefab = a_Prefab;
2732
m_goParent = a_Parent;

0 commit comments

Comments
 (0)