void Clear() { //remove attatchment and points m_attatched = false; m_firstPoint = null; m_secondPoint = null; //disable edge drawer m_edge.enabled = false; }
/// <summary> /// Handles a mouse down event on the given point /// </summary> /// <param name="a_target"></param> public void MouseDown(TourPoint a_target) { //enalbe line drawing m_edge.enabled = true; //set first point m_firstPoint = a_target; //update edge line start m_edge.SetPosition(0, a_target.transform.position); }
/// <summary> /// Handles a mouse event on a settlement /// </summary> /// <param name="a_target"></param> public void MouseEnter(TourPoint a_target) { //don't do anything if no startint point has been selected if (m_firstPoint == null) { return; } //add lock to target point m_attatched = true; m_secondPoint = a_target; // update edge line end to target point m_edge.SetPosition(1, a_target.transform.position); }
/// <summary> /// Handles a mouse exit event for a given point /// </summary> /// <param name="a_target"></param> public void MouseExit(TourPoint a_target) { //do nothing if settlement was not the current target if (a_target != m_secondPoint) { return; } //remove the attatchement lock and the target settlement m_attatched = false; m_secondPoint = null; //update edge to mouse position var pos = Camera.main.ScreenToWorldPoint(Input.mousePosition + 10 * Vector3.forward); m_edge.SetPosition(1, pos); }
/// <summary> /// Add a road tour segment between 2 points /// </summary> /// <param name="a_point1"></param> /// <param name="a_point2"></param> public void AddSegment(TourPoint a_point1, TourPoint a_point2) { // Dont add edge to itself or double edges if (a_point1 == a_point2 || m_graph.ContainsEdge(a_point1.Vertex, a_point2.Vertex)) { return; } //instantiate new road mesh object var roadmesh = Instantiate(m_roadMeshPrefab, Vector3.forward, Quaternion.identity) as GameObject; roadmesh.transform.parent = this.transform; roadmesh.name = $"mesh({a_point1.Vertex}, {a_point2.Vertex})"; //remember segment for destoryal later instantObjects.Add(roadmesh); //create road mesh var roadmeshScript = roadmesh.GetComponent <ReshapingMesh>(); roadmeshScript.CreateNewMesh(a_point1.transform.position, a_point2.transform.position); //create road edge var edge = m_graph.AddEdge(a_point1.Vertex, a_point2.Vertex); //error check if (edge == null) { throw new InvalidOperationException("Edge could not be added to graph"); } //link edge to segment roadmesh.GetComponent <TourSegment>().Edge = edge; //check the solution CheckSolution(); UpdateTextField(); }