VladimirPirozhenko 45b277e7d1 Initial commit
2022-08-07 07:31:16 +03:00

43 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections;
using UnityEngine;
public class CoinPool : MonoBehaviour
{
private ObjectPool<Coin> pool;// { get; private set; } //ВЫНЕСТИ В ОТДЕЛЬНЫЙ КЛАСС, ЗДЕСЬ ХРАНИТЬ СПИСКИ
public void CreateCoinPool(Coin coinPrefab) // ВЫНЕСТИ В КЛАССЫ
{
Func<Coin> createCoin = () =>
{
Coin coin = Instantiate(coinPrefab);
coin.gameObject.SetActive(false);
coin.transform.SetParent(gameObject.transform, false);
return coin;
};
Action<Coin> getCoin = (Coin coin) =>
{
//Debug.LogError("COIN_POS_GET: " + coin.transform.position);
coin.gameObject.SetActive(true);
};
Action<Coin> releaseCoin = (Coin coin) =>
{
//Debug.LogError("COIN_POS_RELEASE: " + coin.transform.position);
coin.gameObject.SetActive(false);
coin.transform.position = Vector3.zero;
coin.transform.localPosition = Vector3.zero;
coin.transform.rotation = Quaternion.identity;
coin.transform.SetParent(null);
};
pool = new ObjectPool<Coin>(createCoin, getCoin, releaseCoin, 100);
}
public Coin GetFromPool()
{
return pool.Get();
}
public void ReturnToPool(Coin coin)
{
pool.ReturnToPool(coin);
}
}