Exemplo n.º 1
0
 private void OnMouseUp(Vector2 touchPos, Transform hitTransform)
 {
     if (!ProcessUserInput)
     {
         return;
     }
     if (hitTransform)
     {
         if (hitTransform.tag == "Line" && !touchStartNode)
         {
             var line = hitTransform.GetComponent <ConnectionLine>();
             if (line.GraphId == graph.Id)
             {
                 Graph.RemoveConnectionMatrix(graph, line.Node1Index, line.Node2Index);
                 connectionLines.Remove(line);
                 nodes[line.Node1Index].lines.Remove(line);
                 nodes[line.Node2Index].lines.Remove(line);
                 Destroy(line.gameObject);
             }
         }
         else if (hitTransform.tag == "Node" && hitTransform.GetComponent <Node>().GraphId == graph.Id)
         {
             var node2 = hitTransform.GetComponent <Node>();
             if (touchStartNode && touchStartNode.Id != node2.Id && !Graph.IsNodesConnectedMatrix(graph, touchStartNode.Index, node2.Index))
             {
                 var node1 = touchStartNode;
                 currentLine.SetConnectedNodes(node1.Index, node1.transform.position, node2.Index, node2.transform.position, StaticValues.ColorByIndex[node1.ColorId - 1], StaticValues.ColorByIndex[node2.ColorId - 1]);
                 connectionLines.Add(currentLine);
                 node1.lines.Add(currentLine);
                 node2.lines.Add(currentLine);
                 currentLine = null;
                 Graph.AddConnectionMatrix(graph, node1.Index, node2.Index);
                 --remainingLineCount;
                 if (TxtRemainingLineCount)
                 {
                     TxtRemainingLineCount.text = remainingLineCount.ToString();
                 }
             }
         }
     }
     touchStartNode = null;
     if (currentLine)
     {
         Destroy(currentLine.gameObject); //TODO: instead, hide it to use later
     }
 }