public override List <Vector3> HandleColliderInteracted(DPInteractor interactor, List <Vector2> interactionPoints) { if (interactionPoints.Count <= 0) { return(new List <Vector3>()); } Vector2 point = interactionPoints.FirstOrDefault(); if (mouseInteractor == null) { mouseInteractor = interactor; } if (mouseInteractor != interactor) { return(null); } float xPos, yPos; point.x = Maths.Linear(point.x, textureBounds.x, textureBounds.z, 0f, 1f); point.y = Maths.Linear(1f - point.y, textureBounds.y, textureBounds.w, 0f, 1f); if (isTargetingWindow) { xPos = (window.rawWidth * point.x) + window.rawX; //float fixedY = 1f - point.y; yPos = (window.rawHeight * point.y) + window.rawY; } else { xPos = (monitor.width * point.x) + monitor.left; //float fixedY = 1f - point.y; yPos = (monitor.height * point.y) + monitor.top; } HandleMouseMove(new Vector2(xPos, yPos)); return(new List <Vector3>() { point }); }
public void HandleScrollEvent(DPInteractor interactor, float delta) { uint newDelta = 0; if (delta > DPSettings.config.joystickDeadzone || delta < -DPSettings.config.joystickDeadzone) { //newDelta = (int) (delta * 0.3f * Time.deltaTime * 144f); newDelta = (uint)(delta * 120 * Time.deltaTime * 10); //if (isTargetingWindow) CursorInteraction.CursorSendInput(window.handle, CursorInteraction.SimulationMode.ScrollV, mousePoint, newDelta); WinNative.mouse_event(0x0800, 0, 0, newDelta, 0); } }
/* * public override void OnOpen() { * base.OnOpen(); * * * if (!windowsLoaded) return; * StartCoroutine(BuildWindowList(false)); * * } */ public void HandleScrollEvent(DPInteractor interactor, float delta) { //if (!dpApp.dpMain) return; if (!windowsLoaded) { return; } float curX = _windowsLayoutGroup.padding.top; if (delta < -0.1f) { _windowsLayoutGroup.padding.top -= (int)(scrollSpeedMultiplier * Time.deltaTime); //Figure out how far down user is allowed to scroll: //int maxScroll = (gamesList.Count / 7) * 400; //if (_gamesListGroup.padding.top <= -maxScroll) _gamesListGroup.padding.top = -maxScroll; LayoutRebuilder.MarkLayoutForRebuild(_windowsRectTransform); } else if (delta > 0.1f) { _windowsLayoutGroup.padding.top += (int)(scrollSpeedMultiplier * Time.deltaTime); //if (_gamesListGroup.padding.top >= gamesGridInitialYOffset) _gamesListGroup.padding.top = (int)gamesGridInitialYOffset; if (_windowsLayoutGroup.padding.top >= 0) { _windowsLayoutGroup.padding.top = 0; } LayoutRebuilder.MarkLayoutForRebuild(_windowsRectTransform); } }
public override List <Vector3> HandleColliderInteracted(DPInteractor interactor, List <Vector2> interactionPoints) { throw new NotImplementedException(); }
public void CheckForMouseClick(DPInteractor interactor, float triggerStrength) { //float triggerStrength = 0.0f; //_unitySteamVrHandler.handTriggerStrengths[activeControllerIndex]; //Debug.Log(triggerStrength); if (isClicking && !hasClicked) { mouseClickHoldTime += Time.deltaTime; } //Haptics //if (!triggeredRightClickHaptics && potentialClick && mouseClickHoldTime > rightClickHoldThreshold) { // //HapticsManager.SendHaptics(activeControllerIndex, 1, 0.7f); // triggeredRightClickHaptics = true; //} if (!isClicking && triggerStrength > triggerStartClickThreshold) { isClicking = true; startClickPos = mousePos; } if (isClicking && !hasClicked && triggerStrength > triggerDoClickThreshold) { potentialClick = true; } //Drag click if (!isDragging && !hasClicked && potentialClick) { isDragging = true; //Move the mouse back to the origin of the click: Point startPoint = new Point((int)startClickPos.x, (int)startClickPos.y); WinNative.SetCursorPos(startPoint.X, startPoint.Y); //WinNative.mouse_event(WinMouseEvents.WM_MOUSEMOVE); //Debug.Log("starting touch drag"); //left down at the origin //CursorInteraction.CursorSendInput(window.handle, // CursorInteraction.SimulationMode.LeftDown); if (useTouchInput) { TouchInject.BeginDragging(startPoint); } else { inputSimulator.Mouse.LeftButtonDown(); } onClickedOn?.Invoke(this); //Move back to where the user had the mouse //CursorInteraction.SetCursorPos(mousePoint.X, mousePoint.Y); } if (isDragging) { //Debug.Log(mousePoint.X); if (useTouchInput) { TouchInject.AddToActiveDrag(mousePoint); } } //End drag click if (isDragging && triggerStrength <= 0.1f) { /*CursorInteraction.CursorSendInput(window.handle, * CursorInteraction.SimulationMode.LeftUp, new Point(), * 0); * EndMouseClick();*/ //Debug.Log("ending drag"); //if (useTouchInput) { TouchInject.EndActiveDrag(); //} //else { inputSimulator.Mouse.LeftButtonUp(); //} EndMouseClick(); } //Right click (we have to check this first to see the mouse hold time) /*if (!isDragging && !hasClicked && potentialClick && * triggerStrength <= (triggerDoClickThreshold - triggerBackToClickThreshold) && * mouseClickHoldTime > rightClickHoldThreshold) { * CursorInteraction.CursorSendInput(selectedDPWindowOverlay.window.handle, * CursorInteraction.SimulationMode.RightClick, * new Point((int) curMousePos.x, (int) curMousePos.y), 0); * * hasClicked = true; * }*/ //Left click /*else if (!isDragging && !hasClicked && potentialClick && * triggerStrength <= (triggerDoClickThreshold - triggerBackToClickThreshold)) { * CursorInteraction.CursorSendInput(window.handle, CursorInteraction.SimulationMode.LeftClick, new Point(), 0); * * hasClicked = true; * }*/ //Allows to click again once the trigger is back below the inital threshold if (isClicking && triggerStrength <= triggerStartClickThreshold) { EndMouseClick(); } //TODO: clear click state when active controller changed }
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 }); }