Newer
Older
fall / FallUnity / Assets / Leaves / Pile.cs
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Pile : MonoBehaviour {
    public int NumLeaves = 0;
    public GameObject Mesh;
    public float Height;

    private float currentScale = 0;

    private float? initialPop = null;
    internal float InitialPop
    {
        set
        {
            if (tween == null)
            {
                initialPop = value;
            }
            else
            {
                Pop(value);
            }
        }
    }
    // Use this for initialization
    void Start() {
        tween = new SimpleTween();
        SetPileScale(0);

        if (initialPop.HasValue)
        {
            Pop(initialPop.Value);
        }
    }

    private void SetPileScale(float scale)
    {
        currentScale = scale;
        Vector3 pos = Mesh.transform.position;
        pos.y = -Height * (1.0f - scale);
        Mesh.transform.position = pos;

        float meshScale = scale * 0.5f + 0.5f;
        Mesh.transform.localScale = new Vector3(meshScale, meshScale, meshScale);
	}
	
	// Update is called once per frame
	void Update () {
		
	}

    private SimpleTween tween;
    public void Pop(float pileScale)
    {
        initialPop = null;
        tween.Init(SetPileScale, SimpleTween.QuadEaseOut, currentScale, pileScale, (pileScale - currentScale) * 0.8f);
    }
}