void UpdateUnityMouseSim(UnityUIDPHandlerData data) { var pd = data.uiHandler.pD; pd.position = data.mousePos; pd.button = PointerEventData.InputButton.Left; pd.scrollDelta = data.scrollStrength; if (data.mouseDown && !data.mouseDragging && !data.hasClicked) { pd.Reset(); pd.clickCount = 1; } else if (data.mouseDown && data.mouseDragging) { pd.clickCount = 0; pd.clickTime = data.mouseDownTime; pd.dragging = true; } HashSet <Selectable> nTargs = data.uiHandler.GetUITargets(data.graphicRaycaster, pd); if (nTargs == null) { return; } data.uiHandler.EnterTargets(nTargs); if (!Mathf.Approximately(pd.scrollDelta.sqrMagnitude, 0.0f)) { var scrollHandler = ExecuteEvents.GetEventHandler <IScrollHandler>(pd.pointerCurrentRaycast.gameObject); ExecuteEvents.ExecuteHierarchy(scrollHandler, pd, ExecuteEvents.scrollHandler); } //_uiHandler.ScrollTargets(nTargs); foreach (Selectable ub in nTargs) { if (data.enterTargets.Contains(ub)) { data.enterTargets.Remove(ub); } } data.enterTargets.RemoveWhere(x => x == null); data.downTargets.RemoveWhere(x => x == null); data.uiHandler.ExitTargets(data.enterTargets); data.enterTargets = nTargs; if (data.mouseDown) { if (!data.mouseDragging && !data.hasClicked) { foreach (Selectable sel in nTargs) { data.downTargets.Add(sel); } data.uiHandler.SubmitTargets(data.downTargets); data.uiHandler.StartDragTargets(data.downTargets); data.uiHandler.DownTargets(data.downTargets); data.hasClicked = true; } else if (data.mouseDragging) { data.uiHandler.MoveTargets(data.downTargets); data.uiHandler.DragTargets(data.downTargets); data.uiHandler.DownTargets(data.downTargets); } } else { data.uiHandler.UpTargets(data.downTargets); data.uiHandler.EndDragTargets(data.downTargets); data.uiHandler.DropTargets(data.downTargets); data.downTargets.Clear(); } }
public override List <Vector3> HandleColliderInteracted(DPInteractor interactor, List <Vector2> interactionPoints) { if (interactionPoints.Count <= 0) { return(null); } Vector2 point = interactionPoints.FirstOrDefault(); //offset it so all positive values //Vector2 posPoint = new Vector2(point.x + overlay.width / 2f, point.y + overlayHeight / 2f); //negPoint.x -= negPoint.x * 0.05f; //Convert to be 0-1 //Vector2 fixedPoint = new Vector2((posPoint.x / overlay.width), posPoint.y / overlayHeight); //Flip the y axis point.y = (point.y * -1f) + 1; //Check if this interactor has been already added if (!interactionsData.ContainsKey(interactor)) { interactionsData[interactor] = new UnityUIDPHandlerData(); if (interactionsData.Count <= 1) { interactionsData[interactor].graphicRaycaster = canvas.gameObject.GetComponent <GraphicRaycaster>(); } //Add the raycaster else { interactionsData[interactor].graphicRaycaster = canvas.gameObject.AddComponent <GraphicRaycaster>(); } } UnityUIDPHandlerData data = interactionsData[interactor]; //Set the pos: data.mousePos = new Vector2(_cameraTexture.width * point.x, _cameraTexture.height * point.y); //Mouse pos and clicking if (data.mouseDown) { data.mouseDownTime += Time.deltaTime; } if (data.mouseDown && IsMouseOutsideDragDist(data.mouseDownPos, data.mousePos)) { data.mouseDragging = true; } if (data.overlayMouseLeftDown && !data.mouseDown) { data.mouseDown = true; data.mouseDownPos = data.mousePos; } if (data.mouseDown && !data.overlayMouseLeftDown) { data.mouseDown = false; data.mouseDragging = false; data.mouseDownTime = 0f; data.hasClicked = false; } UpdateUnityMouseSim(data); return(new List <Vector3>() { point }); }