Exemple #1
0
    public void Merge(GraphicEntity1 another, float duration = 0)
    {
        // TODO race condition!!
        var target = rect.Merge(another.rect);

        another.Remove(duration);
        Transform(target, duration);
    }
Exemple #2
0
    IEnumerator Section4Lifecycle(GraphicEntity1 g)
    {
        var targetRect = new GridRect(g.rect.min.x - 1, g.rect.min.y - 1, Random.Range(1, 5), Random.Range(1, 4));

        g.Transform(targetRect, Beat(1));
        if (targetRect.area > 1)
        {
            g.SetOpacity(Mathf.Max(0, g.opacity - 0.17f), Beat(1));
        }
        yield return(Rest(0, 1.25f));

        if (g.opacity.IsZero())
        {
            g.Remove();
            yield break;
        }
        // Break to unit squares
        g.RotateTo(0, Beat(1));
        yield return(Rest(0, 2f));

        var squares = g.BreakToUnitSquares();

        yield return(Rest(0, 1.25f));

        var rot = Random.Range(0, 12) * 30;

        foreach (var unit in squares)
        {
            var colorRand = Random.value;
            if (colorRand < 0.45f)
            {
                unit.SetColor(orange.WithAlpha(unit.opacity));
            }
            //else if (colorRand < 0.66f) {
            //unit.SetColor(blue.WithAlpha(unit.opacity));
            //}
            int dx = Random.Range(-1, 2);
            int dy = Random.Range(-1, 2);
            unit.Move(dx, dy, Beat(1.25f));
            unit.RotateFor(rot, Beat(2));
        }
        yield return(Rest(0, 2.5f));

        rot = Random.Range(0, 12) * 30;
        foreach (var unit in squares)
        {
            int dx = Random.Range(-1, 2);
            int dy = Random.Range(-1, 2);
            unit.Move(dx, dy, Beat(1));
            unit.RotateFor(rot, Beat(2));
        }
        yield return(Rest(0, 2.5f));

        foreach (var unit in squares)
        {
            if (unit != null)
            {
                if (Random.value < 0.2f)
                {
                    StartCoroutine(Section4Lifecycle(unit));
                }
                else
                {
                    unit.Remove(Beat(2));
                }
            }
        }
    }