Ejemplo n.º 1
0
    public void RemoveBottomPiece()
    {
        if (piecesCollection.Count == 0)
        {
            return;
        }

        TreePiece pieceToRemove = piecesCollection.Dequeue();

        pieceToRemove.DestroyPiece();

        //Move the trunk down
        StopAllCoroutines();
        Vector3 startPosition = trunkParent.localPosition;
        Vector3 endPosition   = -Vector3.up * (treeSize - piecesCollection.Count);

        StartCoroutine(Helper.AnimationRoutine(collapseAnimationDuration, t =>
        {
            trunkParent.localPosition = Vector3.LerpUnclamped(startPosition, endPosition, collapseCurve.Evaluate(t));
        }));

        //If this was the last piece, we fire the event saying the tree was totally destroyed
        if (piecesCollection.Count == 0)
        {
            treeDestroyed?.Invoke(this, EventArgs.Empty);
        }
    }
Ejemplo n.º 2
0
    public override void ReturnToPool()
    {
        //Return all remaining pieces to the pool, in case there's still any
        while (piecesCollection.Count > 0)
        {
            TreePiece piece = piecesCollection.Dequeue();
            piece.transform.SetParent(null);
            piece.ReturnToPool();
        }

        base.ReturnToPool();
    }
Ejemplo n.º 3
0
    private void GenerateTrunk(int size)
    {
        //Clear the list of pieces if any still exists
        while (piecesCollection.Count > 0)
        {
            TreePiece piece = piecesCollection.Dequeue();
            piece.ReturnToPool();
        }

        treeSize = size;
        trunkParent.localPosition = Vector3.zero;

        //Create new pieces based on the size
        for (int i = 0; i < size; i++)
        {
            TreePiece piece = treePiecesPool.GetPooledObject <TreePiece>();
            piece.transform.SetParent(trunkParent);
            piece.transform.SetAsFirstSibling();
            piece.transform.localPosition = Vector3.up * i;
            piece.transform.localScale    = Vector3.one;
            piece.transform.localRotation = Quaternion.AngleAxis(UnityEngine.Random.Range(0, 4) * 90, Vector3.up);
            piecesCollection.Enqueue(piece);
        }
    }