Beispiel #1
0
    public void SplitRectangle(BodyRectangle r, Vector2 pos, BodySplitType splitType)
    {
        // O2 Info for split rectangle
        var O2      = r.GetComponent <OxigenationMeter>();
        var O2Ratio = O2.OxygenRatio;

        BodyRectangle Ob1 = null;
        BodyRectangle Ob2 = null;

        switch (splitType)
        {
        case BodySplitType.Vertical:
            Vector2 newPos = new Vector2((r.position.x - r.HorizontalSize / 2 + pos.x) / 2, r.position.y);
            Ob1 = Instantiate(this.bodyRectPrefab, newPos, Quaternion.identity, r.transform.parent);
            Ob1.Initialize(Mathf.Abs(pos.x - (r.position.x - r.HorizontalSize / 2)), r.VerticalSize);
            Ob1.transform.position = newPos;

            newPos = new Vector2((r.position.x + r.HorizontalSize / 2 + pos.x) / 2, r.position.y);
            Ob2    = Instantiate(this.bodyRectPrefab, newPos, Quaternion.identity, r.transform.parent);
            Ob2.Initialize(Mathf.Abs(pos.x - (r.position.x + r.HorizontalSize / 2)), r.VerticalSize);
            Ob2.transform.position = newPos;
            break;

        case BodySplitType.Horizontal:
            Vector2 newPosV = new Vector2(r.position.x, (r.position.y - r.VerticalSize / 2 + pos.y) / 2);
            Ob1 = Instantiate(this.bodyRectPrefab, newPosV, Quaternion.identity, r.transform.parent);
            Ob1.Initialize(r.HorizontalSize, Mathf.Abs(pos.y - (r.position.y - r.VerticalSize / 2)));
            Ob1.transform.position = newPosV;

            newPosV = new Vector2(r.position.x, (r.position.y + r.VerticalSize / 2 + pos.y) / 2);
            Ob2     = Instantiate(this.bodyRectPrefab, newPosV, Quaternion.identity, r.transform.parent);
            Ob2.Initialize(r.HorizontalSize, Mathf.Abs(pos.y - (r.position.y + r.VerticalSize / 2)));
            Ob2.transform.position = newPosV;
            break;
        }

        OxygenPerArea.Value += OxygenPerAreaIncrementerSplit.Value;

        {
            var newO2     = Ob1.GetComponent <OxigenationMeter>();
            var maxOxygen = Ob1.Area * OxygenPerArea.Value;
            newO2.SetOxygenData(O2Ratio, maxOxygen);
            StartCoroutine(FadeIn(Ob1));
            rectangles.Add(Ob1);
        }

        {
            var newO2     = Ob2.GetComponent <OxigenationMeter>();
            var maxOxygen = Ob2.Area * OxygenPerArea.Value;
            newO2.SetOxygenData(O2Ratio, maxOxygen);
            StartCoroutine(FadeIn(Ob2));
            rectangles.Add(Ob2);
        }

        // delete rectangle
        rectangles.Remove(r);
        StartCoroutine(FadeOut(r));
    }
Beispiel #2
0
    private IEnumerator FadeIn(BodyRectangle r)
    {
        var renderer = r.GetComponent <SpriteRenderer>();

        for (float t = 0; t < this.rectangleFadeoutTime; t += Time.deltaTime)
        {
            var newColorT = renderer.color;
            var alpha     = Mathf.Lerp(0, 1, t / this.rectangleFadeoutTime);
            newColorT.a    = alpha;
            renderer.color = newColorT;
            yield return(null);
        }
    }