@@ -5,11 +5,13 @@ namespace ToolBox.Pools
55{
66 public sealed class Pool
77 {
8- private Poolable _prefab = null ;
9- private Stack < Poolable > _instances = null ;
8+ private readonly Poolable _prefab = null ;
9+ private readonly Stack < Poolable > _instances = null ;
10+ private readonly Quaternion _rotation = default ;
11+ private readonly Vector3 _scale = default ;
1012
11- private static Dictionary < int , Pool > _prefabLookup = new Dictionary < int , Pool > ( ) ;
12- private static Dictionary < int , Pool > _instanceLookup = new Dictionary < int , Pool > ( ) ;
13+ private static readonly Dictionary < int , Pool > _prefabLookup = new Dictionary < int , Pool > ( ) ;
14+ private static readonly Dictionary < int , Pool > _instanceLookup = new Dictionary < int , Pool > ( ) ;
1315
1416 public Pool ( GameObject prefab )
1517 {
@@ -24,6 +26,10 @@ public Pool(GameObject prefab)
2426
2527 _instances = new Stack < Poolable > ( ) ;
2628 _prefabLookup . Add ( prefab . GetHashCode ( ) , this ) ;
29+
30+ var transform = prefab . transform ;
31+ _rotation = transform . rotation ;
32+ _scale = transform . localScale ;
2733 }
2834
2935 public static Pool GetPrefabPool ( GameObject prefab )
@@ -91,12 +97,16 @@ public GameObject Get(Vector3 position, Quaternion rotation, Transform parent)
9197
9298 public void Release ( GameObject instance )
9399 {
94- var poolable = instance . GetComponent < Poolable > ( ) ;
95- _instances . Push ( poolable ) ;
96-
97- instance . transform . SetParent ( null ) ;
98100 instance . SetActive ( false ) ;
101+
102+ var instanceTransform = instance . transform ;
103+ instanceTransform . SetParent ( null ) ;
104+ instanceTransform . rotation = _rotation ;
105+ instanceTransform . localScale = _scale ;
106+
107+ var poolable = instance . GetComponent < Poolable > ( ) ;
99108 poolable . OnRelease ( ) ;
109+ _instances . Push ( poolable ) ;
100110 }
101111
102112 private Poolable GetInstance ( )
0 commit comments