풀링 매니저 생성 및 풀링 기능 구현
- 테스트 프리팹 삭제
This commit is contained in:
@@ -4,27 +4,43 @@ public class ResourceManager
|
||||
{
|
||||
public T Load<T>(string path) where T : Object
|
||||
{
|
||||
if(typeof(T) == typeof(GameObject))
|
||||
{
|
||||
string name = path;
|
||||
int index = name.LastIndexOf('/');
|
||||
|
||||
if (index >= 0)
|
||||
{
|
||||
name = name.Substring(index + 1);
|
||||
}
|
||||
|
||||
GameObject go = Managers.Pool.GetOriginal(name);
|
||||
|
||||
if (go != null)
|
||||
{
|
||||
return go as T;
|
||||
}
|
||||
}
|
||||
|
||||
return Resources.Load<T>(path);
|
||||
}
|
||||
|
||||
public GameObject Instantiate(string path, Transform parent = null)
|
||||
{
|
||||
GameObject prefab = Load<GameObject>($"Prefabs/{path}");
|
||||
if (prefab == null)
|
||||
GameObject original = Load<GameObject>($"Prefabs/{path}");
|
||||
if (original == null)
|
||||
{
|
||||
Debug.Log($"Failed to load prefab : {path}");
|
||||
return null;
|
||||
}
|
||||
|
||||
GameObject go = Object.Instantiate(prefab, parent);
|
||||
int index = go.name.IndexOf("(Clone)");
|
||||
|
||||
if (index >= 0)
|
||||
if (original.GetComponent<Poolable>() != null)
|
||||
{
|
||||
// go.name = go.name.Substring(0, index);
|
||||
go.name = go.name.Remove(index);
|
||||
return Managers.Pool.Pop(original, parent).gameObject;
|
||||
}
|
||||
|
||||
GameObject go = Object.Instantiate(original, parent);
|
||||
go.name = original.name;
|
||||
return go;
|
||||
}
|
||||
|
||||
@@ -34,6 +50,14 @@ public class ResourceManager
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Poolable poolable = go.GetComponent<Poolable>();
|
||||
if (poolable != null)
|
||||
{
|
||||
Managers.Pool.Push(poolable);
|
||||
return;
|
||||
}
|
||||
|
||||
Object.Destroy(go);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user