Пример #1
0
 private void Reset()
 {
     if (TryGetComponent(out XRController controller))
     {
         m_hand = controller.controllerNode;
     }
 }
Пример #2
0
        public static Quaternion GetLocalRotation(XRNode node)
        {
            Quaternion result;

            InputTracking.GetLocalRotation_Injected(node, out result);
            return(result);
        }
Пример #3
0
        public SinputXRNode(XRNode newNodeType)
        {
            nodeType = newNodeType;

            UpdateJoystickIndeces();

            string vrEnvironmentType = UnityEngine.XR.XRSettings.loadedDeviceName.ToLower();

            if (vrEnvironmentType.Contains("openvr"))
            {
                if (nodeType == XRNode.LeftHand)
                {
                    AddBinding("Trigger", (int)OpenVRButtons.TRIGGER_TOUCH_L);
                }
                if (nodeType == XRNode.RightHand)
                {
                    AddBinding("Trigger", (int)OpenVRButtons.TRIGGER_TOUCH_R);
                }
            }
            if (vrEnvironmentType.Contains("oculus"))
            {
                if (nodeType == XRNode.LeftHand)
                {
                    AddBinding("Trigger", (int)OculusButtons.INDEXTRIGGER_PRIMARY_TOUCH);
                }
                if (nodeType == XRNode.RightHand)
                {
                    AddBinding("Trigger", (int)OculusButtons.INDEXTRIGGER_SECONDARY_TOUCH);
                }
            }
        }
Пример #4
0
        private void TryCheckNodeState(TrackingAnchor anchor, XRNode xRNode)
        {
            XRNodeState xRNodeState = default(XRNodeState);

            for (int i = xRNodeStates.Count - 1; i >= 0; i--)
            {
                var nodeState = xRNodeStates[i];
                if (nodeState.nodeType == xRNode)
                {
                    if (nodeState.uniqueID == anchor.uniqueID)
                    {
                        return;
                    }
                    if (xRNodeState.uniqueID == 0)
                    {
                        xRNodeState = nodeState;
                    }
                    if (!anchor.connected)
                    {
                        InputTracking_nodeAdded(anchor, ref nodeState);
                        return;
                    }
                }
            }

            if (anchor.connected)
            {
                InputTracking_nodeRemoved(anchor);
            }
            if (xRNodeState.uniqueID > 0)
            {
                InputTracking_nodeAdded(anchor, ref xRNodeState);
            }
        }
Пример #5
0
    private void GetValues(XRNode node)
    {
        InputDevice device = InputDevices.GetDeviceAtXRNode(node);

        device.TryGetFeatureValue(CommonUsages.trigger, out trigger);
        device.TryGetFeatureValue(CommonUsages.grip, out grip);
    }
Пример #6
0
        /// <summary>
        /// Allows you to get one device based on the XRNode, usually the XRNode.LeftHand or the
        /// XRNode.RightHand and will return the Pose of the device.  It will return null if the
        /// device could not be found or the tracked position and rotation cannot be obtained.
        /// </summary>
        /// <param name="node">The XRNode of the device to find</param>
        /// <returns>The position and rotation in a Pose of the device.  Null if it cannot be found
        /// or tracked.</returns>
        public Pose?GetDevicePose(XRNode node)
        {
            try
            {
                var device = InputDevices.GetDeviceAtXRNode(node);
                if (!device.isValid)
                {
                    return(null);
                }

                bool positionSuccess = device.TryGetFeatureValue(CommonUsages.devicePosition, out Vector3 position);
                bool rotationSuccess = device.TryGetFeatureValue(CommonUsages.deviceRotation, out Quaternion rotation);
                if (positionSuccess && rotationSuccess)
                {
                    return(new Pose {
                        position = position, rotation = rotation
                    });
                }
                else
                {
                    return(null);
                }
            }
            catch
            {
                AlternativePlay.Logger.Error($"Tracker GetDevicePose Error");
                return(null);
            }
        }
Пример #7
0
        public static Vector3 GetLocalPosition(XRNode node)
        {
            Vector3 result;

            InputTracking.INTERNAL_CALL_GetLocalPosition(node, out result);
            return(result);
        }
Пример #8
0
 public static void DoPulseData(XRNode node, HapticPulseData dat)
 {
     if (dat.type != HapticPulseType.NONE)
     {
         pulseData[(int)node] = dat;
     }
 }
Пример #9
0
 private Matrix4x4 GetEyeProjectionMatrix(Camera cam, XRNode eye)
 {
     //IL_0001: Unknown result type (might be due to invalid IL or missing references)
     //IL_0003: Invalid comparison between Unknown and I4
     //IL_000f: Unknown result type (might be due to invalid IL or missing references)
     return(cam.GetStereoProjectionMatrix(((int)eye == 1) ? 1 : 0));
 }
Пример #10
0
    // In implementations, overwrite this to generate clips
    protected virtual bool GenerateClip(XRNode node, ref byte[] clip)
    {
        HapticCapabilities caps = new HapticCapabilities();

        InputDevice device = InputDevices.GetDeviceAtXRNode(node);

        if (device == null ||
            !device.TryGetHapticCapabilities(out caps)
            )
        {
            return(false);
        }

        // This base implementation generates a very boring clip of solid intensity
        // over the max clip time.
        int clipTime = (int)(caps.bufferFrequencyHz * 2); // 2 seconds

        clip = new byte[clipTime];
        for (int i = 0; i < clipTime; i++)
        {
            clip[i] = byte.MaxValue;
        }

        return(true);
    }
Пример #11
0
 private bool Patch(XRNode node, ref float __result)
 {
     if (node == XRNode.LeftHand && PluginConfig.Instance.LeftSelectRemapEnabled)
     {
         bool pressed = false;
         foreach (var button in PluginConfig.Instance.LeftSelectButtons)
         {
             pressed = pressed || OVRInput.Get(button, OVRInput.Controller.Touch);
         }
         __result = pressed ? 1 : 0;
     }
     else if (node == XRNode.RightHand && PluginConfig.Instance.RightSelectRemapEnabled)
     {
         bool pressed = false;
         foreach (var button in PluginConfig.Instance.RightSelectButtons)
         {
             pressed = pressed || OVRInput.Get(button, OVRInput.Controller.Touch);
         }
         __result = pressed ? 1 : 0;
     }
     else
     {
         return(true); // Let the base method run as is
     }
     return(false);
 }
Пример #12
0
        public override void OnUnInteract(XRNode hand, GameObject handObject = null, AnimationController handAnimation = null, XRNodeHandController handController = null)
        {
            inUse = false;


            rb.isKinematic = false;

            this.transform.SetParent(originalParent);
            InheritVelocity();

            if (currentHandController != null)
            {
                currentHandController.active = true;
            }
            if (currentHandAnimation != null)
            {
                currentHandAnimation.ResetController();
            }
            currentHandAnimation  = null;
            currentHandController = null;
            if (dataReader != null)
            {
                dataReader.active = false;
            }

            OnUnGrab.Invoke();
        }
    //// Utility

    // Given an XRNode, get the current position & rotation. If it's not tracking, don't modify the position & rotation.
    private static bool UpdatePose(XRNode node, ref Vector3 position, ref Quaternion rotation)
    {
        List <XRNodeState> nodeStates = new List <XRNodeState>();

        InputTracking.GetNodeStates(nodeStates);

        foreach (XRNodeState nodeState in nodeStates)
        {
            if (nodeState.nodeType == node)
            {
                Vector3    nodePosition;
                Quaternion nodeRotation;
                bool       gotPosition = nodeState.TryGetPosition(out nodePosition);
                bool       gotRotation = nodeState.TryGetRotation(out nodeRotation);

                if (gotPosition)
                {
                    position = nodePosition;
                }
                if (gotRotation)
                {
                    rotation = nodeRotation;
                }

                return(gotPosition);
            }
        }

        return(false);
    }
        private void GetButtonState(XRNode node)
        {
            switch (node)
            {
            case XRNode.LeftHand:
            {
                InputDevices.GetDeviceAtXRNode(node).TryGetFeatureValue(CommonUsages.primary2DAxisClick, out lPrimary2DButton);
                InputDevices.GetDeviceAtXRNode(node).TryGetFeatureValue(CommonUsages.menuButton, out lMenuButton);
                InputDevices.GetDeviceAtXRNode(node).TryGetFeatureValue(CommonUsages.gripButton, out lGripButton);
                InputDevices.GetDeviceAtXRNode(node).TryGetFeatureValue(CommonUsages.triggerButton, out lTriggerButton);
                InputDevices.GetDeviceAtXRNode(node).TryGetFeatureValue(CommonUsages.primaryButton, out x);
                InputDevices.GetDeviceAtXRNode(node).TryGetFeatureValue(CommonUsages.secondaryButton, out y);
            }
            break;

            case XRNode.RightHand:
            {
                InputDevices.GetDeviceAtXRNode(node).TryGetFeatureValue(CommonUsages.primary2DAxisClick, out rPrimary2DButton);
                InputDevices.GetDeviceAtXRNode(node).TryGetFeatureValue(CommonUsages.menuButton, out rMenuButton);
                InputDevices.GetDeviceAtXRNode(node).TryGetFeatureValue(CommonUsages.gripButton, out rGripButton);
                InputDevices.GetDeviceAtXRNode(node).TryGetFeatureValue(CommonUsages.triggerButton, out rTriggerButton);
                InputDevices.GetDeviceAtXRNode(node).TryGetFeatureValue(CommonUsages.primaryButton, out a);
                InputDevices.GetDeviceAtXRNode(node).TryGetFeatureValue(CommonUsages.secondaryButton, out b);
            }
            break;
            }
        }
Пример #15
0
        public bool TryGetPosition(XRNode node, ref Vector3 position)
        {
            if (IsSimulation == true)
            {
                foreach (var simulatedState in simulatedStates)
                {
                    if (simulatedState.Node == node)
                    {
                        if (simulatedState.Set == false)
                        {
                            return(false);
                        }

                        position = simulatedState.Position;

                        return(true);
                    }
                }
            }
            else
            {
                InputTracking.GetNodeStates(states);

                foreach (var state in states)
                {
                    if (state.nodeType == node)
                    {
                        return(state.TryGetPosition(out position));
                    }
                }
            }

            return(false);
        }
Пример #16
0
        public override void OnInteract(XRNode hand, GameObject handObject = null, AnimationController handAnimation = null, XRNodeHandController handController = null)
        {
            inUse = true;

            currentHandController = handController;
            currentHandAnimation  = handAnimation;

            this.transform.SetParent(handObject.transform.parent);
            rb.isKinematic = true;

            VelocityEstimator estimator = this.GetComponent <VelocityEstimator>();

            if (estimator == null)
            {
                estimator = this.gameObject.AddComponent <VelocityEstimator>();
            }
            estimator.BeginEstimatingVelocity();

            if (dataReader != null)
            {
                dataReader.ApplyData(hand, currentHandAnimation, currentHandController);
            }

            OnGrab.Invoke();
        }
Пример #17
0
        public bool TryGetRotation(XRNode node, ref Quaternion rotation)
        {
            if (IsSimulation == true)
            {
                foreach (var simulatedState in simulatedStates)
                {
                    if (simulatedState.Node == node)
                    {
                        if (simulatedState.Set == false)
                        {
                            return(false);
                        }

                        rotation = simulatedState.Rotation;

                        return(true);
                    }
                }
            }
            else
            {
                InputTracking.GetNodeStates(states);

                foreach (var state in states)
                {
                    if (state.nodeType == node)
                    {
                        return(state.TryGetRotation(out rotation));
                    }
                }
            }

            return(false);
        }
Пример #18
0
        public static Quaternion GetLocalRotation(XRNode node)
        {
            Quaternion result;

            InputTracking.INTERNAL_CALL_GetLocalRotation(node, out result);
            return(result);
        }
Пример #19
0
        internal static void AdjustControllerTransform(
            IVRPlatformHelper platformHelper,
            XRNode node, Transform transform
            )
        {
            if (!Plugin.IsEnabled)
            {
                return;
            }
            if (!IsInGame)
            {
                return;
            }

            switch (node)
            {
            case XRNode.LeftHand:
                transform.Translate(Preferences.LeftTranslation);
                transform.Rotate(Preferences.LeftRotation);
                break;

            case XRNode.RightHand:
                transform.Translate(Preferences.RightTranslation);
                transform.Rotate(Preferences.RightRotation);
                break;
            }
        }
Пример #20
0
        public static Vector3 GetLocalPosition(XRNode node)
        {
            Vector3 result;

            InputTracking.GetLocalPosition_Injected(node, out result);
            return(result);
        }
Пример #21
0
        internal static void OnTrackerDisconnected(TrackingAnchor anchor)
        {
            XRNode xRNode = XRNode.HardwareTracker;

            if (anchor.type == NodeType.Head)
            {
                xRNode = XRNode.Head;
            }
            else if (anchor.type == NodeType.LeftHand)
            {
                xRNode = XRNode.LeftHand;
            }
            else if (anchor.type == NodeType.RightHand)
            {
                xRNode = XRNode.RightHand;
            }
            else if (anchor.type == NodeType.Pelive)
            {
            }
            else if (anchor.type == NodeType.LeftFoot)
            {
            }
            else if (anchor.type == NodeType.RightFoot)
            {
            }
            checkTouchPad();

            onTrackingAnchorDisconnected?.Invoke(xRNode, anchor.name);
            Log($" onTrackerDisconnected... [type = {xRNode},name = {anchor.name}]");
        }
Пример #22
0
        public Controller(
            XRNode node,
            string gameObjectName,
            bool constructScene)
        {
            XRNode = node;

            if (constructScene)
            {
                GameObject = new GameObject(gameObjectName);

                XRITController = GameObject.AddComponent <UnityEngine.XR.Interaction.Toolkit.XRController>();

                XRITController.selectUsage = InputHelpers.Button.Trigger;

                XRITController.controllerNode = node;
            }
            else
            {
                GameObject = GameObject.Find(gameObjectName);

                XRITController = GameObject.GetComponent <UnityEngine.XR.Interaction.Toolkit.XRController>();

                if (XRITController.controllerNode != node)
                {
                    Debug.LogError("Expected " + node + " but found " + XRITController.controllerNode);
                }
            }
        }
 private static void Prefix(XRNode node, Transform transform, ref Vector3 position, ref Vector3 rotation)
 {
     if (!Configuration.Grip.IsGripModEnabled)
     {
         return;
     }
     Utilities.AdjustControllerTransform(node, transform, ref position, ref rotation);
 }
Пример #24
0
 public Recorder(int poseId, XRNode Node, int poseType, Material MaterialRecord, Material MaterialValidate)
 {
     this.Node             = Node;
     this.poseId           = poseId;
     this.poseType         = poseType;
     this.MaterialRecord   = MaterialRecord;
     this.MaterialValidate = MaterialValidate;
 }
Пример #25
0
 public UnityXRDevice(XRNode targetXRNode, int deviceIndex, UnityAction OnDeviceValid, UnityAction OnDeviceInvalid, bool debugLog = false)
 {
     xrNode               = targetXRNode;
     this.deviceIndex     = deviceIndex;
     this.OnDeviceValid   = OnDeviceValid;
     this.OnDeviceInvalid = OnDeviceInvalid;
     this.debugLog        = debugLog;
     Initialize();
 }
Пример #26
0
    public static bool TryGetNodeState(XRNode node, out XRNodeState nodeState)
    {
        List <XRNodeState> nodeStates = new List <XRNodeState>();

        InputTracking.GetNodeStates(nodeStates);
        nodeState = nodeStates.Where(p => p.nodeType == node).FirstOrDefault();

        return(nodeState.tracked);
    }
Пример #27
0
    public static void FlatPulse(XRNode node, float amplitude, float length)
    {
        HapticPulseData dat = new HapticPulseData();

        dat.type             = HapticPulseType.FLAT;
        dat.length           = length;
        dat.amplitude1       = amplitude;
        pulseData[(int)node] = dat;
    }
 static void Prefix(XRNode node, float strength)
 {
     //var stack = new StackTrace(3, false);
     //if (stack.GetFrame(0).GetMethod().DeclaringType.Name == "VRInputModule")
     if (strength == 0.25f)
     {
         PersistentSingleton <MyHapticFeedbackController> .instance.Rumble(node, Plugin.UIClip);
     }
 }
Пример #29
0
        public IEnumerator GazeCheck()
        {
            m_XrNodeStates = new List <XRNodeState>();
            yield return(new WaitForSeconds(kDeviceSetupWait));

            RaycastHit info = new RaycastHit();

            yield return(null);

            InputTracking.GetNodeStates(m_XrNodeStates);

            foreach (XRNodeState node in m_XrNodeStates)
            {
                if (node.nodeType == XRNode.Head)
                {
                    m_Head = node.nodeType;
                    node.TryGetPosition(out m_XrHeadNodePos);
                }
            }

            InputTracking.Recenter();

            yield return(null);

            if (m_Cube != null)
            {
                m_Cube.transform.position = new Vector3(m_XrHeadNodePos.x, m_XrHeadNodePos.y, m_XrHeadNodePos.z + 2f);
            }
            else if (m_Cube == null)
            {
                m_TestSetupHelpers.TestCubeSetup(TestCubesConfig.TestCube);
                m_Cube.transform.position = new Vector3(m_XrHeadNodePos.x, m_XrHeadNodePos.y, m_XrHeadNodePos.z + 2f);
            }


            yield return(new WaitForSeconds(2f));

            if (Physics.Raycast(m_XrHeadNodePos, m_Camera.GetComponent <Camera>().transform.forward, out info, 10f))
            {
                yield return(new WaitForSeconds(0.05f));

                if (info.collider.name == m_Cube.name)
                {
                    m_RaycastHit = true;
                }
            }

            if (m_Cube != null)
            {
                GameObject.Destroy(m_Cube);
            }

            if (Application.platform != RuntimePlatform.IPhonePlayer)
            {
                Assert.IsTrue(m_RaycastHit, "Gaze check failed to hit something!");
            }
        }
Пример #30
0
    public static void LerpPulse(XRNode node, float startAmplitude, float endAmplitude, float length)
    {
        HapticPulseData dat = new HapticPulseData();

        dat.type             = HapticPulseType.LERP;
        dat.amplitude1       = startAmplitude;
        dat.amplitude2       = endAmplitude;
        dat.length           = length;
        pulseData[(int)node] = dat;
    }