コード例 #1
0
ファイル: HandTouchAxis.cs プロジェクト: nan023062/navevr
        internal override void UpdateState(TrackingAnchor xRNodeUsage)
        {
            HandAnchor handUsage = xRNodeUsage as HandAnchor;

            mTouched = handUsage.primary2DAxisTouch;

            mVec2Value = Vector2.zero;
            mKeyForce  = 0f;
            if (mTouched)
            {
                mVec2Value = handUsage.primary2DAxis;
                mKeyForce  = 0.1f;
            }

            bool lastPressed = mPressed;

            mPressed = handUsage.primary2DAxisPressed;
            if (mPressed)
            {
                mKeyForce = 1f;
            }

            mBoolDown = !lastPressed && mPressed;
            mBoolUp   = lastPressed && !mPressed;
        }
コード例 #2
0
ファイル: TrackingEvnBase.cs プロジェクト: nan023062/navevr
        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);
            }
        }
コード例 #3
0
ファイル: InputDevices.cs プロジェクト: nan023062/navevr
        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}]");
        }
コード例 #4
0
ファイル: TrackingEvnBase.cs プロジェクト: nan023062/navevr
 private void InputTracking_nodeRemoved(TrackingAnchor anchor)
 {
     if (anchor == null || !anchor.connected)
     {
         return;
     }
     InputDevices.OnTrackerDisconnected(anchor);
     anchor.Disconnect();
 }
コード例 #5
0
ファイル: HandTouchButton.cs プロジェクト: nan023062/navevr
        internal override void UpdateState(TrackingAnchor xRNodeUsage)
        {
            HandAnchor handUsage = xRNodeUsage as HandAnchor;

            mTouched  = handUsage.primary2DAxisTouch;
            mKeyForce = 0f;
            bool lastPressed = mPressed;

            mPressed = false;

            if (mTouched)
            {
                Vector2 axis = handUsage.primary2DAxis;

                mTouched = false;
                m_Degree = 0f;
                bool bInCenter = inCenter(axis);
                if (keyCode == InputKey.Middle)
                {
                    mTouched = bInCenter;
                }
                else if (!bInCenter && keyCode == InputKey.North)
                {
                    m_Degree = angleToNorth(axis);
                    mTouched = m_Degree < degree45;
                }
                else if (!bInCenter && keyCode == InputKey.South)
                {
                    m_Degree = angleToSouth(axis);
                    mTouched = m_Degree < degree45;
                }
                else if (!bInCenter && keyCode == InputKey.West)
                {
                    m_Degree = angleToWest(axis);
                    mTouched = m_Degree < degree45;
                }
                else if (!bInCenter && keyCode == InputKey.East)
                {
                    m_Degree = angleToEast(axis);
                    mTouched = m_Degree < degree45;
                }

                if (mTouched)
                {
                    if (keyCode == InputKey.Middle || InputDevices.isTouchPad)
                    {
                        mPressed = handUsage.primary2DAxisPressed;
                    }
                    else
                    {
                        mPressed = axis.sqrMagnitude >= touchPressSqr;
                    }
                }
            }
            mBoolDown = !lastPressed && mPressed;
            mBoolUp   = lastPressed && !mPressed;
        }
コード例 #6
0
ファイル: Hardwares.cs プロジェクト: nan023062/navevr
        public void DestroyHardware(TrackingAnchor acnhor)
        {
            Hardware hardware = acnhor.hardware;

            if (hardware != null)
            {
                GameObject.Destroy(hardware);
            }
        }
コード例 #7
0
        internal override void UpdateState(TrackingAnchor input)
        {
            HandAnchor hand = input as HandAnchor;

            poseChanged = hand.handPoseChanged;
            if (poseChanged)
            {
                Array.Copy(hand.fingerCurls, handPose_Value, handPose_Value.Length);
            }
        }
コード例 #8
0
        internal void Connected(TrackingAnchor metadata)
        {
            m_UniqueId = metadata.uniqueID;

            m_DeviceName = metadata.name;

            InputDevices.Log($"{name} Connected : nodeType={NodeType},id={m_UniqueId},device={m_DeviceName}!");

            OnDeviceConnected();
        }
コード例 #9
0
ファイル: Hardwares.cs プロジェクト: nan023062/navevr
        public Hardware CreateHardware(TrackingAnchor anchor)
        {
            string   deviceName = InputDevices.deviceName;
            Hardware hardware   = anchor.hardware;

#if UNITY_EDITOR
            if (test != null)
            {
                if (hardware)
                {
                    GameObject.Destroy(hardware);
                }
                hardware = GameObject.Instantiate(test, anchor.transform);
                hardware.transform.localPosition = Vector3.zero;
                hardware.transform.localRotation = Quaternion.identity;
                hardware.SetNodeType(anchor.type);
                return(hardware);
            }
#endif

            if (hardware != null)
            {
                if (hardware.TryMatchName(deviceName))
                {
                    return(hardware);
                }
                else
                {
                    GameObject.Destroy(hardware);
                }
                hardware = null;
            }

            Hardware __prefab = null;
            foreach (var prefab in hardwarePrefabs)
            {
                if (prefab.TryMatchName(deviceName))
                {
                    __prefab = prefab;
                    break;
                }
            }

            if (__prefab == null)
            {
                Debug.LogError("ShowHardware() 没有找到匹配的设备!!!就默认使用第一个配置");
                __prefab = hardwarePrefabs[0];
            }

            hardware = GameObject.Instantiate(__prefab, anchor.transform);
            hardware.transform.localPosition = Vector3.zero;
            hardware.transform.localRotation = Quaternion.identity;
            hardware.SetNodeType(anchor.type);
            return(hardware);
        }
コード例 #10
0
ファイル: TrackingEvnBase.cs プロジェクト: nan023062/navevr
        private void InputTracking_nodeAdded(TrackingAnchor anchor, ref XRNodeState xRNodeState)
        {
            if (anchor == null || anchor.connected)
            {
                return;
            }
            InputDevice inputDevice = U3DInputDevices.GetDeviceAtXRNode(xRNodeState.nodeType);

            anchor.Connected(xRNodeState.uniqueID, inputDevice.name);
            InputDevices.OnTrackerConnected(anchor);
        }
コード例 #11
0
        //当前按钮还未实现。
        internal override void UpdateState(TrackingAnchor xRNodeUsage)
        {
            HandAnchor handUsage = xRNodeUsage as HandAnchor;

            bool lastPressed = mPressed;

            mPressed  = handUsage.systemPressed;
            mBoolDown = !lastPressed && mPressed;
            mBoolUp   = lastPressed && !mPressed;

            mKeyForce = handUsage.systemTouchValue;
            mTouched  = isTouched(mKeyForce);
        }
コード例 #12
0
ファイル: HandGrip.cs プロジェクト: nan023062/navevr
        internal override void UpdateState(TrackingAnchor xRNodeUsage)
        {
            HandAnchor handUsage = xRNodeUsage as HandAnchor;

            bool  lastPressed = mPressed;
            float lastForce   = mKeyForce;

            mKeyForce = handUsage.gripTouchValue;
            mTouched  = isTouched(mKeyForce);

            mPressed  = OptimizPressByKeyForce(lastForce, mKeyForce, 0.01f, 0.2f, 0.6f);
            mBoolDown = !lastPressed && mPressed;
            mBoolUp   = lastPressed && !mPressed;
        }
コード例 #13
0
ファイル: HandTrigger.cs プロジェクト: nan023062/navevr
        internal override void UpdateState(TrackingAnchor xRNodeUsage)
        {
            bool  lastPressed = mPressed;
            float lastForce   = mKeyForce;

            HandAnchor handUsage = xRNodeUsage as HandAnchor;

            mKeyForce = handUsage.triggerTouchValue;
            mTouched  = isTouched(mKeyForce);

            //这里不使用UnityXR的按钮状态,因为会有感官上的延迟
            //device.TryGetFeatureValue(CommonUsages.triggerButton, out mPressed);
            mPressed  = OptimizPressByKeyForce(lastForce, mKeyForce, 0.01f, 0.2f, 0.6f);
            mBoolDown = !lastPressed && mPressed;
            mBoolUp   = lastPressed && !mPressed;
        }
コード例 #14
0
ファイル: TrackingEvnBase.cs プロジェクト: nan023062/navevr
        private void TryCheckTrackNodeState(TrackingAnchor anchor, XRNode xRNode)
        {
            XRNodeState xRNodeState = default(XRNodeState);
            var         pelvis      = InputDevices.pelivsAnchor;
            var         lfoot       = InputDevices.leftFootAnchor;
            var         rfoot       = InputDevices.rightFootAnchor;

            for (int i = xRNodeStates.Count - 1; i >= 0; i--)
            {
                var   nodeState = xRNodeStates[i];
                ulong uniqueID  = nodeState.uniqueID;
                if (nodeState.nodeType == xRNode)
                {
                    if (nodeState.uniqueID == anchor.uniqueID)
                    {
                        return;
                    }

                    if ((pelvis.connected && uniqueID == pelvis.uniqueID) ||
                        (lfoot.connected && uniqueID == lfoot.uniqueID) ||
                        (rfoot.connected && uniqueID == rfoot.uniqueID))
                    {
                        continue;
                    }

                    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);
            }
        }
コード例 #15
0
ファイル: TrackingSpace.cs プロジェクト: nan023062/navevr
        private void OnDrawGizmos()
        {
            if (mesh == null)
            {
                mesh          = new Mesh();
                mesh.vertices = new Vector3[] {
                    new Vector3(-1, -1, -1),
                    new Vector3(1, -1, -1),
                    new Vector3(-1, 1, -1),
                    new Vector3(1, 1, -1),
                    new Vector3(-1, -1, 1),
                    new Vector3(1, -1, 1),
                    new Vector3(-1, 1, 1),
                    new Vector3(1, 1, 1),
                };
                mesh.triangles = new int[] {
                    0, 2, 3, 0, 3, 1,
                    1, 3, 7, 1, 7, 5,
                    4, 6, 2, 4, 2, 0,
                    4, 0, 1, 4, 1, 5,
                    2, 6, 7, 2, 7, 3,
                    6, 4, 5, 6, 5, 7
                };
                mesh.RecalculateNormals();
            }

            TrackingAnchor[] anchors = new TrackingAnchor[] {
                headAnchor, leftHandAnchor, rightHandAnchor,
                pelivsAnchor, leftFootAnchor, rightFootAnchor
            };

            Color oldColor = Gizmos.color;

            Gizmos.color = color;

            foreach (var anchor in anchors)
            {
                if (anchor.transform != null)
                {
                    Gizmos.DrawMesh(mesh, anchor.transform.position,
                                    anchor.transform.rotation, new Vector3(0.02f, 0.02f, 0.1f));
                }
            }
            Gizmos.color = oldColor;
        }
コード例 #16
0
ファイル: TrackingEvnBase.cs プロジェクト: nan023062/navevr
        protected void FillPoseMetadata(TrackingAnchor anchor, ref XRNodeState xRNode)
        {
            xRNode.TryGetPosition(out anchor.position);

            xRNode.TryGetRotation(out anchor.rotation);
        }
コード例 #17
0
 internal abstract void UpdateState(TrackingAnchor xRNodeUsage);
コード例 #18
0
 internal override void UpdateState(TrackingAnchor xRNodeUsage)
 {
 }