// Update is called once per frame void Update() { if(Input.GetMouseButtonDown(0)) { Vector3 mousePos = Camera.main.ScreenToWorldPoint( new Vector3(Input.mousePosition.x, Input.mousePosition.y, -Camera.main.transform.position.z)); Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if(Physics.Raycast(mouseRay, out hitInfo, float.MaxValue)) { SphereCollider sc = hitInfo.collider as SphereCollider; if(sc != null) { Debug.Log("Selected: " + sc.name + " RAY: " + mouseRay + "MOUSE: " + mousePos); lastSelection = sc.gameObject.GetComponent<GraphVertice>(); lastSelection.isSelected = true; lastSelection.renderer.sharedMaterial = graph.selectedMaterial; } } } else if(Input.GetMouseButtonUp(0)) { if(lastSelection != null) { lastSelection.renderer.sharedMaterial = graph.defaultMaterial; lastSelection.isSelected = false; lastSelection = null; } } }
public GraphLine CreateNeighborLine(GraphVertice vert) { PlanarGraph graph = GameObject.FindObjectOfType<PlanarGraph>(); if(neighbors.Contains(vert)) { return null; } // Neighbors - to avoid duplicating lines - add SELF to THEIR neighbors list neighbors.Add(vert); vert.neighbors.Add(this); // create line renderers to each other vertice // this +--------------+ vert string name = this.name + "-line-" + vert; GraphLine newLine = new GameObject(name).AddComponent<GraphLine>(); newLine.gameObject.transform.position = Vector3.zero; newLine.gameObject.transform.rotation = Quaternion.identity; newLine.gameObject.transform.localScale = Vector3.one; newLine.A = this; newLine.B = vert; // add lineRenderer LineRenderer lr = newLine.gameObject.AddComponent<LineRenderer>(); lr.SetVertexCount(2); lr.SetWidth(0.1f, 0.1f); lr.SetPosition(0, newLine.A.transform.position); lr.SetPosition(1, newLine.B.transform.position); lr.sharedMaterial = graph.lineNormalMaterial; //lines.Add(newLine); return newLine; }
// Use this for initialization void Start() { graph = GetComponent<PlanarGraph>(); lastSelection = null; }