Example #1
0
    //左手反応するか
    public void learnUnlockKey()
    {
        ulong Leftbutton, Rightbutton;
        ulong key = 0;

        if (util.GetControllerButtonPressed(util.GetLeftControllerIndex(), out Leftbutton))
        {
            key |= Leftbutton;
        }
        if (util.GetControllerButtonPressed(util.GetRightControllerIndex(), out Rightbutton))
        {
            key |= Rightbutton;
        }
        if (key == 0)
        {
            menu.ShowDialogOK(LanguageManager.config.showdialog.BUTTON_NOT_FOUND, "", 0.5f, () => { });
            return;
        }

        config.unlockkey = key;
        saveJSON();
        menu.ShowDialogOK(LanguageManager.config.showdialog.BUTTON_REGISTER, "key: " + key.ToString(), 0.5f, () => { });
    }
Example #2
0
    void Update()
    {
        ValueWatcher();
        //System.GC.Collect();

        //FPSモニタ
        if (showing && !busy)
        {
            fps             = fps * 0.99f + (1f / Time.deltaTime) * 0.01f;
            FPSMonitor.text = String.Format("{0:###}", 1f / Time.deltaTime);

            //よほどのことがない限り下がらないfpsが一気に下がったらメニューを強制的に閉じる
            if (fps < 15f) //表示時で15fps以下
            {
                MenuEndFunc(0);
            }
        }
        else
        {
            fps = 90; //閉じてるときは90扱いにする
        }


        //初期化されていないとき初期化する
        if (!util.IsReady())
        {
            util.Init();
            return;
        }

        //チュートリアル中の見失い防止処理
        //初期位置から動いてないときは自動で再配置する
        if (isInTutorial || EOVRO.Position == Vector3.zero)
        {
            TutorialTimer += Time.deltaTime;
            if (TutorialTimer > 10f)
            {
                TutorialTimer = 0;
                setPosition();
            }
        }

        //移動モード
        if (isScreenMoving)
        {
            ulong button = 0;
            EasyOpenVRUtil.Transform pos  = util.GetHMDTransform();
            EasyOpenVRUtil.Transform cpos = null;
            if (screenMoveWithRight)
            {
                if (util.GetControllerButtonPressed(util.GetRightControllerIndex(), out button))
                {
                    cpos = util.GetRightControllerTransform();
                }
            }
            else
            {
                if (util.GetControllerButtonPressed(util.GetLeftControllerIndex(), out button))
                {
                    cpos = util.GetLeftControllerTransform();
                }
            }
            if (button == 0)
            {
                AudioMan.PlayApplySound();
                isScreenMoving = false;
            }

            if (pos != null && cpos != null)
            {
                var     z   = 0;
                Vector3 ang = (cpos.rotation * Quaternion.AngleAxis(45, Vector3.right)).eulerAngles;
                //常にこっちに向き、ゆっくり追従する
                Vector3 BillboardPosition = cpos.position;                      //これが難しい...
                Vector3 BillboardRotation = new Vector3(-ang.x, -ang.y, ang.z); //こっち向く。これでオッケー

                EOVRO.Position = BillboardPosition;
                EOVRO.Rotation = BillboardRotation;
            }
        }
    }
Example #3
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Q))
        {
            Debug.Log("!");
        }
        if (Input.GetKeyDown(KeyCode.A))
        {
            Debug.Log(eou.Init());
        }
        if (Input.GetKeyDown(KeyCode.W))
        {
            Debug.Log(eou.StartOpenVR());
        }
        if (Input.GetKeyDown(KeyCode.S))
        {
            Debug.Log(eou.TakeScreenShot("D:\\tmp\\test", "D:\\tmp\\test2"));
        }
        if (Input.GetKeyDown(KeyCode.X))
        {
            Debug.Log(eou.GetDeviceIndexBySerialNumber("LHR-72214A13"));
        }
        if (Input.GetKeyDown(KeyCode.Z))
        {
            eou.Update();
            Debug.Log(eou.PutDeviceInfoListString());
        }

        if (Input.GetKeyDown(KeyCode.V))
        {
            Debug.Log(eou.PutDeviceInfoListStringFromDeviceIndexList(eou.GetDeviceIndexListByRegisteredDeviceType("tracker")));
            Debug.Log(eou.PutDeviceInfoListStringFromDeviceIndexList(eou.GetDeviceIndexListByRenderModelName("tracker")));
        }
        if (Input.GetKeyDown(KeyCode.N))
        {
            Debug.Log(eou.TriggerHapticPulse(eou.GetLeftControllerIndex()));
            Debug.Log(eou.TriggerHapticPulse(eou.GetRightControllerIndex()));
        }
        if (Input.GetKeyDown(KeyCode.B))
        {
            Debug.Log("Controller");
            Debug.Log(eou.PutDeviceInfoListStringFromDeviceIndexList(eou.GetViveControllerIndexList()));
            Debug.Log("Tracker");
            Debug.Log(eou.PutDeviceInfoListStringFromDeviceIndexList(eou.GetViveTrackerIndexList()));
            Debug.Log("BaseStation");
            Debug.Log(eou.PutDeviceInfoListStringFromDeviceIndexList(eou.GetBaseStationIndexList()));
        }
        if (Input.GetKeyDown(KeyCode.Y))
        {
        }

        /*
         * Vector3 pos;
         * Quaternion rot;
         * eou.GetHMDPose(out pos, out rot);
         * obj.transform.position = pos;
         * obj.transform.rotation = rot;
         *
         * eou.GetPoseBySerialNumber("LHR-72214A13", out pos, out rot);
         * obj2.transform.position = pos;
         * obj2.transform.rotation = rot;
         *
         * Vector3 pos2;
         * Quaternion rot2;
         * eou.GetControllerPose(out pos, out rot, out pos2, out rot2);
         * obj3.transform.position = pos;
         * obj3.transform.rotation = rot;
         *
         * obj4.transform.position = pos2;
         * obj4.transform.rotation = rot2;
         */
    }
Example #4
0
    void Update()
    {
        //姿勢取得ライブラリが初期化されていないとき初期化する
        //(OpenVRの初期化はEasyOpenVROverlayの方で行われるはずなので待機)
        if (!util.IsReady())
        {
            util.Init();
            return;
        }

        //HMDの位置情報が使えるようになった & 初期位置が初期化されていないとき
        if (util.GetHMDTransform() != null && PositionInitialize)
        {
            //とりあえずUnityスタート時のHMD位置に設定
            //(サンプル用。より適切なタイミングで呼び直してください。
            // OpenVRが初期化されていない状態では原点になってしまいます)
            setPosition();

            //初期位置初期化処理を停止
            PositionInitialize = false;
        }

        //カーソル位置を更新
        //オーバーレイライブラリが返す座標系をCanvasの座標系に変換している。
        //オーバーレイライブラリの座標サイズ(RenderTexture依存)と
        //Canvasの幅・高さが一致する必要がある。
        LeftCursorTextRectTransform.anchoredPosition  = new Vector2(EasyOpenVROverlay.LeftHandU - CanvasRectTransform.sizeDelta.x / 2f, EasyOpenVROverlay.LeftHandV - CanvasRectTransform.sizeDelta.y / 2f);
        RightCursorTextRectTransform.anchoredPosition = new Vector2(EasyOpenVROverlay.RightHandU - CanvasRectTransform.sizeDelta.x / 2f, EasyOpenVROverlay.RightHandV - CanvasRectTransform.sizeDelta.y / 2f);

        //移動モード処理
        if (isScreenMoving)
        {
            ulong button = 0;
            EasyOpenVRUtil.Transform pos  = util.GetHMDTransform(); //HMDが有効か調べる
            EasyOpenVRUtil.Transform cpos = null;                   //任意の手の姿勢情報
            if (screenMoveWithRight)                                //右手で操作されたなら
            {
                //右手のボタンが押されているか取得しながら、右手が有効か調べる
                if (util.GetControllerButtonPressed(util.GetRightControllerIndex(), out button))
                {
                    //有効なら右手の姿勢情報を取得する(瞬間的に通信が切れnullの可能性もある)
                    cpos = util.GetRightControllerTransform();
                }
            }
            else
            {
                //左手のボタンが押されているか取得しながら、右手が有効か調べる
                if (util.GetControllerButtonPressed(util.GetLeftControllerIndex(), out button))
                {
                    //有効なら左手の姿勢情報を取得する(瞬間的に通信が切れnullの可能性もある)
                    cpos = util.GetLeftControllerTransform();
                }
            }

            //ボタンが一切押されなくなったならば移動モードから抜ける
            if (button == 0)
            {
                isScreenMoving = false;
            }

            //HMDも取得したコントローラ姿勢も有効ならば
            if (pos != null && cpos != null)
            {
                //コントローラの姿勢クォータニオンを45度傾けて、オイラー角に変換(しないと意図しない向きになってしまう)
                Vector3 ang = (cpos.rotation * Quaternion.AngleAxis(45, Vector3.right)).eulerAngles;

                //コントローラの位置をそのままOverlayの位置に反映
                EasyOpenVROverlay.Position = cpos.position;                 //これが難しい...

                //コントローラの回転を適時反転させてOverlayの回転に反映(こちら向きにする)
                EasyOpenVROverlay.Rotation = new Vector3(-ang.x, -ang.y, ang.z);
            }
        }
    }
Example #5
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (!util.IsReady())
        {
            util.Init();
            return;
        }

        button = 0;

        Vector3 nowPos;

        if (controller == LR.Left)
        {
            util.GetControllerButtonPressed(util.GetLeftControllerIndex(), out button);
            nowPos = util.GetLeftControllerTransform().position;
        }
        else
        {
            util.GetControllerButtonPressed(util.GetRightControllerIndex(), out button);
            nowPos = util.GetRightControllerTransform().position;
        }

        /**
         * 加速度
         */
        float   deltaTime = 1; //1フレーム
        Vector3 v         = (nowPos - prePos) / deltaTime;
        Vector3 a         = (v - preV) / deltaTime;

        accele    = a * 10000;
        acceleAvg = Mathf.Sqrt(
            (a.x * a.x) +
            (a.y * a.y) +
            (a.z * a.z)
            );

        prePos = nowPos;
        preV   = v;

        /**
         * コードショット部分
         */
        if (isTriggerPressed)
        {
            //トリガー押されてる状態から離されるとコードを放つ
            if (button != ViveConstants.TRIGGER)
            {
                //ChordPadManager.instance.Ring(nowPos.y - 0.5f);
                Debug.Log(nowPos.y - 0.5f);
                isTriggerPressed = false;
            }
        }
        else
        {
            //トリガーが離されてる状態から押されるとコードを止める
            if (button == ViveConstants.TRIGGER)
            {
                //ChordPadManager.instance.Mute();
                isTriggerPressed = true;
            }
        }
    }
Example #6
0
    void Update()
    {
        if (!eou.IsReady())
        {
            eou.StartOpenVR();
        }

        if (HMD_Offset == null || LeftHand_Offset == null || RightHand_Offset == null)
        {
            HMD_Offset       = eou.GetHMDTransform();
            LeftHand_Offset  = eou.GetLeftControllerTransform();
            RightHand_Offset = eou.GetRightControllerTransform();
        }

        eou.AutoExitOnQuit();

        _config = configManager.GetConfig();

        HMDTrans       = eou.GetHMDTransform();
        LeftHandTrans  = eou.GetLeftControllerTransform();
        RightHandTrans = eou.GetRightControllerTransform();

        eou.SetGameObjectTransform(ref HMD, HMDTrans);
        eou.SetGameObjectTransform(ref LeftHand, LeftHandTrans);
        eou.SetGameObjectTransform(ref RightHand, RightHandTrans);

        eou.SetGameObjectTransformWithOffset(ref HMD_withOffset, HMDTrans, HMD_Offset);
        eou.SetGameObjectTransformWithOffset(ref LeftHand_withOffset, LeftHandTrans, LeftHand_Offset);
        eou.SetGameObjectTransformWithOffset(ref RightHand_withOffset, RightHandTrans, RightHand_Offset);

        ulong button;

        if (isFollowRightHand)
        {
            eou.GetControllerButtonPressed(eou.GetRightControllerIndex(), out button);
        }
        else
        {
            eou.GetControllerButtonPressed(eou.GetLeftControllerIndex(), out button);
        }
        if (button != 0)
        {
            V_Chest.SetActive(false);
            V_Foot_L.SetActive(false);
            V_Foot_R.SetActive(false);
            V_Offset.SetActive(false);
        }

        if (_config.isMenuLeftHand && LeftHandTrans != null && LeftHandTrans.velocity.y < -3.5f || _config.isMenuRightHand && RightHandTrans != null && RightHandTrans.velocity.y < -3.5f)
        {
            if (!MenuManager.IsActive() && (!_config.isMenuLock || _config.MenuLockButton == 0 || _config.MenuLockButton == button))
            {
                MenuManager.Open();
            }
        }
        else if (_config.isMenuLeftHand && LeftHandTrans != null && LeftHandTrans.velocity.y > 3.5f || _config.isMenuRightHand && RightHandTrans != null && RightHandTrans.velocity.y > 3.5f)
        {
            if (MenuManager.IsActive() && (!_config.isMenuLock || _config.MenuLockButton == 0 || _config.MenuLockButton == button))
            {
                MenuManager.Close();
            }
        }
    }