Skip to content

Commit

Permalink
addendum to previous commits
Browse files Browse the repository at this point in the history
  • Loading branch information
ertanturan committed Nov 27, 2022
1 parent 1e4498f commit d9dd944
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions Assets/CustomTools/ObjectPooling/Scripts/ObjectPooler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,22 @@ public GameObject SpawnFromPool(PooledObjectType pooledObjectType, Vector3 posit
{
objToSpawn = _poolDictionary[pooledObjectType].Peek();
objToSpawn.SetActive(true);
objToSpawn.transform.position = position;
objToSpawn.transform.rotation = rotation;

if (parent)
{
objToSpawn.transform.SetParent(parent);
}

RectTransform rect = objToSpawn.GetComponent<RectTransform>();
if (rect != null)
{
rect.anchoredPosition = position;
}
else
{
objToSpawn.transform.position = position;
objToSpawn.transform.rotation = rotation;
}

IPooledObject iPooledObj = objToSpawn.GetComponent<IPooledObject>();

Expand All @@ -81,17 +95,6 @@ public GameObject SpawnFromPool(PooledObjectType pooledObjectType, Vector3 posit
return ExpandAndSpawnFromPool(pooledObjectType, position, rotation, parent);
}

if (parent)
{
objToSpawn.transform.SetParent(parent);
}

RectTransform rect = objToSpawn.GetComponent<RectTransform>();
if (rect != null)
{
rect.anchoredPosition = Vector2.zero;
}


return objToSpawn;
}
Expand Down

0 comments on commit d9dd944

Please sign in to comment.