Linerender on a GUI ?

Hello,
i’ve developed a script computing the response of an electronic filter. Now i’m trying to render it through a GUI, to do so i’m using a linerenderer and the canvas system and they don’t seem to work really great together. I’ve trouble with resolution and the line can go out of screen when you change it. Is there any better feature to render a list of points ?

This some view of the actual rendering but if i change the resolution everything goes out:

And this is the code rendering the line :

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

 
   
    public void reload(){
       
        if (PlayerPrefs.GetString ("Type") == "OrderOne") {
            f2=new OrderOne("PB",PlayerPrefs.GetFloat ("T0"), PlayerPrefs.GetFloat ("Tinf"), PlayerPrefs.GetFloat ("Omega0"));
        }
        if (PlayerPrefs.GetString ("Type") == "OrderTwo") {
            f2=new OrderTwo("PB",  PlayerPrefs.GetFloat ( "Omega0"), PlayerPrefs.GetFloat ( "m") , PlayerPrefs.GetFloat("T0"), PlayerPrefs.GetFloat("Tmax"),PlayerPrefs.GetFloat("Tinf"));
        }
       
        f2.autoscale (45f,20f);
        lineSol.SetVertexCount (0);
        lineModule.SetVertexCount (0);
        linePhase.SetVertexCount (0);
        echelon.SetVertexCount (0);
        lineSol.SetVertexCount (f2.getSol().Count);
        linePhase.SetVertexCount (f2.getOmega().Count);
        lineModule.SetVertexCount (f2.getOmega().Count);
        echelon.SetVertexCount (f2.getEchelon().Count);

        this.loadPosition ();               
    }
   
    private void loadPosition(){
        int i = 0;
        lineSol.useWorldSpace = true;
        lineModule.useWorldSpace = true ;
        linePhase.useWorldSpace = true;
        echelon.useWorldSpace = true;
        List<float> ech = f2.getEchelon ();
        while (i < f2.getT().Count) {
            Vector3 pos = new Vector3 ( f2.getT () [i]+20f, f2.getSol () [i]+25f, 50f);
            lineSol.SetPosition (i, pos);
            i++;
        }
        i=0;
        while (i < f2.getT().Count) {
            Vector3 pos = new Vector3 ( f2.getT ()[i] + 20f , ech [i] + 25f, 50f);
            echelon.SetPosition (i, pos);
            i++;
        }

        i = 0;
        while (i < f2.getOmega().Count) {
            Vector3 pos = new Vector3 (f2.getOmega () [i]+20f,  f2.getModule () [i], 50f);
            lineModule.SetPosition (i, pos);
            i++;
        }
       
        i = 0;
        while (i < f2.getOmega().Count) {
            Vector3 pos = new Vector3 (f2.getOmega () [i]+20f, f2.getPhase () [i]-30f, 50f);
            linePhase.SetPosition (i, pos);
            i++;
        }
       
    }
}

The solution lies in mapping a unit box in 3d to the size of the viewport.

Since you are probably rendering the line onto a plane using a perspective camera, you just need to determine the bounds of that box at the z-depth of the plane.

One way to do this is using
Unity - Scripting API: Camera.ViewportPointToRay

Once you have the corners of the box in world coordinates, you just need to scale the vertices of the LineRenderer so they fit correctly in the box.

If you drawing code assumes the line points in a 0-1 box , then 0 maps to box_left and 1 maps to box_right.

So just box_left + box_width*line_point_vert

Hello,
I am pacodupont’s colleague and we were wondering if there wasn’t an easier way to do this…
We use the autoscale function that we defined in our Function class which renders the line in a box (f2.autoscale(45f,20f) ) and we’ve been trying to set it (as well as the position of the lines) using Screen.width, camera.width, camera.pixelWidth, camera.rect, camera.pixelRect, but whenever we try to build the project in a different resolution it’s complete freestyle… Shouldn’t these features be able to fix our problems??

Ps: thank you very much for your help