示例#1
0
        private void EnterHandMode(EHandMode mode)
        {
            if (m_eHandMode == mode)
            {
                return;
            }

            if (m_eHandMode == EHandMode.GRABBING)
            {
                if (m_bGravityChanged)
                {
                    m_grabbedActor.Actor.body.bustDynamicBone_L.setGravity(0, m_grabStartGravityL);
                    m_grabbedActor.Actor.body.bustDynamicBone_R.setGravity(0, m_grabStartGravityR);
                    m_bGravityChanged = false;
                }
                Owner?.StopRumble(m_rumble);
            }

            m_eHandMode = mode;

            if (mode == EHandMode.GRABBING)
            {
                m_grabStartControllerPos = m_raycastTransform.position;
                m_rumble.Reset();
                Owner?.StartRumble(m_rumble);
            }

            m_handOpen.gameObject.SetActive(mode == EHandMode.SHOW);
            m_handGrab.gameObject.SetActive(mode == EHandMode.GRABBING);
        }
示例#2
0
        private void EnterState(WarpState state)
        {
            // LEAVE state
            switch (State)
            {
            case WarpState.None:


                break;

            case WarpState.Rotating:

                break;

            case WarpState.Grabbing:
                Owner.StopRumble(_TravelRumble);
                _ScaleInitialized = _RotationInitialized = false;
                if (HasLock())
                {
                    VRLog.Debug("Releasing lock on other controller!");
                    _OtherLock.SafeRelease();
                }
                break;
            }


            // ENTER state
            switch (state)
            {
            case WarpState.None:
                SetVisibility(false);
                break;

            case WarpState.Rotating:
                SetVisibility(true);
                Reset();
                break;

            case WarpState.Grabbing:
                _PrevControllerPos = transform.position;
                _GripStartTime     = Time.unscaledTime;
                _TravelRumble.Reset();
                _PrevControllerPos = transform.position;
                _PrevControllerRot = transform.rotation;
                Owner.StartRumble(_TravelRumble);
                break;
            }

            State = state;
        }
示例#3
0
        protected override void OnUpdate()
        {
            base.OnUpdate();

            var device = this.Controller;

            if (Studio.Studio.Instance?.ociCamera != null && (Controller.GetPress(EVRButtonId.k_EButton_Grip) || Controller.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Grip) || Controller.GetPressUp(EVRButtonId.k_EButton_Grip)))
            {
                if (Controller.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Grip))
                {
                    _PrevControllerPos = transform.position;
                    _GripStartTime     = Time.unscaledTime;
                    _TravelRumble.Reset();
                    _PrevControllerPos = Studio.Studio.Instance.ociCamera.objectItem.transform.position - transform.position;
                    _PrevControllerRot = Quaternion.Inverse(Studio.Studio.Instance.ociCamera.objectItem.transform.rotation) * transform.rotation;
                    Owner.StartRumble(_TravelRumble);
                }
                if (Controller.GetPress(EVRButtonId.k_EButton_Grip))
                {
                    var diffPos = (Studio.Studio.Instance.ociCamera.objectItem.transform.position - transform.position) - _PrevControllerPos;
                    var diffRot = Quaternion.Inverse(_PrevControllerRot * Quaternion.Inverse(Quaternion.Inverse(Studio.Studio.Instance.ociCamera.objectItem.transform.rotation) * transform.rotation)) * (Quaternion.Inverse(Studio.Studio.Instance.ociCamera.objectItem.transform.rotation) * transform.rotation * Quaternion.Inverse(Quaternion.Inverse(Studio.Studio.Instance.ociCamera.objectItem.transform.rotation) * transform.rotation));
                    if (Time.unscaledTime - _GripStartTime > GRIP_TIME_THRESHOLD || Calculator.Distance(diffPos.magnitude) > GRIP_DIFF_THRESHOLD)
                    {
                        var forwardA  = Vector3.forward;
                        var forwardB  = diffRot * Vector3.forward;
                        var angleDiff = Calculator.Angle(forwardA, forwardB) * VR.Settings.RotationMultiplier;

                        Studio.Studio.Instance.ociCamera.objectItem.transform.position -= diffPos;
                        if (!VR.Settings.GrabRotationImmediateMode && Controller.GetPress(ButtonMask.Trigger | ButtonMask.Touchpad))
                        {
                            Studio.Studio.Instance.ociCamera.objectItem.transform.RotateAround(VR.Camera.Head.position, Vector3.up, -angleDiff);
                        }
                        _GripStartTime = 0; // To make sure that pos is not reset
                    }
                }

                if (Controller.GetPressUp(EVRButtonId.k_EButton_Grip))
                {
                    Owner.StopRumble(_TravelRumble);
                }

                _PrevControllerPos = Studio.Studio.Instance.ociCamera.objectItem.transform.position - transform.position;
                _PrevControllerRot = Quaternion.Inverse(Studio.Studio.Instance.ociCamera.objectItem.transform.rotation) * transform.rotation;
            }
            else if (Studio.Studio.Instance?.ociCamera == null && (Controller.GetPress(EVRButtonId.k_EButton_Grip) || Controller.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Grip) || Controller.GetPressUp(EVRButtonId.k_EButton_Grip)))
            {
                if (Controller.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Grip))
                {
                    _PrevControllerPos = transform.position;
                    _GripStartTime     = Time.unscaledTime;
                    _TravelRumble.Reset();
                    _PrevControllerPos = Studio.Studio.Instance.ociCamera.objectItem.transform.position - transform.position;
                    _PrevControllerRot = Quaternion.Inverse(Studio.Studio.Instance.ociCamera.objectItem.transform.rotation) * transform.rotation;
                    Owner.StartRumble(_TravelRumble);
                }
                if (Controller.GetPress(EVRButtonId.k_EButton_Grip))
                {
                    var diffPos = transform.position - _PrevControllerPos;
                    var diffRot = Quaternion.Inverse(_PrevControllerRot * Quaternion.Inverse(transform.rotation)) * (transform.rotation * Quaternion.Inverse(transform.rotation));
                    if (Time.unscaledTime - _GripStartTime > GRIP_TIME_THRESHOLD || Calculator.Distance(diffPos.magnitude) > GRIP_DIFF_THRESHOLD)
                    {
                        var forwardA  = Vector3.forward;
                        var forwardB  = diffRot * Vector3.forward;
                        var angleDiff = Calculator.Angle(forwardA, forwardB) * VR.Settings.RotationMultiplier;

                        VR.Camera.SteamCam.origin.transform.position -= diffPos;
                        if (!VR.Settings.GrabRotationImmediateMode && Controller.GetPress(ButtonMask.Trigger | ButtonMask.Touchpad))
                        {
                            VR.Camera.SteamCam.origin.transform.RotateAround(VR.Camera.Head.position, Vector3.up, -angleDiff);
                        }
                        _GripStartTime = 0; // To make sure that pos is not reset
                    }
                }

                if (Controller.GetPressUp(EVRButtonId.k_EButton_Grip))
                {
                    Owner.StopRumble(_TravelRumble);
                }

                _PrevControllerPos = transform.position;
                _PrevControllerRot = transform.rotation;
            }
            else if (Controller.GetPressDown(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger))
            {
                triggerStartTime = Time.unscaledTime;
                rewindCamera     = false;
            }
            else if (Controller.GetPressDown(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad))
            {
                rewindOCICamera = false;
                List <ObjectInfo> list = ObjectInfoAssist.Find(5);
                listCamera    = list.Select((ObjectInfo i) => Studio.Studio.GetCtrlInfo(i.dicKey) as OCICamera).ToList();
                backStartTime = Time.unscaledTime;
            }
            else if (Controller.GetPressUp(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad) && Time.unscaledTime - backStartTime <= .5f && !rewindOCICamera)
            {
                currentOCICamera++;
                if (currentOCICamera + 1 >= listCamera.Count)
                {
                    currentOCICamera = -1;
                    Singleton <Studio.Studio> .Instance.ChangeCamera(Singleton <Studio.Studio> .Instance.ociCamera, _active : false);
                }
                else
                {
                    Singleton <Studio.Studio> .Instance.ChangeCamera(listCamera[currentOCICamera], _active : true);
                }
                VRPlugin.MessageLogger.LogMessage($"Set Current Camera {Singleton<Studio.Studio>.Instance.ociCamera?.name}");
            }
            else if (Controller.GetPressUp(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger) && Time.unscaledTime - triggerStartTime <= .5f && !rewindCamera)
            {
                if (currentCamera == Studio.Studio.Instance.sceneInfo.cameraData.Length - 1)
                {
                    currentCamera = 0;
                }
                else
                {
                    currentCamera++;
                }
                Singleton <Studio.Studio> .Instance.cameraCtrl.Import(Singleton <Studio.Studio> .Instance.sceneInfo.cameraData[currentCamera]);

                VRPlugin.MessageLogger.LogMessage($"Set Current Camera {currentCamera + 1}");
            }
            else if (Controller.GetPress(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad) && Time.unscaledTime - backStartTime > .5f)
            {
                backStartTime   = float.MaxValue;
                rewindOCICamera = true;
                currentOCICamera--;
                if (currentOCICamera == -2)
                {
                    currentOCICamera = listCamera.Count - 1;
                }
                if (currentOCICamera == -1)
                {
                    Singleton <Studio.Studio> .Instance.ChangeCamera(Singleton <Studio.Studio> .Instance.ociCamera, _active : false);
                }
                else
                {
                    Singleton <Studio.Studio> .Instance.ChangeCamera(listCamera[currentOCICamera], _active : true);
                }
                VRPlugin.MessageLogger.LogMessage($"Set Current Camera {Singleton<Studio.Studio>.Instance.ociCamera?.name}");
            }
            else if (Controller.GetPress(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger) && Time.unscaledTime - triggerStartTime > .5f)
            {
                triggerStartTime = float.MaxValue;
                rewindCamera     = true;
                if (currentCamera == 0)
                {
                    currentCamera = 9;
                }
                else if (currentCamera == -1)
                {
                    currentCamera = 9;
                }
                else
                {
                    currentCamera--;
                }

                Singleton <Studio.Studio> .Instance.cameraCtrl.Import(Singleton <Studio.Studio> .Instance.sceneInfo.cameraData[currentCamera]);

                VRPlugin.MessageLogger.LogMessage($"Set Current Camera {currentCamera + 1}");
            }
        }