Exemplo n.º 1
0
    public void GetEnityFromPoolAsync(string assetName, Action <GameObject> cb)
    {
        Queue <AssetPoolItem> pool = null;

        _entityPoolMap.TryGetValue(assetName, out pool);
        GameObject obj = null;

        if (pool != null && pool.Count > 0)
        {
            AssetPoolItem item = pool.Dequeue();
            obj = item.gameObject;
            obj.SetActive(true);
            cb(obj);
        }
        else
        {
            GetEntityPrefabAsync(assetName, (prefab) => {
                obj = GameObject.Instantiate <GameObject>(prefab);
                if (obj != null)
                {
                    AssetPoolItem item = obj.GetComponent <AssetPoolItem>();
                    if (item != null)
                    {
                        item.SetAssetName(assetName);
                    }
                    else
                    {
                        SampleDebuger.LogError("asset " + assetName + " is not a pool item");
                    }
                    cb(obj);
                }
            });
        }
    }