Esempio n. 1
0
    void ResetGraphLines()
    {
        _edgeLines.ForEach(e => GameObject.Destroy(e));
        _edgeLines.Clear();
        List <Edge <SpringNode> > edges = _undirectedGraph.GetEdges();

        foreach (var edge in edges)
        {
            //Calculate the difference between the edge length and the desired length
            float relaxedDistance = Mathf.Abs((float)edge.Weight - (edge.Source.Position - edge.Target.Position).magnitude);
            float colour          = Mathf.Clamp01(relaxedDistance / 2);

            //Draw lines
            GameObject   edgeLine = new GameObject($"Edge {_edgeLines.Count}");
            LineRenderer renderer = edgeLine.AddComponent <LineRenderer>();
            renderer.SetPosition(0, edge.Source.Position);
            renderer.SetPosition(1, edge.Target.Position);

            //Set colours
            renderer.material   = _lineRenderMaterial;
            renderer.startWidth = 0.2f;
            renderer.startColor = new Color(colour, 1 - colour, 0f);
            renderer.endWidth   = 0.2f;
            renderer.endColor   = new Color(colour, 1 - colour, 0f);
            _edgeLines.Add(edgeLine);
        }
    }
Esempio n. 2
0
    void ResetGraphLines()
    {
        _edgeLines.ForEach(e => GameObject.Destroy(e));
        _edgeLines.Clear();
        List <Edge <GameObject> > edges = _undirectedGraph.GetEdges();

        foreach (var edge in edges)
        {
            GameObject   edgeLine = new GameObject($"Edge {_edgeLines.Count}");
            LineRenderer renderer = edgeLine.AddComponent <LineRenderer>();
            renderer.SetPosition(0, edge.Source.transform.position);
            renderer.SetPosition(1, edge.Target.transform.position);
            renderer.startWidth = 0.2f;
            renderer.startColor = new Color(1f, 0f, 0f);
            renderer.endWidth   = 0.2f;
            renderer.startColor = new Color(0f, 1f, 0f);
            _edgeLines.Add(edgeLine);
        }
    }
    //public LineType _lineType = LineType.Empty;

    //public LineType Status
    //{
    //    get
    //    {
    //        return _lineType;
    //    }
    //    set
    //    {
    //        _line.SetActive(value == LineType.Empty);
    //        _lineType = value;
    //    }
    //}

    //public void SetAsPublicLine()
    //{
    //    if (Status == LineType.Public)
    //    {
    //        _line.GetComponent<MeshRenderer>().material = Resources.Load<Material>("Materials/Public");
    //    }
    //}
    //public void SetAsPrivateLine()
    //{
    //    if (Status == LineType.Private)
    //    {

    //        _line.GetComponent<MeshRenderer>().material = Resources.Load<Material>("Materials/Private");
    //    }
    //}



    //A new list with only the edges that hold the vertices you want to use, and recreate the graph
    //AllEmptyVoxels
    public void ResetGraphLines()
    {
        // Adjust the Line Grid in here
        _edgeLines.ForEach(e => GameObject.Destroy(e));
        _edgeLines.Clear();

        List <Edge <Voxel> > edges = VoxelGraph.GetEdges();

        foreach (var edge in edges)
        {
            GameObject   edgeLine = new GameObject($"Edge {_edgeLines.Count}");
            LineRenderer renderer = edgeLine.AddComponent <LineRenderer>();

            renderer.SetPosition(0, edge.Source._voxelGO.transform.position);
            renderer.SetPosition(1, edge.Target._voxelGO.transform.position);
            renderer.startWidth = 0.02f;
            renderer.startColor = new Color(0f, 0f, 0f);
            renderer.endWidth   = 0.02f;
            renderer.startColor = new Color(0f, 0f, 0f);
            _edgeLines.Add(edgeLine);
        }
    }