public GraphEditor(int width, int height) { InitializeComponent(); this.Size = new Size(width, height); nodeLayer = this.Layer; edgeLayer = new PLayer(); Root.AddChild(edgeLayer); this.Camera.AddLayer(0, edgeLayer); backLayer = new PLayer(); Root.AddChild(backLayer); backLayer.MoveToBack(); this.Camera.AddLayer(1, backLayer); dragHandler = new NodeDragHandler(); nodeLayer.AddInputEventListener(dragHandler); zoomController = new ZoomController(this); }
public void Update() { if (Input.GetMouseButtonDown(0)) { if (EventSystem.current.currentSelectedGameObject == gameObject) { if (copyOnDrag) { Node intendedCopy = toDrag.GetComponentInParent <NodeController> ().node; if (intendedCopy is Always && Always.StartPoint != null) { return; // Uh, no threading! } dragging = Instantiate <GameObject> (toDrag.gameObject).GetComponentInChildren <NodeDragHandler> (); dragging.copyOnDrag = false; NodeController nodeController = dragging.GetComponentInParent <NodeController> (); nodeController.IsInGraph = true; SFXPlayer.PlaySound("PickupNode"); } else { // TODO: box select? dragging = this; } initialClickLocation = Input.mousePosition; clickDisplacement = transform.position - initialClickLocation; canvasGroup.blocksRaycasts = false; dragging.canvasGroup.blocksRaycasts = false; dragging.toDrag.SetParent(dragParent); } } if (Input.GetMouseButtonUp(0) && dragging != null) { if (EventSystem.current.currentSelectedGameObject == gameObject) { canvasGroup.blocksRaycasts = true; dragging.canvasGroup.blocksRaycasts = true; if (DirectScroll.BlockNodeDrop) { Destroy(dragging.toDrag.gameObject); SFXPlayer.PlaySound("DestroyNode"); } else { dragging.toDrag.SetParent(finalParent, true); SFXPlayer.PlaySound("PlaceNode"); } Vector3 totalDisplacement = Input.mousePosition - initialClickLocation; if (totalDisplacement.sqrMagnitude < CLICK_GATE_SQR_RADIUS) { dragging.GetComponentInParent <NodeController> ().node.OnClicked(); } dragging = null; } } if (Input.GetMouseButton(0) && dragging != null) { if (EventSystem.current.currentSelectedGameObject == gameObject) { dragging.toDrag.position = Input.mousePosition + clickDisplacement; } } }