Example #1
0
        protected override void Awake()
        {
            base.Awake();

            // Initialize the pools
            if (Instance == this)
            {
                // This manager should persist after level restarts
                transform.SetParent(null, false);
                DontDestroyOnLoad(gameObject);

                _piecePool.CreateFunction = () =>
                {
                    HexagonPiece result = Instantiate(piecePrefab);
                    SceneManager.MoveGameObjectToScene(result.gameObject, gameObject.scene); // So that the piece will be DontDestroyOnLoad'ed
                    result.transform.localScale = new Vector3(GridManager.PIECE_WIDTH, GridManager.PIECE_WIDTH, GridManager.PIECE_WIDTH);

                    return(result);
                };
                _piecePool.OnPop  = (piece) => piece.gameObject.SetActive(true);
                _piecePool.OnPush = (piece) => piece.gameObject.SetActive(false);
                _piecePool.Populate(32);

                _bombPool.CreateFunction = () =>
                {
                    HexagonBomb result = Instantiate(bombPrefab);
                    SceneManager.MoveGameObjectToScene(result.gameObject, gameObject.scene); // So that the bomb will be DontDestroyOnLoad'ed
                    result.transform.localScale = new Vector3(GridManager.PIECE_WIDTH, GridManager.PIECE_WIDTH, GridManager.PIECE_WIDTH);

                    return(result);
                };
                _bombPool.OnPop  = (bomb) => bomb.gameObject.SetActive(true);
                _bombPool.OnPush = (bomb) =>
                {
                    bomb.gameObject.SetActive(false);
                    bomb.transform.SetParent(null, false); // Bombs are attached to their target hexagon pieces, release the bomb
                };
                _bombPool.Populate(2);

                _matchPool.CreateFunction = () => new HexagonMatch();
                _matchPool.OnPush         = (match) => match.Clear();
                _matchPool.Populate(8);

                _moveAnimPool.CreateFunction = () => new AnimationManager.MovePieceAnimation();
                _moveAnimPool.Populate(64);

                _blowAnimPool.CreateFunction = () => new AnimationManager.BlowPieceAnimation();
                _blowAnimPool.Populate(8);
            }
        }