Exemplo n.º 1
0
    IEnumerator DrawLine(WorldBubble startNode, WorldBubble destNode, Color c, string factor, float time = -1, int verts = 100, float delay = 1)
    {
        Vector3 start = startNode.transform.position, dest = destNode.transform.position;

        time = time == -1 ? duration : time;

        GameObject lrgo = GameObject.Instantiate(baseLine, Vector3.zero, Quaternion.identity, transform);

        lrgo.SetActive(true);
        LineRenderer lr = lrgo.GetComponent <LineRenderer>();

        lr.material.color = c;
        lr.positionCount  = 2;

        // float mag = (dest - start).magnitude / 2;
        // float angle = Mathf.Atan2((dest - start).y, (dest - start).x);

        Vector3 half   = Vector3.Lerp(start, dest, .5f);
        var     dir    = Vector2.Perpendicular(dest - start).normalized *dist;
        var     centre = half + new Vector3(dir.x, dir.y, 0);

        var startAngle = Mathf.Atan2((centre - start).y, (centre - start).x) * Mathf.Rad2Deg;
        var destAngle  = Mathf.Atan2((centre - dest).y, (centre - dest).x) * Mathf.Rad2Deg;

        // TODO: animation curve lerp
        List <Vector3> points = new int[verts].Map((_, i) =>
                                                   Func.Lambda <float, Vector3>((float newAngle) => new Vector3(-Mathf.Cos(newAngle), -Mathf.Sin(newAngle), -1) * (centre - start).magnitude + centre)
                                                       (Mathf.LerpAngle(startAngle, destAngle, (float)i / verts) * Mathf.Deg2Rad)
                                                   ).ToList();

        lr.SetPositions(points.Take(2).ToArray());
        float begin      = Time.time;
        bool  inProgress = true;

        while (inProgress)
        {
            yield return(null);

            int   curCount = lr.positionCount;
            float step     = Time.time - begin;
            lr.positionCount = System.Math.Min((int)(step / time * verts), verts);
            for (int i = curCount; i < lr.positionCount; i++)
            {
                lr.SetPosition(i, points[i]);
            }
            if (step > time)
            {
                inProgress = false;
            }
        }
        if (factor != "")
        {
            StartCoroutine(ShowLogo(destNode.icons[World.GetFactor(factor)?.verbose], delay));
        }
        yield return(new WaitForSeconds(delay));

        // lr.Simplify(1E-8);

        StartCoroutine(EraseLine(lr, points, .25f));
    }
Exemplo n.º 2
0
 void Start()
 {
     // World.lineToDraw = new List < (World.Region, World.Region, string) > () { (World.Region.City, World.Region.Forest, "co2"), (World.Region.City, World.Region.Arctic, "co2"), (World.Region.City, World.Region.Fire, "co2") };
     foreach (var(from, to, tag) in World.lineToDraw)
     {
         WorldBubble dest = Fetch($"{to.ToString()}Node").GetValue(this) as WorldBubble;
         StartCoroutine(DrawLine(Fetch($"{from.ToString()}Node").GetValue(this) as WorldBubble, dest, dest.colour, tag));
     }
     World.lineToDraw = new List <(World.Region, World.Region, string)> ();
 }