Ejemplo n.º 1
0
    public void AddEdge(PuzzleEdge edge)
    {
        EdgeFront edgeFront = Instantiate(edgePrefab) as EdgeFront;

        edgeFront.transform.parent = transform;
        edgeFront.gameObject.name  = "Edge " + edge.nodeA.name + " - " + edge.nodeB.name;
        edgeFront.Set(this, edge);
        edges.Add(edgeFront);
    }
Ejemplo n.º 2
0
 public EdgeFront GetEdge(PuzzleEdge edge)
 {
     foreach (EdgeFront edgeFront in edges)
     {
         if (edgeFront.edge == edge)
         {
             return(edgeFront);
         }
     }
     return(null);
 }
Ejemplo n.º 3
0
 public void RemoveEdge(PuzzleEdge edge)
 {
     // Remove element
     if (edge.element != null)
     {
         RemoveElement(edge.element);
     }
     // Remove edge
     edges.Remove(edge);
     removeEdge(edge);
 }
Ejemplo n.º 4
0
 public void RemoveEdge(PuzzleEdge edge)
 {
     foreach (EdgeFront edgeFront in edges)
     {
         if (edgeFront.edge == edge)
         {
             Destroy(edgeFront.gameObject);
             edges.Remove(edgeFront);
             break;
         }
     }
 }
Ejemplo n.º 5
0
    void HandleEdgeDrag()
    {
        if (Input.GetMouseButtonUp(0))
        {
            s_TempDragEdge.gameObject.SetActive(false);
            if (hovered is NodeFront && hovered != s_DragStartNode)
            {
                NodeFront hoveredNode = (hovered as NodeFront);

                // Add new node and edge to it.
                if (hovered == s_TempDragNode)
                {
                    PuzzleNode newNode = new PuzzleNode();
                    newNode.SetPosition(VectorToPoint(Snap(hoveredNode.transform.position)));
                    puzzle.AddNode(newNode);

                    foreach (NodeFront node in nodes)
                    {
                        if (node.node == newNode)
                        {
                            s_Selected = node;
                        }
                    }

                    PuzzleEdge edge = new PuzzleEdge(s_DragStartNode.node, newNode);
                    puzzle.AddEdge(edge);
                }

                // Add edge to existing node.
                else
                {
                    PuzzleEdge edge = new PuzzleEdge(s_DragStartNode.node, hoveredNode.node);
                    puzzle.AddEdge(edge);
                    foreach (EdgeFront edgeFront in edges)
                    {
                        if (edgeFront.edge == edge)
                        {
                            s_Selected = edgeFront;
                        }
                    }
                }
            }
            s_DragStartNode = null;
            s_TempDragNode.gameObject.SetActive(false);
        }
        else
        {
            Vector2 pos = GetMousePos();
            if (hovered is NodeFront)
            {
                pos = hovered.transform.position;
            }
            s_TempDragEdge.SetPositions(s_TempDragEdge.transform.position, pos);

            Vector2 snapped  = Snap(pos);
            Point   position = VectorToPoint(snapped);
            bool    validNew = true;
            if (Vector2.Distance(snapped, pos * 0.5f) > 0.25f)
            {
                validNew = false;
            }
            else
            {
                foreach (PuzzleNode node in puzzle.nodes)
                {
                    if (node.position == position)
                    {
                        validNew = false;
                        break;
                    }
                }
            }

            s_TempDragNode.gameObject.SetActive(validNew);
            s_TempDragNode.SetPoint(position);
        }
    }
Ejemplo n.º 6
0
 public void AddEdge(PuzzleEdge edge)
 {
     edges.Add(edge);
     addEdge(edge);
 }