コード例 #1
0
        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);
        }
コード例 #2
0
        public bool Grabbed(ControllerInteractionPoint interactionPoint)
        {
            if (attachedInteractionPoint != null)
            {
                return(false);
            }
            // Don't allow joystick use when editing is unlocked, so the movable surface can be used instead
            if (!controller.editLocked)
            {
                return(false);
            }

            attachedInteractionPoint = interactionPoint;

            rotationZeroPoint.rotation = attachedInteractionPoint.transform.rotation;
            rotationZeroPoint.position = attachedInteractionPoint.transform.position;
            rotationPoint.rotation     = attachedInteractionPoint.transform.rotation;
            translationPoint.position  = attachedInteractionPoint.transform.position;

            // Is the controller being held upright light a joystick, or forward like the ship
            upright = Vector3.Angle(Vector3.up, rotationPoint.transform.forward) < 40f;

            if (buttons)
            {
                buttons.Grabbed(interactionPoint.Hand);
            }

            return(true);
        }
コード例 #3
0
        public bool Grabbed(ControllerInteractionPoint interactionPoint)
        {
            if (attachedInteractionPoint != null)
            {
                return(false);
            }
            // Don't allow throttle use when editing is unlocked, so the movable surface can be used instead
            if (!controller.editLocked)
            {
                return(false);
            }

            attachedInteractionPoint = interactionPoint;

            var attachPointObject = new GameObject("[AttachPoint]");

            attachPointObject.transform.SetParent(attachedInteractionPoint.transform);
            attachPointObject.transform.SetPositionAndRotation(handle.position, handle.rotation);
            attachPoint = attachPointObject.transform;

            if (buttons)
            {
                buttons.Grabbed(interactionPoint.Hand == TrackedHand.Hand.Right ? ActionsController.Hand.Right : ActionsController.Hand.Left);
            }

            return(true);
        }
コード例 #4
0
 public void Ungrabbed(ControllerInteractionPoint interactionPoint)
 {
     if (interactionPoint == attachedInteractionPoint)
     {
         attachedInteractionPoint = null;
         Destroy(attachPoint.gameObject);
         attachPoint = null;
     }
 }
コード例 #5
0
        public void Activate(ControllerInteractionPoint interactionPoint)
        {
            Vector2 clickPoint = CalculateCursorPoint(interactionPoint.transform.position);

            if (destination)
            {
                destination.Click(clickPoint);
            }
        }
コード例 #6
0
        public Action Activate(ControllerInteractionPoint interactionPoint)
        {
            var handle = new CoroutineHandle();

            StartCoroutine(InteractionLoop(interactionPoint, handle));

            return(() =>
            {
                handle.Stop();
            });
        }
コード例 #7
0
        public void Unhover(ControllerInteractionPoint interactionPoint)
        {
            if (hoveringRoutines.ContainsKey(interactionPoint))
            {
                StopCoroutine(hoveringRoutines[interactionPoint]);
                hoveringRoutines.Remove(interactionPoint);
            }

            if (destination)
            {
                destination.Hover();
            }
        }
コード例 #8
0
        public Action Activate(ControllerInteractionPoint interactionPoint)
        {
            Vector2 clickPoint = CalculateCursorPoint(interactionPoint.transform.position);

            if (destination)
            {
                destination.Click(clickPoint);
            }

            // Return a noop since all we care about for now is clicks
            // We could change this later if we want to implement draggable UI
            return(() => { });
        }
コード例 #9
0
        public Action Activate(ControllerInteractionPoint interactionPoint)
        {
            // @fixme Activations end when the controller leaves
            // we probably actyally want it to continue until released
            // So we'll need some way to tell the interaction point to not auto-release
            var handle = new CoroutineHandle();

            StartCoroutine(InteractionLoop(interactionPoint, handle));

            return(() =>
            {
                handle.Stop();
            });
        }
コード例 #10
0
        public void Ungrabbed(ControllerInteractionPoint interactionPoint)
        {
            if (interactionPoint == attachedInteractionPoint)
            {
                attachedInteractionPoint = null;

                if (buttons)
                {
                    buttons.Ungrabbed();
                }

                vJoyInterface.instance?.SetStickAxis(StickAxis.Zero);
            }
        }
コード例 #11
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);
            }
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        public IEnumerator Hovering(ControllerInteractionPoint interactionPoint)
        {
            Vector2 cursorPoint;

            while (enabled)
            {
                cursorPoint = CalculateCursorPoint(interactionPoint.transform.position);

                if (destination)
                {
                    destination.Hover(cursorPoint);
                }

                yield return(null);
            }
        }
コード例 #14
0
        public void Ungrabbed(ControllerInteractionPoint interactionPoint)
        {
            if (interactionPoint == attachedInteractionPoint)
            {
                attachedInteractionPoint = null;

                if (buttons)
                {
                    buttons.Ungrabbed();
                }

                if (line)
                {
                    line.SetPosition(1, Vector3.zero);
                }
                if (marker)
                {
                    marker.gameObject.SetActive(false);
                    marker.transform.localPosition = Vector3.zero;
                    var euler = marker.transform.localEulerAngles;
                    euler.y = 0;
                    marker.transform.localEulerAngles = euler;
                }
                if (verticalDisplay)
                {
                    verticalDisplay.transform.localPosition = Vector3.zero;
                }
                if (verticalLine)
                {
                    verticalLine.transform.localPosition = Vector3.zero;
                    verticalLine.SetPosition(1, Vector3.zero);
                }
                if (rollMarker)
                {
                    rollMarker.gameObject.SetActive(false);
                    rollMarker.transform.localPosition    = Vector3.zero;
                    rollMarker.transform.localEulerAngles = Vector3.zero;
                }

                var output = vJoyInterface.instance;
                if (output)
                {
                    output.SetThrusters(ThrusterAxis.Zero);
                    output.SetStickAxis(StickAxis.Zero);
                }
            }
        }
コード例 #15
0
        public Action Activate(ControllerInteractionPoint interactionPoint)
        {
            if (currentPressingInteractionPoint)
            {
                return () => { }
            }
            ;

            currentPressingInteractionPoint = interactionPoint;
            var unpress = Activate();

            return(() =>
            {
                currentPressingInteractionPoint = null;
                unpress();
            });
        }
コード例 #16
0
        public void Ungrabbed(ControllerInteractionPoint interactionPoint)
        {
            if (interactionPoint == attachedInteractionPoint)
            {
                attachedInteractionPoint = null;

                if (buttons)
                {
                    buttons.Ungrabbed();
                }

                if (output)
                {
                    output.SetStickAxis(StickAxis.Zero);
                }
            }
        }
コード例 #17
0
        public Action Activate(ControllerInteractionPoint interactionPoint)
        {
            if (!mapHorizontalPlaneController.Reserve())
            {
                return () => { }
            }
            ;

            var handle = new CoroutineHandle();

            StartCoroutine(InteractionLoop(interactionPoint, handle));

            return(() =>
            {
                handle.Stop();
                mapHorizontalPlaneController.Release();
            });
        }
コード例 #18
0
        public bool Grabbed(ControllerInteractionPoint interactionPoint)
        {
            if (attachedInteractionPoint != null)
            {
                return(false);
            }
            if (controller.editLocked)
            {
                return(false);
            }

            attachedInteractionPoint = interactionPoint;

            var attachPointObject = new GameObject("[AttachPoint]");

            attachPointObject.transform.SetParent(attachedInteractionPoint.transform);
            attachPointObject.transform.SetPositionAndRotation(transform.position, transform.rotation);
            attachPoint = attachPointObject.transform;

            return(true);
        }
コード例 #19
0
        public bool Grabbed(ControllerInteractionPoint interactionPoint)
        {
            if (attachedInteractionPoint != null)
            {
                return(false);
            }
            // Don't allow joystick use when editing is unlocked, so the movable surface can be used instead
            if (!controller.editLocked)
            {
                return(false);
            }

            attachedInteractionPoint = interactionPoint;

            zeroPoint.rotation     = attachedInteractionPoint.transform.rotation;
            rotationPoint.rotation = attachedInteractionPoint.transform.rotation;

            if (buttons)
            {
                buttons.Grabbed(interactionPoint.Hand == TrackedHand.Hand.Right ? ActionsController.Hand.Right : ActionsController.Hand.Left);
            }

            return(true);
        }
コード例 #20
0
 public void Activate(ControllerInteractionPoint interactionPoint)
 {
     Activate();
 }
コード例 #21
0
 public void Hover(ControllerInteractionPoint interactionPoint)
 {
     hoveringRoutines.Add(interactionPoint, StartCoroutine(Hovering(interactionPoint)));
 }