Esempio n. 1
0
        public void SetGripState(GripState state)
        {
            if (m_CurrentGripState != state)
            {
                ControllerStyle style = ControllerGeometry.Style;
                if (style != ControllerStyle.InitializingSteamVR &&
                    style != ControllerStyle.None &&
                    style != ControllerStyle.Unset)
                {
                    bool manuallyAnimateGrips = (style == ControllerStyle.Vive ||
                                                 style == ControllerStyle.Wmr);

                    switch (state)
                    {
                    case GripState.Standard:
                        if (manuallyAnimateGrips)
                        {
                            ControllerGeometry.LeftGripMesh.transform.localPosition  = Vector3.zero;
                            ControllerGeometry.RightGripMesh.transform.localPosition = Vector3.zero;
                        }
                        ControllerGeometry.LeftGripMesh.material  = ControllerGeometry.BaseGrippedMaterial;
                        ControllerGeometry.RightGripMesh.material = ControllerGeometry.BaseGrippedMaterial;
                        break;

                    case GripState.ReadyToGrip:
                        if (manuallyAnimateGrips)
                        {
                            ControllerGeometry.LeftGripMesh.transform.localPosition =
                                m_ControllerGeometry.LeftGripPopOutVector;
                            Vector3 vRightPopOut = m_ControllerGeometry.LeftGripPopOutVector;
                            vRightPopOut.x *= -1.0f;
                            ControllerGeometry.RightGripMesh.transform.localPosition = vRightPopOut;
                        }
                        ControllerGeometry.LeftGripMesh.material  = m_ControllerGeometry.GripReadyMaterial;
                        ControllerGeometry.RightGripMesh.material = m_ControllerGeometry.GripReadyMaterial;
                        ControllerGeometry.LeftGripMesh.material.SetColor("_Color", m_Tint);
                        ControllerGeometry.RightGripMesh.material.SetColor("_Color", m_Tint);
                        break;

                    case GripState.Gripped:
                        if (manuallyAnimateGrips)
                        {
                            ControllerGeometry.LeftGripMesh.transform.localPosition =
                                m_ControllerGeometry.LeftGripPopInVector;
                            Vector3 vRightPopIn = m_ControllerGeometry.LeftGripPopInVector;
                            vRightPopIn.x *= -1.0f;
                            ControllerGeometry.RightGripMesh.transform.localPosition = vRightPopIn;
                        }
                        ControllerGeometry.LeftGripMesh.material  = m_ControllerGeometry.GrippedMaterial;
                        ControllerGeometry.RightGripMesh.material = m_ControllerGeometry.GrippedMaterial;
                        ControllerGeometry.LeftGripMesh.material.SetColor("_Color", m_Tint);
                        ControllerGeometry.RightGripMesh.material.SetColor("_Color", m_Tint);
                        break;
                    }
                }
            }
            m_CurrentGripState = state;
        }
Esempio n. 2
0
        public void AttachToController(BaseControllerBehavior behavior)
        {
            ControllerGeometry geo = behavior.ControllerGeometry;

            transform.parent   = null;
            transform.position = geo.ConsoleAttachPoint.position;
            transform.rotation = geo.ConsoleAttachPoint.rotation;
            transform.parent   = geo.ConsoleAttachPoint.transform;

            m_NotificationAnchor.position = geo.BaseAttachPoint.position;
            m_NotificationAnchor.rotation = geo.BaseAttachPoint.rotation;

            // The logitech pen has a custom activation angle.
            ControllerStyle geoStyle = geo.Style;

            m_ActivateAngle = (geoStyle == ControllerStyle.LogitechPen) ?
                              m_ActivationAngle_LogitechPen : m_ActivationAngle_Default;
        }
Esempio n. 3
0
        void Start()
        {
            m_AnimationValue     = 0.0f;
            m_ControllerBasePosA = m_GeometryWandPanel.localPosition;
            m_ControllerBasePosB = m_GeometryBrushStroke.localPosition;
            m_Flipped            = false;
            m_RepelTime          = m_ClickTime * 2.0f;

            // Ignore the Logitech Pen.
            ControllerStyle style = App.VrSdk.VrControls.BaseControllerStyle;

            switch (style)
            {
            case ControllerStyle.OculusTouch:
                if (App.Config.VrHardware == VrHardware.Rift)
                {
                    m_ControllerGeometryLeft  = m_GeometryRiftLeft;
                    m_ControllerGeometryRight = m_GeometryRiftRight;
                }
                else if (App.Config.VrHardware == VrHardware.Quest)
                {
                    // TODO(b/135950527): rift-s also uses quest controllers.
                    m_ControllerGeometryLeft  = m_GeometryQuestLeft;
                    m_ControllerGeometryRight = m_GeometryQuestRight;
                }
                break;

            case ControllerStyle.Wmr:
                m_ControllerGeometryLeft  = m_GeometryWmrLeft;
                m_ControllerGeometryRight = m_GeometryWmrRight;
                break;

            case ControllerStyle.Knuckles:
                m_ControllerGeometryLeft  = m_GeometryKnucklesLeft;
                m_ControllerGeometryRight = m_GeometryKnucklesRight;
                break;

            case ControllerStyle.Vive:
            default:
                m_ControllerGeometryLeft  = m_GeometryViveLeft;
                m_ControllerGeometryRight = m_GeometryViveRight;
                break;
            }
        }
        void Awake()
        {
            // Dodge the logitech pen.  That's not supported.
            ControllerStyle style = App.VrSdk.VrControls.BaseControllerStyle;

            // Default to all off.
            ActivateControllers(m_RiftControllers, false);
            ActivateControllers(m_ViveControllers, false);
            ActivateControllers(m_WmrControllers, false);
            ActivateControllers(m_QuestControllers, false);
            ActivateControllers(m_KnucklesControllers, false);

            // Enable whatever style is active.
            switch (style)
            {
            case ControllerStyle.OculusTouch:
                if (App.Config.VrHardware == VrHardware.Rift)
                {
                    ActivateControllers(m_RiftControllers, true);
                }
                else if (App.Config.VrHardware == VrHardware.Quest)
                {
                    // TODO(b/135950527): rift-s also uses quest controllers.
                    ActivateControllers(m_QuestControllers, true);
                }
                break;

            case ControllerStyle.Wmr:
                ActivateControllers(m_WmrControllers, true);
                break;

            case ControllerStyle.Knuckles:
                ActivateControllers(m_KnucklesControllers, true);
                break;

            case ControllerStyle.Vive:
            default:
                ActivateControllers(m_ViveControllers, true);
                break;
            }
        }
Esempio n. 5
0
        // Destroy and recreate the ControllerBehavior and ControllerGeometry objects.
        // This is mostly useful if you want different geometry.
        //
        // TODO: this will always give the wand left-hand geometry and the brush right-hand geometry,
        // so InputManager.WandOnRight should probably be reset to false after this? Or maybe
        // SetControllerStyle should be smart enough to figure that out.
        public void SetControllerStyle(ControllerStyle style)
        {
            Debug.Log("Calling SetControllerStyle");
            // Clear console parent in case we're switching controllers.
            if (ControllerConsoleScript.m_Instance != null)
            {
                ControllerConsoleScript.m_Instance.transform.parent = null;
            }

            // Clean up existing controllers.
            // Note that we are explicitly not transferring state.  This is because, in practice,
            // we only change controller style when we're initializing SteamVR, and the temporary
            // controllers are largely disabled.  Any bugs that occur will be trivial and cosmetic.
            // If we add the ability to dynamically change controllers or my above comment about
            // trivial bugs is not true, state transfer should occur here.
            //
            // In practice, the only style transitions we should see are:
            // - None -> correct style                   During VrSdk.Awake()
            // - None -> InitializingSteamVr             During VrSdk.Awake()
            //   InitializingSteamVr -> correct style    Many frames after VrSdk.Awake()
            if (m_VrControls != null)
            {
                Destroy(m_VrControls.gameObject);
                m_VrControls = null;
            }

            m_NeedsToAttachConsoleScript = true;

            GameObject controlsPrefab;

            switch (style)
            {
            case ControllerStyle.Vive:
                controlsPrefab = m_SteamViveControlsPrefab;
                break;

            case ControllerStyle.Knuckles:
                controlsPrefab = m_SteamKnucklesControlsPrefab;
                break;

            case ControllerStyle.Cosmos:
                controlsPrefab = m_SteamCosmoControlsPrefab;
                break;

            case ControllerStyle.OculusTouch:
            {
                // This will probably not work once new headsets are released.
                // Maybe something like this instead?
                //   isQuest = (UnityEngine.XR.XRDevice.model != "Oculus Rift CV1");
                bool isQuestController = (UnityEngine.XR.XRDevice.refreshRate < 81f) ||
                                         (App.Config.VrHardware == VrHardware.Quest);
                if (App.Config.m_SdkMode == SdkMode.Oculus)
                {
                    controlsPrefab = isQuestController ? m_OculusQuestControlsPrefab : m_OculusRiftControlsPrefab;
                }
                else         /* Assume SteamVR */
                {
                    controlsPrefab = isQuestController ? m_SteamQuestControlsPrefab : m_SteamRiftControlsPrefab;
                }
                break;
            }

            case ControllerStyle.Wmr:
                controlsPrefab = m_SteamWmrControlsPrefab;
                break;

            case ControllerStyle.Gvr:
                controlsPrefab = m_GvrPointerControlsPrefab;
                break;

            case ControllerStyle.None:
                controlsPrefab = m_NonVrControlsPrefab;
                m_NeedsToAttachConsoleScript = false;
                break;

            case ControllerStyle.InitializingSteamVR:
                controlsPrefab = m_SteamUninitializedControlsPrefab;
                m_NeedsToAttachConsoleScript = false;
                break;

            case ControllerStyle.Unset:
            default:
                controlsPrefab = null;
                m_NeedsToAttachConsoleScript = false;
                break;
            }

#if UNITY_EDITOR
            // This is _just_ robust enough to be able to switch between the Rift and Touch
            // controllers. To force (for example) a Wmr controller when using a Touch will
            // probably require being able to specify an override style as well, because TB
            // might act funny if we spawn a Wmr prefab with style OculusTouch.
            // Additionally, the Logitech Pen override happens after this, so there's no way
            // to override it.

            // Wait for the "real" SetControllerStyle to come through.
            if (style != ControllerStyle.InitializingSteamVR)
            {
                GameObject overridePrefab = null;
                switch (App.Config.m_SdkMode)
                {
                case SdkMode.Oculus: overridePrefab = App.Config.m_ControlsPrefabOverrideOvr; break;

                case SdkMode.SteamVR: overridePrefab = App.Config.m_ControlsPrefabOverrideSteamVr; break;
                }
                if (overridePrefab != null)
                {
                    Debug.LogWarning("Overriding Vr controls with {0}", overridePrefab);
                    controlsPrefab = overridePrefab;
                }
            }
#endif

            if (controlsPrefab != null)
            {
                Debug.Assert(m_VrControls == null);
                GameObject controlsObject = Instantiate(controlsPrefab);
                m_VrControls = controlsObject.GetComponent <VrControllers>();
                if (m_VrControls == null)
                {
                    throw new InvalidOperationException(
                              string.Format("Bad prefab for {0} {1}", style, controlsPrefab));
                }
                m_VrControls.transform.parent = m_VrSystem.transform;
            }

            if (m_VrControls != null)
            {
                if (m_NeedsToAttachConsoleScript && ControllerConsoleScript.m_Instance)
                {
                    ControllerConsoleScript.m_Instance.AttachToController(
                        m_VrControls.Brush);
                    m_NeedsToAttachConsoleScript = false;
                }

                // TODO: the only case where this is necessary is when using empty geometry
                // for ControllerStyle.InitializingSteamVR. Can we keep track of "initializing"
                // some other way?
                m_VrControls.Brush.ControllerGeometry.TempWritableStyle = style;
                m_VrControls.Wand.ControllerGeometry.TempWritableStyle  = style;
            }
        }
Esempio n. 6
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            ControllerStyle src = (ControllerStyle)value;

            return((int)src);
        }