Пример #1
0
        public bool TryGetValidTooltipRig(ControllerButton button, out TooltipRig rig)
        {
            rig = default(TooltipRig);
            if (!EnumArrayBase <ControllerButton> .StaticIsValidIndex((int)button))
            {
                return(false);
            }

            var model       = VRModule.GetDeviceState(m_viveRole.GetDeviceIndex()).deviceModel;
            var rigSetAsset = (TooltipRigAsset)null;

            if (m_customTooltipRigSet != null)
            {
                rigSetAsset = m_customTooltipRigSet[(int)model];
            }

            if (rigSetAsset != null || TooltipRigAsset.TryGetDefaultAsset(model, out rigSetAsset))
            {
                var entries = rigSetAsset.rigEntries;
                if (entries != null && entries.Count > 0)
                {
                    for (int i = 0, imax = entries.Count; i < imax; ++i)
                    {
                        var entry = entries[i];
                        if (entry.button == button)
                        {
                            rig = entry.tooltipRig;
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
        private void UpdateMainCamTracking()
        {
            if (VIUSettings.simulatorAutoTrackMainCamera)
            {
                if (!m_autoTrackMainCam)
                {
                    m_autoTrackMainCam = true;
                    m_mainCamStartPose = new RigidPose(Camera.main.transform, true);
                }

                if (Camera.main != null)
                {
                    var hmd = VRModule.GetDeviceState(VRModule.HMD_DEVICE_INDEX);
                    if (hmd.isConnected)
                    {
                        RigidPose.SetPose(Camera.main.transform, hmd.pose);
                    }
                }
            }
            else
            {
                if (m_autoTrackMainCam)
                {
                    m_autoTrackMainCam = false;

                    if (Camera.main != null)
                    {
                        RigidPose.SetPose(Camera.main.transform, m_mainCamStartPose);
                    }
                }
            }
        }
    void Update()
    {
        Collider[] Colliders = Physics.OverlapSphere(transform.position, 0.1f);
        if (ViveInput.GetPressDown(HandRole.RightHand, ControllerButton.Trigger) || ViveInput.GetPressDown(HandRole.LeftHand, ControllerButton.Trigger))
        {
            if (Colliders.Length > 0 && Colliders[0].gameObject.layer == 14)
            {
                Colliders[0].gameObject.transform.parent = this.transform;
                child = Colliders[0].gameObject;
                child.GetComponent <Rigidbody>().isKinematic = true;
                child.GetComponent <Rigidbody>().useGravity  = false;
            }
        }

        if (ViveInput.GetPressUp(HandRole.RightHand, ControllerButton.Trigger) || ViveInput.GetPressUp(HandRole.LeftHand, ControllerButton.Trigger))
        {
            if (child != null)
            {
                child.GetComponent <Rigidbody>().isKinematic = false;
                uint    deviceIndex = ViveRoleProperty.New(HandRole.RightHand).GetDeviceIndex();
                Vector3 v           = VRModule.GetDeviceState(deviceIndex, false).velocity;
                Vector3 Av          = VRModule.GetDeviceState(deviceIndex, false).angularVelocity;

                child.GetComponent <Rigidbody>().velocity        = v;
                child.GetComponent <Rigidbody>().angularVelocity = Av;
                child.GetComponent <Rigidbody>().useGravity      = true;
                child.transform.parent = null;
            }
        }
    }
Пример #4
0
            protected void UpdateDefaultRenderModel(bool shouldActive)
            {
                var deviceState = VRModule.GetDeviceState(hook.GetModelDeviceIndex());

                var lastModelActivated      = m_isModelActivated;
                var lastActivatedModel      = m_activeModel;
                var shouldActiveModelNum    = deviceState.deviceModel;
                var shouldActiveModelPrefab = shouldActive ? GetDefaultDeviceModelPrefab(shouldActiveModelNum) : null;
                var shouldActiveModel       = shouldActive && deviceState.isConnected && shouldActiveModelPrefab != null;

                if (lastModelActivated)
                {
                    if (!shouldActiveModel || lastActivatedModel != shouldActiveModelNum)
                    {
                        // deactivate custom override model
                        var lastActiveModelObj = m_modelObjs[m_activeModel];
                        if (lastActiveModelObj != null && SendBeforeModelDeactivatedMessage(lastActiveModelObj, hook))
                        {
                            lastActiveModelObj.gameObject.SetActive(false);
                        }
                        m_isModelActivated = false;
                    }
                }

                if (shouldActiveModel)
                {
                    var shouldActiveModelObj = m_modelObjs[shouldActiveModelNum];
                    if (shouldActiveModelObj == null)
                    {
                        // instantiate custom override model
                        shouldActiveModelObj = Instantiate(shouldActiveModelPrefab);
                        shouldActiveModelObj.transform.position = Vector3.zero;
                        shouldActiveModelObj.transform.rotation = Quaternion.identity;
                        shouldActiveModelObj.transform.SetParent(hook.transform, false);
                        m_modelObjs[shouldActiveModelNum] = shouldActiveModelObj;
                        m_activeModel      = shouldActiveModelNum;
                        m_isModelActivated = false;
                        SendAfterModelCreatedMessage(shouldActiveModelObj, hook);
                    }

                    if (!m_isModelActivated)
                    {
                        // active custom override model
                        if (SendBeforeModelActivatedMessage(shouldActiveModelObj, hook))
                        {
                            shouldActiveModelObj.gameObject.SetActive(true);
                        }
                        m_isModelActivated = true;
                    }
                }
            }
Пример #5
0
        private void CheckHand()
        {
            uint tempRightIndex = VRModule.GetRightControllerDeviceIndex();
            uint tempLeftIndex  = VRModule.GetLeftControllerDeviceIndex();

            bool isRightConnected = VRModule.GetDeviceState(tempRightIndex).isConnected;
            bool isLeftConnected  = VRModule.GetDeviceState(tempLeftIndex).isConnected;

            if (!isLeftConnected && !isRightConnected)
            {
                reticleCanvas.enabled = false;
            }
            else
            {
                reticleCanvas.enabled = true;
            }
        }
            public void Update(uint index)
            {
                var deviceState = VRModule.GetDeviceState(index);

                deviceIndex     = index;
                serialNumber    = deviceState.serialNumber;
                modelNumber     = deviceState.modelNumber;
                renderModelName = deviceState.renderModelName;
                deviceClass     = deviceState.deviceClass;
                deviceModel     = deviceState.deviceModel;
                input2DType     = deviceState.input2DType;

                isConnected     = deviceState.isConnected;
                isPoseValid     = deviceState.isPoseValid;
                isOutOfRange    = deviceState.isOutOfRange;
                isCalibrating   = deviceState.isCalibrating;
                isUninitialized = deviceState.isUninitialized;

                velocity        = deviceState.velocity;
                angularVelocity = deviceState.angularVelocity;
                pose            = deviceState.pose;

                UpdateFieldString <VRModuleRawButton>(ref pressedFields, deviceState.buttonPressed, pressed);
                UpdateFieldString <VRModuleRawButton>(ref touchedFields, deviceState.buttonTouched, touched);

                foreach (VRModuleRawAxis i in axisValue.Enums)
                {
                    axisValue[i] = deviceState.GetAxisValue(i);
                }

                jointCount = 0;
                if (deviceState.readOnlyHandJoints != null)
                {
                    foreach (var p in deviceState.readOnlyHandJoints.EnumValues)
                    {
                        handJoints[p.Key] = p.Value;
                        if (p.Value.isValid)
                        {
                            jointCount++;
                        }
                    }
                }
            }
Пример #7
0
    /// <summary>
    /// When scalingActivated is true and both triggers are pressed,
    /// scale the game object base on the change of distance between two controllers
    /// </summary>
    void Update()
    {
        if (scalingActivated &&
            ViveInput.GetPressEx(HandRole.RightHand, ControllerButton.Trigger) &&
            ViveInput.GetPressEx(HandRole.LeftHand, ControllerButton.Trigger))
        // Conditions for active scaling
        {
            var rightHandIndex = ViveRole.GetDeviceIndexEx(HandRole.RightHand);
            var leftHandIndex  = ViveRole.GetDeviceIndexEx(HandRole.LeftHand);

            if (VRModule.IsValidDeviceIndex(rightHandIndex) && VRModule.IsValidDeviceIndex(leftHandIndex))
            {
                var rightHandState = VRModule.GetDeviceState(rightHandIndex);
                var leftHandState  = VRModule.GetDeviceState(leftHandIndex);
                // Get device state for both hands

                float dist = Vector3.Distance(rightHandState.position, leftHandState.position);

                if (prevDist == 0)
                {
                    prevDist = dist;
                }
                else
                {
                    // Scaling the object based on distance change
                    gameObject.transform.localScale *= (1 + scalingFactor * (dist - prevDist));
                    prevDist = dist;
                }
            }
            else
            {
                Debug.Log("Scaling: controller state error");
            }
        }

        if (ViveInput.GetPressUpEx(HandRole.RightHand, ControllerButton.Trigger) ||
            ViveInput.GetPressUpEx(HandRole.LeftHand, ControllerButton.Trigger))
        {
            prevDist = 0.0f;
        }
    }
        public void Refresh()
        {
            // find right/left controller index
            var rightIndex = VRModule.INVALID_DEVICE_INDEX;
            var leftIndex  = VRModule.INVALID_DEVICE_INDEX;

            if (RoleMap.IsRoleValueBound((int)ControllerRole.RightHand))
            {
                rightIndex = RoleMap.GetMappedDeviceByRoleValue((int)ControllerRole.RightHand);
            }
            else
            {
                var index = VRModule.GetRightControllerDeviceIndex();
                if (VRModule.GetDeviceState(index).deviceClass == VRModuleDeviceClass.Controller)
                {
                    rightIndex = index;
                }
            }
            if (RoleMap.IsRoleValueBound((int)ControllerRole.LeftHand))
            {
                leftIndex = RoleMap.GetMappedDeviceByRoleValue((int)ControllerRole.LeftHand);
            }
            else
            {
                var index = VRModule.GetRightControllerDeviceIndex();
                if (VRModule.GetDeviceState(index).deviceClass == VRModuleDeviceClass.Controller)
                {
                    leftIndex = index;
                }
            }
            if (leftIndex == rightIndex)
            {
                leftIndex = VRModule.INVALID_DEVICE_INDEX;
            }

            // find all other unbound controller class devices
            for (uint i = 0u, imax = VRModule.GetDeviceStateCount(); i < imax; ++i)
            {
                if (i == rightIndex)
                {
                    continue;
                }
                if (i == leftIndex)
                {
                    continue;
                }

                var device = VRModule.GetDeviceState(i);
                if (!device.isConnected)
                {
                    continue;
                }
                if (device.deviceClass != VRModuleDeviceClass.Controller)
                {
                    continue;
                }
                if (RoleMap.IsDeviceBound(device.serialNumber))
                {
                    continue;
                }

                m_sortedDeviceList.Add(i);
            }

            // if module didn't hint left/right controllers
            // find left/right most device in m_sortedDeviceList and assigned to leftIndex/rightIndex
            if (m_sortedDeviceList.Count > 0)
            {
                HandRoleHandler.SortDeviceIndicesByDirection(m_sortedDeviceList, VRModule.GetCurrentDeviceState(VRModule.HMD_DEVICE_INDEX).pose);

                if (rightIndex == VRModule.INVALID_DEVICE_INDEX && !RoleMap.IsRoleBound(ControllerRole.RightHand))
                {
                    rightIndex = m_sortedDeviceList[0];
                    m_sortedDeviceList.RemoveAt(0);
                }

                if (m_sortedDeviceList.Count > 0 && leftIndex == VRModule.INVALID_DEVICE_INDEX && !RoleMap.IsRoleBound(ControllerRole.RightHand))
                {
                    leftIndex = m_sortedDeviceList[m_sortedDeviceList.Count - 1];
                    m_sortedDeviceList.RemoveAt(m_sortedDeviceList.Count - 1);
                }
            }

            if (rightIndex != VRModule.INVALID_DEVICE_INDEX)
            {
                MappingRoleIfUnbound(ControllerRole.RightHand, rightIndex);
            }

            if (leftIndex != VRModule.INVALID_DEVICE_INDEX)
            {
                MappingRoleIfUnbound(ControllerRole.LeftHand, leftIndex);
            }

            if (m_sortedDeviceList.Count > 0)
            {
                var otherCtrlIndex = -1;
                var otherRole      = ControllerRole.Controller3 - 1;
                while (NextUnmappedSortedDevice(ref otherCtrlIndex) && NextUnmappedRole(ref otherRole))
                {
                    MappingRole(otherRole, m_sortedDeviceList[otherCtrlIndex]);
                }

                m_sortedDeviceList.Clear();
            }
        }
Пример #9
0
        public void Refresh()
        {
            // find tracked right/left hand index
            var deviceCount = VRModule.GetDeviceStateCount();
            var rightIndex  = VRModule.INVALID_DEVICE_INDEX;
            var leftIndex   = VRModule.INVALID_DEVICE_INDEX;

            for (uint deviceIndex = 0u; deviceIndex < deviceCount; ++deviceIndex)
            {
                var deviceState = VRModule.GetDeviceState(deviceIndex);
                if (deviceState.isConnected && deviceState.deviceClass == VRModuleDeviceClass.TrackedHand)
                {
                    if (deviceState.deviceModel.IsRight())
                    {
                        rightIndex = deviceIndex;
                    }
                    else if (deviceState.deviceModel.IsLeft())
                    {
                        leftIndex = deviceIndex;
                    }
                }
            }

            if (!RoleMap.IsRoleMapped(TrackedHandRole.RightHand))
            {
                if (rightIndex < deviceCount)
                {
                    MappingRoleIfUnbound(TrackedHandRole.RightHand, rightIndex);
                }
            }
            else if (!RoleMap.IsRoleBound(TrackedHandRole.RightHand))
            {
                if (rightIndex < deviceCount)
                {
                    MappingRoleIfUnbound(TrackedHandRole.RightHand, rightIndex);
                }
                else
                {
                    UnmappingRole(TrackedHandRole.RightHand);
                }
            }

            if (!RoleMap.IsRoleMapped(TrackedHandRole.LeftHand))
            {
                if (leftIndex < deviceCount)
                {
                    MappingRoleIfUnbound(TrackedHandRole.LeftHand, leftIndex);
                }
            }
            else if (!RoleMap.IsRoleBound(TrackedHandRole.LeftHand))
            {
                if (leftIndex < deviceCount)
                {
                    MappingRoleIfUnbound(TrackedHandRole.LeftHand, leftIndex);
                }
                else
                {
                    UnmappingRole(TrackedHandRole.LeftHand);
                }
            }
        }
Пример #10
0
        public void UpdateModel()
        {
            if (m_isQuiting)
            {
                return;
            }

            if (m_updateModelLock)
            {
                Debug.LogWarning("Recursive UpdateModel call is not supported");
                return;
            }

            m_updateModelLock = true;

            var deviceState = VRModule.GetDeviceState(GetModelDeviceIndex());

            var lastActiveCustomModelNum      = m_activeCustomModel;
            var lastActiveCustomModelObj      = m_customModelObjs[m_activeCustomModel];
            var lastCustomModelActive         = m_isCustomModelActivated;
            var shouldActiveCustomModelNum    = deviceState.deviceModel;
            var shouldActiveCustomModelPrefab = m_customModels[shouldActiveCustomModelNum];

            if (shouldActiveCustomModelPrefab == null)
            {
                shouldActiveCustomModelPrefab = VIUSettings.GetOverrideDeviceModel(shouldActiveCustomModelNum);
            }
            var shouldActiveCustomModel = enabled && deviceState.isConnected && shouldActiveCustomModelPrefab != null;

            var lastCreatorActive        = m_activeCreatorIndex >= 0;
            var shouldActiveCreator      = enabled && !shouldActiveCustomModel;
            var shouldActiveCreatorIndex = -1;

            if (shouldActiveCreator)
            {
                // determin which creator should be activated
                shouldActiveCreatorIndex = m_defaultCreatorIndex;
                if (m_overrideModel == OverrideModelEnum.DontOverride)
                {
                    for (int i = 0, imax = m_creators.Length; i < imax; ++i)
                    {
                        if (m_creators[i].shouldActive)
                        {
                            shouldActiveCreatorIndex = i;
                            break;
                        }
                    }
                }
            }

            if (lastCustomModelActive)
            {
                if (!shouldActiveCustomModel || lastActiveCustomModelNum != shouldActiveCustomModelNum)
                {
                    // deactivate custom override model
                    if (lastActiveCustomModelObj != null && SendBeforeModelDeactivatedMessage(lastActiveCustomModelObj, this))
                    {
                        lastActiveCustomModelObj.gameObject.SetActive(false);
                    }
                    m_isCustomModelActivated = false;
                }
            }

            if (lastCreatorActive)
            {
                if (!shouldActiveCreator || m_activeCreatorIndex != shouldActiveCreatorIndex)
                {
                    // clean up old creator
                    m_creators[m_activeCreatorIndex].CleanUpRenderModel();
                    m_activeCreatorIndex = -1;
                }
            }

            if (shouldActiveCustomModel)
            {
                var shouldActiveCustomModelObj = m_customModelObjs[shouldActiveCustomModelNum];
                if (shouldActiveCustomModelObj == null)
                {
                    // instantiate custom override model
                    shouldActiveCustomModelObj = Instantiate(shouldActiveCustomModelPrefab);
                    shouldActiveCustomModelObj.transform.position = Vector3.zero;
                    shouldActiveCustomModelObj.transform.rotation = Quaternion.identity;
                    shouldActiveCustomModelObj.transform.SetParent(transform, false);
                    m_activeCustomModel = shouldActiveCustomModelNum;
                    m_customModelObjs[shouldActiveCustomModelNum] = shouldActiveCustomModelObj;
                    m_isCustomModelActivated = false;
                    SendAfterModelCreatedMessage(shouldActiveCustomModelObj, this);
                }

                if (!m_isCustomModelActivated)
                {
                    // active custom override model
                    if (SendBeforeModelActivatedMessage(shouldActiveCustomModelObj, this))
                    {
                        shouldActiveCustomModelObj.gameObject.SetActive(true);
                    }
                    m_isCustomModelActivated = true;
                }
            }

            if (shouldActiveCreator)
            {
                m_activeCreatorIndex = shouldActiveCreatorIndex;
                // update active creator
                m_creators[m_activeCreatorIndex].UpdateRenderModel();
            }

            m_updateModelLock = false;
        }
        private void Update()
        {
            if (m_updateDynamically)
            {
#if VIU_WAVEXR_ESSENCE_CONTROLLER_MODEL && UNITY_ANDROID
                updateBatteryLevel();
                CollectEffectObjects();

                var deviceState = VRModule.GetDeviceState(m_deviceIndex);

                if (preferedModelName.Contains("Right"))
                {
                    if (deviceState.GetButtonPress(VRModuleRawButton.Grip))
                    {
                        //Debug.Log("hasEffect: " + pressObjectArrays[0].hasEffect);
                        pressObjectArrays[1].gameObject.GetComponent <MeshRenderer>().material = pressObjectArrays[1].effectMat;
                        pressObjectArrays[1].gameObject.SetActive(true);
                    }
                    else
                    {
                        pressObjectArrays[1].gameObject.GetComponent <MeshRenderer>().material = pressObjectArrays[1].originMat;
                        pressObjectArrays[1].gameObject.SetActive(false);
                    }

                    if (deviceState.GetButtonPress(VRModuleRawButton.Trigger))
                    {
                        //Debug.Log("hasEffect: " + pressObjectArrays[4].hasEffect);
                        pressObjectArrays[4].gameObject.GetComponent <MeshRenderer>().material = pressObjectArrays[4].effectMat;
                        pressObjectArrays[4].gameObject.SetActive(true);
                    }
                    else
                    {
                        pressObjectArrays[4].gameObject.GetComponent <MeshRenderer>().material = pressObjectArrays[4].originMat;
                        pressObjectArrays[4].gameObject.SetActive(false);
                    }

                    if (deviceState.GetButtonPress(VRModuleRawButton.A))
                    {
                        //Debug.Log("hasEffect: " + pressObjectArrays[4].hasEffect);
                        pressObjectArrays[5].gameObject.GetComponent <MeshRenderer>().material = pressObjectArrays[5].effectMat;
                        pressObjectArrays[5].gameObject.SetActive(true);
                    }
                    else
                    {
                        pressObjectArrays[5].gameObject.GetComponent <MeshRenderer>().material = pressObjectArrays[5].originMat;
                        pressObjectArrays[5].gameObject.SetActive(false);
                    }

                    if (deviceState.GetButtonPress(VRModuleRawButton.ApplicationMenu))
                    {
                        //Debug.Log("hasEffect: " + pressObjectArrays[4].hasEffect);
                        pressObjectArrays[6].gameObject.GetComponent <MeshRenderer>().material = pressObjectArrays[6].effectMat;
                        pressObjectArrays[6].gameObject.SetActive(true);
                    }
                    else
                    {
                        pressObjectArrays[6].gameObject.GetComponent <MeshRenderer>().material = pressObjectArrays[6].originMat;
                        pressObjectArrays[6].gameObject.SetActive(false);
                    }
                }

                if (preferedModelName.Contains("Left"))
                {
                    if (deviceState.GetButtonPress(VRModuleRawButton.System))
                    {
                        //Debug.Log("hasEffect: " + pressObjectArrays[0].hasEffect);
                        pressObjectArrays[0].gameObject.GetComponent <MeshRenderer>().material = pressObjectArrays[0].effectMat;
                        pressObjectArrays[0].gameObject.SetActive(true);
                    }
                    else
                    {
                        pressObjectArrays[0].gameObject.GetComponent <MeshRenderer>().material = pressObjectArrays[0].originMat;
                        pressObjectArrays[0].gameObject.SetActive(false);
                    }

                    if (deviceState.GetButtonPress(VRModuleRawButton.Grip))
                    {
                        //Debug.Log("hasEffect: " + pressObjectArrays[0].hasEffect);
                        pressObjectArrays[1].gameObject.GetComponent <MeshRenderer>().material = pressObjectArrays[1].effectMat;
                        pressObjectArrays[1].gameObject.SetActive(true);
                    }
                    else
                    {
                        pressObjectArrays[1].gameObject.GetComponent <MeshRenderer>().material = pressObjectArrays[1].originMat;
                        pressObjectArrays[1].gameObject.SetActive(false);
                    }

                    if (deviceState.GetButtonPress(VRModuleRawButton.Trigger))
                    {
                        //Debug.Log("hasEffect: " + pressObjectArrays[4].hasEffect);
                        pressObjectArrays[4].gameObject.GetComponent <MeshRenderer>().material = pressObjectArrays[4].effectMat;
                        pressObjectArrays[4].gameObject.SetActive(true);
                    }
                    else
                    {
                        pressObjectArrays[4].gameObject.GetComponent <MeshRenderer>().material = pressObjectArrays[4].originMat;
                        pressObjectArrays[4].gameObject.SetActive(false);
                    }

                    if (deviceState.GetButtonPress(VRModuleRawButton.A))
                    {
                        //Debug.Log("hasEffect: " + pressObjectArrays[4].hasEffect);
                        pressObjectArrays[7].gameObject.GetComponent <MeshRenderer>().material = pressObjectArrays[7].effectMat;
                        pressObjectArrays[7].gameObject.SetActive(true);
                    }
                    else
                    {
                        pressObjectArrays[7].gameObject.GetComponent <MeshRenderer>().material = pressObjectArrays[7].originMat;
                        pressObjectArrays[7].gameObject.SetActive(false);
                    }

                    if (deviceState.GetButtonPress(VRModuleRawButton.ApplicationMenu))
                    {
                        //Debug.Log("hasEffect: " + pressObjectArrays[4].hasEffect);
                        pressObjectArrays[8].gameObject.GetComponent <MeshRenderer>().material = pressObjectArrays[8].effectMat;
                        pressObjectArrays[8].gameObject.SetActive(true);
                    }
                    else
                    {
                        pressObjectArrays[8].gameObject.GetComponent <MeshRenderer>().material = pressObjectArrays[8].originMat;
                        pressObjectArrays[8].gameObject.SetActive(false);
                    }
                }
#endif
            }
        }