1- using System . Collections . Generic ;
2- using UnityEngine ;
1+ #region Statements
2+
33#if MIRAGE
44using Mirage ;
55#else
66using Mirror ;
77#endif
8+ using System . Collections . Generic ;
9+ using UnityEngine ;
10+
11+ #endregion
812
913namespace Object_Pooler
1014{
@@ -16,15 +20,15 @@ public struct PooledObject<T>
1620
1721 internal struct ObjectPooling < T > where T : Object
1822 {
19- #region Fields
23+ #region Fields
2024
2125 private readonly Queue < PooledObject < T > > _inactiveGameObjects ;
2226 private readonly T _objectPrefabToPool ;
2327 private readonly NetworkIdentity _networkObjectPrefabToPool ;
2428 internal readonly HashSet < int > PooledObjectIDs ;
2529 private readonly GameObject _parentBackObject ;
2630
27- #endregion
31+ #endregion
2832
2933 /// <summary>
3034 /// Constructor for this object pool.
@@ -56,7 +60,7 @@ public ObjectPooling(NetworkIdentity poolObject, int initialPool, GameObject net
5660 _objectPrefabToPool = null ;
5761 }
5862
59- #region Network Pool Spawning
63+ #region Network Pool Spawning
6064
6165 /// <summary>
6266 /// Method to spawn network object from our inactive pool.
@@ -82,7 +86,9 @@ public NetworkIdentity NetworkSpawn(Vector3 position, Quaternion rotation)
8286 spawnedObject = _inactiveGameObjects . Dequeue ( ) . NetId ;
8387
8488 if ( spawnedObject is null )
89+ {
8590 continue ;
91+ }
8692
8793 break ;
8894 }
@@ -112,7 +118,9 @@ public NetworkIdentity NetworkSpawn(Transform parentTransform, bool worldStayPos
112118 spawnedObject = _inactiveGameObjects . Dequeue ( ) . NetId ;
113119
114120 if ( spawnedObject is null )
121+ {
115122 continue ;
123+ }
116124
117125 spawnedObject . transform . SetParent ( parentTransform , worldStayPosition ) ;
118126
@@ -133,7 +141,10 @@ public NetworkIdentity NetworkSpawn(Transform parentTransform, bool worldStayPos
133141 /// <param name="obj">The object we want to return back to the pool.</param>
134142 internal void Despawn ( NetworkIdentity obj )
135143 {
136- if ( ! obj . gameObject . activeInHierarchy ) return ;
144+ if ( ! obj . gameObject . activeInHierarchy )
145+ {
146+ return ;
147+ }
137148
138149 obj . gameObject . SetActive ( false ) ;
139150
@@ -147,9 +158,9 @@ internal void Despawn(NetworkIdentity obj)
147158 _inactiveGameObjects . Enqueue ( recycle ) ;
148159 }
149160
150- #endregion
161+ #endregion
151162
152- #region Normal Pool Spawning.
163+ #region Normal Pool Spawning.
153164
154165 /// <summary>
155166 /// Method to spawn an object from our inactive pool.
@@ -175,7 +186,9 @@ public object Spawn(Vector3 position, Quaternion rotation)
175186 spawnedObject = _inactiveGameObjects . Dequeue ( ) . Object ;
176187
177188 if ( spawnedObject is null )
189+ {
178190 continue ;
191+ }
179192
180193 break ;
181194 }
@@ -205,7 +218,9 @@ public T Spawn(Transform parentTransform, bool worldStayPosition)
205218 spawnedObject = _inactiveGameObjects . Dequeue ( ) . Object ;
206219
207220 if ( spawnedObject is null )
221+ {
208222 continue ;
223+ }
209224
210225 ( spawnedObject as MonoBehaviour ) ? . transform . SetParent ( parentTransform , worldStayPosition ) ;
211226
@@ -262,6 +277,6 @@ internal void Despawn(T obj)
262277 _inactiveGameObjects . Enqueue ( recycle ) ;
263278 }
264279
265- #endregion
280+ #endregion
266281 }
267282}
0 commit comments