Esempio n. 1
0
    // Start is called before the first frame update
    void Start()
    {
        robot     = GameObject.Find("Robot");
        rb_script = robot.GetComponent <robotScript>();

        // First point will be the position of the robot game object
        waypointList.Add(robot);

        //lineRenderer instantiation

        lineRenderer                 = gameObject.AddComponent <LineRenderer>();
        lineRenderer.material        = new Material(Shader.Find("Sprites/Default"));
        lineRenderer.widthMultiplier = .1f;
        lineRenderer.positionCount   = rb_script.path_segments + 1;
        lineRenderer.sortingOrder    = 2;
        lineRenderer.useWorldSpace   = true;

        // A simple 2 color gradient with a fixed alpha of 1.0f.
        float    alpha    = 1.0f;
        Gradient gradient = new Gradient();

        gradient.SetKeys(
            new GradientColorKey[] { new GradientColorKey(c1, 0.0f), new GradientColorKey(c2, 1.0f) },
            new GradientAlphaKey[] { new GradientAlphaKey(alpha, 0.0f), new GradientAlphaKey(alpha, 1.0f) }
            );
        lineRenderer.colorGradient = gradient;
    }
    // Start is called before the first frame update
    void Start()
    {
        //access robot object with preloaded
        robot     = GameObject.Find("Robot");
        rb_script = robot.GetComponent <robotScript>();
        rb_body   = rb_script.robot_body;

        //lineRenderer instantiation
        LineRenderer lineRenderer = gameObject.AddComponent <LineRenderer>();

        lineRenderer.material        = new Material(Shader.Find("Sprites/Default"));
        lineRenderer.widthMultiplier = .1f;
        lineRenderer.positionCount   = rb_script.path_segments + 1;
        lineRenderer.sortingOrder    = 1;
        lineRenderer.useWorldSpace   = true;

        // A simple 2 color gradient with a fixed alpha of 1.0f.
        float    alpha    = 1.0f;
        Gradient gradient = new Gradient();

        gradient.SetKeys(
            new GradientColorKey[] { new GradientColorKey(c1, 0.0f), new GradientColorKey(c2, 1.0f) },
            new GradientAlphaKey[] { new GradientAlphaKey(alpha, 0.0f), new GradientAlphaKey(alpha, 1.0f) }
            );
        lineRenderer.colorGradient = gradient;
    }
    private void saveCallback()
    {
        robotScript rb_Script = GameObject.Find("Robot").GetComponent <robotScript>();

        rb_Script.setTrajectoryConstants(float.Parse(maxJerk.text),
                                         float.Parse(maxAcc.text),
                                         float.Parse(maxDeacc.text),
                                         float.Parse(maxVel.text));
        rb_Script.setPathGenerationConstants(float.Parse(maxStepX.text),
                                             float.Parse(maxStepY.text),
                                             float.Parse(maxStepTheta.text),
                                             float.Parse(lookaheadDist.text));
        rb_Script.setRobotConstants(float.Parse(driveRadius.text),
                                    float.Parse(driveWidth.text));
    }
    private void StartAlgo()
    {
        GameObject robot = (GameObject)Instantiate(robotPrefab);

        _robotScript = robot.GetComponent <robotScript>();
        switch (StaticVars.algo)
        {
        case "BFS":
            graph.BFS(StaticVars.startRow, StaticVars.startCol, graph);
            break;

        case "DFS":
            graph.DFS(StaticVars.startRow, StaticVars.startCol, graph);
            break;

        default:
            throw new Exception("No Algo");
        }
    }