// Use this for initialization void Start() { placemat = GetComponent <Placemat>(); placemat.OnPlacematEnter += Placemat_OnPlacematEnter; placemat.OnPlacematExit += Placemat_OnPlacematExit; GetComponentInChildren <MeshRenderer>().enabled = false; CreateVirus(); }
void AddToPlacemat() { var pos = new Rect(); var nodeList = new List <GraphElement>(); foreach (ISelectable s in selection) { if (s is Node n) { nodeList.Add(n); } } if (nodeList.Count > 0 && Placemat.ComputeElementBounds(ref pos, nodeList)) { CreatePlacemat(pos); } }
IEnumerator CreateElements(Vector2 firstNodePos, Vector2 secondNodePos, Vector2 placematPos, Vector2 stickyNotePos, bool smallerSize) { FirstNodeModel = CreateNode("Node1", firstNodePos); SecondNodeModel = CreateNode("Node2", secondNodePos); PlacematModel = CreatePlacemat(new Rect(placematPos, new Vector2(200, smallerSize ? 100 : 200)), "Placemat"); StickyNoteModel = CreateSticky("Sticky", "", new Rect(stickyNotePos, smallerSize ? new Vector2(100, 100) : new Vector2(200, 200))); MarkGraphViewStateDirty(); yield return(null); // Get the UI elements m_FirstNode = FirstNodeModel.GetUI <Node>(graphView); m_SecondNode = SecondNodeModel.GetUI <Node>(graphView); m_Placemat = PlacematModel.GetUI <Placemat>(graphView); m_StickyNote = StickyNoteModel.GetUI <StickyNote>(graphView); Assert.IsNotNull(m_FirstNode); Assert.IsNotNull(m_SecondNode); Assert.IsNotNull(m_Placemat); Assert.IsNotNull(m_StickyNote); }
public IEnumerator ElementUnderMouseShouldSnapWhenMultipleSelectedElements() { // Config // // | | //----+-------+----------------- // | Node1 | +-----|----+ // +-------+ | Placemat | // | +----------+ // | | m_SnappingNodePos = new Vector2(k_ReferenceNodePos.x, k_ReferenceNodePos.y); snappingNodeModel = CreateNode("Node1", m_SnappingNodePos); Vector2 secondElementPos = new Vector2(m_SnappingNodePos.x + k_HalfSpacing, m_SnappingNodePos.y + 10); var secondElementModel = CreatePlacemat(new Rect(secondElementPos, new Vector2(k_HalfSpacing, k_HalfSpacing)), "Placemat"); MarkGraphViewStateDirty(); yield return(null); // Get the UI nodes var snappingNode = snappingNodeModel.GetUI <Node>(graphView); Placemat secondElement = secondElementModel.GetUI <Placemat>(graphView); Assert.IsNotNull(snappingNode); Assert.IsNotNull(secondElement); // Changing the node' size to make it easier to test the snapping SetUINodeSize(ref snappingNode, k_HalfSpacing, k_HalfSpacing); yield return(null); Vector2 worldPosSnappingNode = graphView.ContentViewContainer.LocalToWorld(m_SnappingNodePos); Vector2 worldPosSecondElement = graphView.ContentViewContainer.LocalToWorld(secondElementPos); Vector2 selectionPosSnappingNode = worldPosSnappingNode + m_SelectionOffset; Vector2 selectionPosSecondElement = worldPosSecondElement + m_SelectionOffset; // Select placemat by clicking on it and pressing Ctrl helpers.MouseDownEvent(selectionPosSecondElement, MouseButton.LeftMouse, TestEventHelpers.multiSelectModifier); yield return(null); helpers.MouseUpEvent(selectionPosSecondElement, MouseButton.LeftMouse, TestEventHelpers.multiSelectModifier); yield return(null); // Move mouse to Node2 helpers.MouseMoveEvent(selectionPosSecondElement, selectionPosSnappingNode, MouseButton.LeftMouse, TestEventHelpers.multiSelectModifier); yield return(null); // Select Node1 by clicking on it and pressing Ctrl helpers.MouseDownEvent(selectionPosSnappingNode, MouseButton.LeftMouse, TestEventHelpers.multiSelectModifier); yield return(null); // Move Node1 within snapping distance Vector2 moveOffset = new Vector2(10, SnapToGridHelper.GetSnapDistance(snappingNode, SnapToGridHelper.Edge.Top)); Vector2 end = selectionPosSnappingNode + moveOffset; helpers.MouseDragEvent(selectionPosSnappingNode, end, MouseButton.LeftMouse, TestEventHelpers.multiSelectModifier); yield return(null); helpers.MouseUpEvent(end, MouseButton.LeftMouse, TestEventHelpers.multiSelectModifier); yield return(null); // The snapping Node1 top border should snap but X should be dragged normally var borderWidth = SnapToGridStrategy.GetBorderWidth(snappingNode); Assert.AreEqual(GraphViewStaticBridge.RoundToPixelGrid(m_SnappingNodePos.y), snappingNode.layout.y - GraphViewStaticBridge.RoundToPixelGrid(borderWidth.Top)); Assert.AreEqual(GraphViewStaticBridge.RoundToPixelGrid(m_SnappingNodePos.x + moveOffset.x), snappingNode.layout.x); Assert.AreNotEqual(GraphViewStaticBridge.RoundToPixelGrid(m_SnappingNodePos.y + moveOffset.y), snappingNode.layout.y); // placemat should follow the same offset as Node1 Assert.AreEqual(GraphViewStaticBridge.RoundToPixelGrid(secondElementPos.y), secondElement.layout.y - GraphViewStaticBridge.RoundToPixelGrid(borderWidth.Top)); Assert.AreEqual(GraphViewStaticBridge.RoundToPixelGrid(secondElementPos.x + moveOffset.x), secondElement.layout.x); Assert.AreNotEqual(GraphViewStaticBridge.RoundToPixelGrid(secondElementPos.y + moveOffset.y), secondElement.layout.y); yield return(null); }
public IEnumerator ElementUnderMouseShouldSnapWhenMultipleSelectedElements() { // Config // +-------+ // | Node1 | +-------+ // +-------+ | Node2 | +----------+ // +-------+ | Placemat | // +----------+ referenceNode1Model = CreateNode("Node1", k_ReferenceNodePos); m_SnappingNodePos = new Vector2(k_ReferenceNodePos.x + 200, k_ReferenceNodePos.y + 100); snappingNodeModel = CreateNode("Node2", m_SnappingNodePos); // Third element Vector2 secondSelectedElementPos = new Vector2(m_SnappingNodePos.x + 200, m_SnappingNodePos.y + 100); var placematModel = CreatePlacemat(new Rect(secondSelectedElementPos, new Vector2(200, 200)), "Placemat"); MarkGraphViewStateDirty(); yield return(null); Vector2 worldPosNode2 = graphView.ContentViewContainer.LocalToWorld(m_SnappingNodePos); Vector2 worldPosNode3 = graphView.ContentViewContainer.LocalToWorld(secondSelectedElementPos); Vector2 selectionPosNode2 = worldPosNode2 + m_SelectionOffset; Vector2 selectionPosNode3 = worldPosNode3 + m_SelectionOffset; // Select placemat by clicking on it and pressing Ctrl helpers.MouseDownEvent(selectionPosNode3, MouseButton.LeftMouse, TestEventHelpers.multiSelectModifier); yield return(null); helpers.MouseUpEvent(selectionPosNode3, MouseButton.LeftMouse, TestEventHelpers.multiSelectModifier); yield return(null); // Move mouse to Node2 helpers.MouseMoveEvent(selectionPosNode3, selectionPosNode2, MouseButton.LeftMouse, TestEventHelpers.multiSelectModifier); yield return(null); // Select Node2 by clicking on it and pressing Ctrl helpers.MouseDownEvent(selectionPosNode2, MouseButton.LeftMouse, TestEventHelpers.multiSelectModifier); yield return(null); Node node1 = referenceNode1Model.GetUI <Node>(graphView); Node node2 = snappingNodeModel.GetUI <Node>(graphView); Placemat placemat = placematModel.GetUI <Placemat>(graphView); Assert.IsNotNull(node1); Assert.IsNotNull(node2); Assert.IsNotNull(placemat); // Move Node2 toward reference Node1 within the snapping range float topToTopDistance = node2.layout.yMin - node1.layout.yMin; float offSetY = k_SnapDistance - topToTopDistance; Vector2 moveOffset = new Vector2(0, offSetY); Vector2 end = selectionPosNode2 + moveOffset; helpers.MouseDragEvent(selectionPosNode2, end, MouseButton.LeftMouse, TestEventHelpers.multiSelectModifier); yield return(null); helpers.MouseUpEvent(end, MouseButton.LeftMouse, TestEventHelpers.multiSelectModifier); yield return(null); // The snapping Node2 top border should snap to Node1's top border Assert.AreEqual(node1.layout.yMin, node2.layout.yMin); // placemat top border should not snap to Node1's top border Assert.AreNotEqual(node1.layout.yMin, placemat.layout.yMin); // placemat should have moved by the move offset in x and the same y offset as Node2 Assert.AreEqual(secondSelectedElementPos.x + moveOffset.x, placemat.layout.x); Assert.AreEqual(secondSelectedElementPos.y - topToTopDistance, placemat.layout.y); yield return(null); }