ball 项目提交
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BallKingdomCrush
|
||||
{
|
||||
public class GObjectsPool
|
||||
{
|
||||
private Transform m_releaseRoot;
|
||||
private Transform m_getRoot;
|
||||
private Action<GameObject> m_onNew;
|
||||
private Action<GameObject> m_onGet;
|
||||
private Action<GameObject> m_onRelease;
|
||||
|
||||
private Dictionary<string, GObjectPool> m_pools = new();
|
||||
|
||||
public GameObject Get(string prefabPath, string assetName)
|
||||
{
|
||||
var poolName = $"{prefabPath} | {assetName}";
|
||||
if (!m_pools.ContainsKey(poolName))
|
||||
{
|
||||
RegisterNew(prefabPath, assetName);
|
||||
}
|
||||
|
||||
GObjectPool pool = m_pools[poolName];
|
||||
return pool.Get();
|
||||
}
|
||||
|
||||
private void RegisterNew(string prefabPath, string assetName)
|
||||
{
|
||||
GObjectPool pool = new GObjectPool();
|
||||
pool.Init(prefabPath, assetName, m_releaseRoot, m_getRoot);
|
||||
pool.InitCallBack(m_onNew, m_onGet, m_onRelease);
|
||||
m_pools.Add($"{prefabPath} | {assetName}", pool);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user