// Use this for initialization void Start() { Instance = this; //listPolygon = new List<GameObject>(); workPoly = null; MouseState = VOID; ActiveMenu = false; //guideLines = new GameObject[4]; guideLines = new GameObject[2]; for (int n = 0; n < 2; n++) { guideLines[n] = Instantiate(LinePrefab, new Vector3(0f, 0f, -1f), LinePrefab.transform.rotation); guideLines[n].transform.localScale += new Vector3(499.0f, -0.9f, 0); guideLines[n].transform.Rotate(new Vector3(0, 0, n * 90)); //guideLines[n].transform.Rotate(new Vector3(0, 0, n * 45)); guideLines[n].GetComponent <SpriteRenderer>().color = new Color(130, 0, 205, 90); guideLines[n].SetActive(false); guideLines[n].transform.parent = SceneObjects.transform; } path = Application.dataPath + "/StreamingAssets/Line2Blocks/"; GameObject.Find("std2").GetComponent <Text>().color = WOOD_COLOR; }
public void ResolveLeftClick() { //if (!EventSystem.current.IsPointerOverGameObject() return; if (MouseX < 0 || MouseY < 0 || _lock || _hardLock) { return; } GameObject poly; sVertex v1; sVertex v2; int deltaX; int deltaY; switch (MouseState) { case VOID: // Declara nova Estrutura e adiciona um vértice na posição do mouse if (workPoly == null) { poly = Instantiate(Polygon); // poly.name = "Estrutura_" + (listPolygon.Count + 1).ToString(); // listPolygon.Add(poly); workPoly = poly.GetComponent <sPolygon>(); workPoly.Init(); poly.transform.parent = SceneObjects.transform; } workPoly.AddVertex(MouseX, MouseY); break; case CELL: // Declara novo vértice, traça linha entre novo vértice e vértice ativo da estrutura v1 = workPoly.GetActiveVertex(); deltaX = (int)v1.Coordinate.x - MouseX; deltaY = ( int )v1.Coordinate.y - MouseY; if (deltaX == 0 || deltaY == 0) { // mesma linha horizontal ou vertical v2 = workPoly.AddVertex(MouseX, MouseY); workPoly.AddLine(v1, v2); } // else if (Mathf.Abs(deltaX) == Mathf.Abs(deltaY)) { // Ângulo de 45º //v2 = workPoly.AddVertex(MouseX, MouseY); //} else { // if (Mathf.Abs(deltaX) > Mathf.Abs(deltaY)) { // int coordY = (int)v1.Coordinate.y - Mathf.Abs(deltaX) * Mathf.Abs(deltaY) / deltaY; // if (coordY >= 0 && coordY < sGridController.GetInstance().maxHeight && Mathf.Abs(deltaY) > Mathf.Abs(deltaX) / 2) { // // Reta em ângulo // v2 = workPoly.AddVertex(MouseX, coordY); // } else { // // Reta em nível // v2 = workPoly.AddVertex(MouseX, ( int )v1.Coordinate.y); // } // } else { // int coordX = (int)v1.Coordinate.x - Mathf.Abs(deltaY) * Mathf.Abs(deltaX) / deltaX; // if (coordX >= 0 && coordX < sGridController.GetInstance().maxWidth && Mathf.Abs(deltaX) > Mathf.Abs(deltaY) / 2) { // // Reta em ângulo // v2 = workPoly.AddVertex(coordX, MouseY); // } else { // // Reta em nível // v2 = workPoly.AddVertex(( int )v1.Coordinate.x, MouseY); // } // } //} //workPoly.AddLine(v1, v2); break; //case NO_VERTEX: // // Seleciona Estrutura e vértice // workPoly = listPolygon.Find(p => p.GetComponent<sPolygon>().SelectVertex(MouseX, MouseY)).GetComponent<sPolygon>(); // break; case SAME_VERTEX: // Cria linha entre os dois vértices (ativo e clicado) v1 = workPoly.GetActiveVertex(); v2 = workPoly.GetVertex(MouseX, MouseY); deltaX = (int)(v1.Coordinate.x - v2.Coordinate.x); deltaY = (int)(v1.Coordinate.y - v2.Coordinate.y); if (deltaX == 0 && deltaY == 0) { // Mesmo ponto break; } else if (deltaX != 0 && deltaY != 0) { HardLock(true); Warning.SetActive(true); GameObject.Find("Mensagem").GetComponent <Text>().text = "Não é possível traçar retas anguladas"; } else { workPoly.AddLine(v1, v2); workPoly.SelectVertex(MouseX, MouseY); } break; //case DIFF_VERTEX: // // Desseleciona esrutura, seleciona nova esrutura e vértice // workPoly.Desselect(); // workPoly = listPolygon.Find(p => p.GetComponent<sPolygon>().SelectVertex(MouseX, MouseY)).GetComponent<sPolygon>(); // break; //case NO_LINE: // // Seleciona estrutura e segmenta reta // workPoly = listPolygon.Find(p => p.GetComponent<sPolygon>().ContainsLine(MouseX, MouseY) != null).GetComponent<sPolygon>(); // workPoly.SegmentLine(MouseX, MouseY); // break; case SAME_LINE: // Segmenta reta workPoly.SegmentLine(MouseX, MouseY); break; //case DIFF_LINE: // // Desseleciona estrutura, seleciona nova estrutura e segmenta a linha // workPoly.Desselect(); // workPoly = listPolygon.Find(p => p.GetComponent<sPolygon>().ContainsLine(MouseX, MouseY) != null).GetComponent<sPolygon>(); // workPoly.SegmentLine(MouseX, MouseY); // break; } UpdateMouseState(); }