protected IEnumerator InteractionLoop(ControllerInteractionPoint interactionPoint, CoroutineHandle handle) { while (handle.Running) { var pos = transform.InverseTransformPoint(interactionPoint.transform.position); var zoomScale = pos.x / axisMaxDistance; // Clamp values to the -/+1 range zoomScale = Mathf.Clamp(zoomScale, -1, 1); mapPlaneController.SetZoom(zoomScale); yield return(null); } mapPlaneController.SetZoom(0); }
protected IEnumerator InteractionLoop(ControllerInteractionPoint interactionPoint, CoroutineHandle handle) { var sizeMagnitude = GetMagnitude(barRegion.rect.size); var pivot = GetMagnitude(barRegion.pivot); float PointToMagnitude(Vector3 pos) { var magnitude = (sizeMagnitude * pivot) + GetMagnitude(pos); // Scale to 0-1 values, with unclamped values <0,>1 return(magnitude / sizeMagnitude); } var lastAbsScale = PointToMagnitude(barRegion.InverseTransformPoint(interactionPoint.transform.position)); yield return(null); var lastSensorZoom = sensorZoom; while (handle.Running) { var absScale = PointToMagnitude(barRegion.InverseTransformPoint(interactionPoint.transform.position)); var delta = absScale - lastAbsScale; // Clamp sensor zoom scale to the -/+1 range sensorZoom = Mathf.Clamp(sensorZoom + delta * 2, -1, 1); // Set vJoy axis output.SetSensorZoom(sensorZoom); // Move the bar and re-render the overlay on-demand when the bar has been moved a notable distance var updateScale = 0.01f; var sensorZoomDelta = sensorZoom - lastSensorZoom; if (Math.Abs(sensorZoomDelta) > updateScale) { var roundedSensorZoom = Mathf.Round(sensorZoom / updateScale) * updateScale; var barMag = ((roundedSensorZoom / 2f + 0.5f) - pivot) * sizeMagnitude; barMid.anchoredPosition = SetMagnitude2(barMid.anchoredPosition, barMag); lastSensorZoom = sensorZoom; OnDemandRenderer.SafeDirty(gameObject); } lastAbsScale = absScale; yield return(null); } }
protected IEnumerator InteractionLoop(ControllerInteractionPoint interactionPoint, CoroutineHandle handle) { while (handle.Running) { Vector2 axis; var pos = transform.InverseTransformPoint(interactionPoint.transform.position); var axisPos = new Vector2(pos.x, pos.y); if (axisPos.magnitude < centerRadius) { axis = Vector2.zero; } else { // Subtract the center radius from the magnitute axisPos = axisPos.normalized * (axisPos.magnitude - centerRadius); // Divide by the size of the usable axis area to get an axis value float x = (axisRadius - centerRadius); axis = axisPos / x; // Clamp values to the -/+1 range axis.x = Mathf.Clamp(axis.x, -1, 1); axis.y = Mathf.Clamp(axis.y, -1, 1); } mapHorizontalPlaneController.SetAxis(axis); yield return(null); } mapHorizontalPlaneController.SetAxis(Vector2.zero); }