コード例 #1
0
        // Helper for SwapGeometry.
        // Sets up pointers from this -> geom, and from geom -> this.
        private void SetGeometry(ControllerGeometry geom)
        {
            m_ControllerGeometry = geom;

            // The back-pointers is implicit; it's geometry.transform.parent.
            // worldPositionStays: false because we're about to overwrite it anyway
            m_ControllerGeometry.transform.SetParent(this.transform, worldPositionStays: false);
            Quaternion rot = m_GeometryRotation.IsInitialized() ? m_GeometryRotation : Quaternion.identity;

            Coords.AsLocal[m_ControllerGeometry.transform] = TrTransform.TRS(m_GeometryOffset, rot, 1);
            m_ControllerGeometry.OnBehaviorChanged();
        }
コード例 #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;
        }
コード例 #3
0
        // Override the controller geometry with an instance of the passed in prefab unless we're passed
        // null. In that case, use the default controller geometry prefab.
        public void InstantiateControllerGeometryFromPrefab(ControllerGeometry prefab)
        {
            bool changedController = false;

            if (m_ControllerGeometry != null)
            {
                Destroy(m_ControllerGeometry.gameObject);
                changedController = true;
            }

            if (prefab == null)
            {
                prefab = m_ControllerGeometryPrefab;
            }
            SetGeometry(Instantiate(prefab));

            if (changedController)
            {
                InputManager.ControllersHaveChanged();
            }
        }
コード例 #4
0
        private void Start()
        {
            // This is the base of our prefab and will never change
            m_geometry = GetComponentInParent <ControllerGeometry>();
            if (m_geometry == null)
            {
                Debug.LogWarning("Bad prefab: must be below a ControllerGeometry", this);
                enabled = false;
            }

            if (m_animator == null)
            {
                Debug.LogWarning("Bad prefab: must have an animator", this);
                enabled = false;
            }

            // Removed for b/134974904
            // TODO(for release 21): Remove this entirely
            // if (App.Config.m_SdkMode != SdkMode.SteamVR) {
            //   enabled = false;
            // }
        }
コード例 #5
0
        void Update()
        {
            // This is a proxy for "tutorial mode".
            SketchControlsScript.m_Instance.AssignControllerMaterials(m_ControllerName);

            // Skip the tint and animation update if in intro sketch because
            // - nothing but the default has been assigned
            // - the user is not able to change the tint color
            // - we do not want to animate the buttons/pads
            if (!PanelManager.m_Instance.IntroSketchbookMode)
            {
                // Send a signal to the controller that the materials have been assigned.
                ControllerGeometry.OnMaterialsAssigned(GetTintColor());
            }

            if (ControllerGeometry.XRayVisuals)
            {
                float XRayHeight_ss = (App.Scene.Pose.translation.y
                                       + App.Scene.Pose.scale * SceneSettings.m_Instance.ControllerXRayHeight);
                bool bControllerUnderground = transform.position.y < XRayHeight_ss;
                bool bHMDUnderground        = ViewpointScript.Head.position.y < XRayHeight_ss;
                ControllerGeometry.XRayVisuals.SetActive(bControllerUnderground != bHMDUnderground);
            }

            if (ControllerGeometry.TriggerAnchor != null)
            {
                // This is hooked up for Wmr, Vive.
                // This is not hooked up for the Quest, Rift, Knuckles controller geometry;
                // they work using Animators and AnimateOculusTouchSteam.cs
                Vector2 range = m_ControllerGeometry.TriggerRotation;
                ControllerGeometry.TriggerAnchor.localRotation = Quaternion.AngleAxis(
                    Mathf.Lerp(range.x, range.y, ControllerInfo.GetTriggerRatio()),
                    Vector3.right);
            }

            //
            // If the transform visuals are active and the user is interacting with a widget, add the
            // transform visuals to the highlight queue. Eventually, we may:
            //
            // (a) only have the post process higlight in which case these transform visuals will not need
            //     a renderer/material or
            // (b) modify the highlight queue to a dynamic list that retains state across frames in which
            //     case this logic can be moved into EnableTransformVisuals().
            //
            if (TransformVisuals.activeSelf &&
                SketchControlsScript.m_Instance.IsUserAbleToInteractWithAnyWidget())
            {
                App.Instance.SelectionEffect.RegisterMesh(TransformVisuals.GetComponent <MeshFilter>());

                switch (ControllerGeometry.Style)
                {
                case ControllerStyle.OculusTouch:
                case ControllerStyle.Knuckles:
                    App.Instance.SelectionEffect.RegisterMesh(
                        ControllerGeometry.JoystickPad.GetComponent <MeshFilter>());
                    break;

                case ControllerStyle.Vive:
                    App.Instance.SelectionEffect.RegisterMesh(
                        ControllerGeometry.PadMesh.GetComponent <MeshFilter>());
                    break;

                case ControllerStyle.Wmr:
                    // TODO What should be here?  Joystick or pad?
                    break;
                }
            }

            OnUpdate();
        }