Ejemplo n.º 1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        //初期化されていないとき初期化する
        if (!util.IsReady())
        {
            util.Init();
            return;
        }

        //fpsに依存しない更新にする
        util.SetAutoUpdate(false);
        util.ClearPredictedTime();
        util.Update();

        //フレームタイミングを表示
        FrameTiming = FrameTiming * 0.99 + util.GetCompositorFrameTime() * 0.01f;

        FPSMonitor2.text = String.Format("{0:###.#}", FrameTiming + 0.05f);
        //30fpsを切ったら自動でセーフモードへ
        if (FrameTiming > 33.3)
        {
            ResoMan.LowResolution(false);
        }

        //秒に一回Battery残量を反映
        if (BatteryUpdateTimer > 1.0f)
        {
            //コントローラ
            batteryWorker.PercentL = util.GetDeviceBatteryPercentage(util.GetLeftControllerIndex()) / 100.0f;
            batteryWorker.PercentR = util.GetDeviceBatteryPercentage(util.GetRightControllerIndex()) / 100.0f;

            //トラッカー
            List <uint> list = util.GetViveTrackerIndexList();
            if (list.Count > 0)
            {
                batteryWorker.PercentT1 = util.GetDeviceBatteryPercentage(list[0]) / 100.0f;
            }
            else
            {
                batteryWorker.PercentT1 = float.NaN;
            }
            if (list.Count > 1)
            {
                batteryWorker.PercentT2 = util.GetDeviceBatteryPercentage(list[1]) / 100.0f;
            }
            else
            {
                batteryWorker.PercentT2 = float.NaN;
            }
            if (list.Count > 2)
            {
                batteryWorker.PercentT3 = util.GetDeviceBatteryPercentage(list[2]) / 100.0f;
            }
            else
            {
                batteryWorker.PercentT3 = float.NaN;
            }

            BatteryUpdateTimer = 0f;
        }
        else
        {
            BatteryUpdateTimer += Time.deltaTime;
        }


        //コントローラのボタン入力と取得可能かをチェック
        ulong Leftbutton = 0, Rightbutton = 0, HMDbutton = 0;
        bool  leftok  = util.GetControllerButtonPressed(util.GetLeftControllerIndex(), out Leftbutton);
        bool  rightok = util.GetControllerButtonPressed(util.GetRightControllerIndex(), out Rightbutton);
        //bool hmdok = util.GetControllerButtonPressed(util.GetHMDIndex(), out HMDbutton);

        /*
         * if (hmdok) {
         *  if ((HMDbutton & 0x80000000) != 0)
         *  {
         *      //かぶってる
         *  }
         *  else {
         *      //かぶってない
         *  }
         * }*/

        //左手の加速度を取得(左手が有効な場合)
        Vector3 leftHandVelocity = Vector3.zero;

        if (leftok && config.detectLeftHand)
        {
            var trans = util.GetLeftControllerTransform();
            if (trans != null)
            {
                leftHandVelocity = trans.velocity;
            }
        }

        //右手の加速度を取得(右手が有効な場合)
        Vector3 rightHandVelocity = Vector3.zero;

        if (rightok && config.detectRightHand)
        {
            var trans = util.GetRightControllerTransform();
            if (trans != null)
            {
                rightHandVelocity = trans.velocity;
            }
        }

        //タップロック反映
        if (config.taplockmode)
        {
            if ((Leftbutton == config.unlockkey) || (Rightbutton == config.unlockkey))
            {
                //ボタンが押されているとき
                eovro.tapEnable = true;

                CursorL.locked = false;
                CursorR.locked = false;
            }
            else
            {
                //ボタンが押されていないとき
                eovro.tapEnable = false;

                CursorL.locked = true;
                CursorR.locked = true;
            }
        }
        else
        {
            //ロック関係なし
            eovro.tapEnable = true;

            CursorL.locked = false;
            CursorR.locked = false;
        }

        //ピーク検出
        if (AccelerationPeak < Math.Abs(leftHandVelocity.y))
        {
            AccelerationPeak = Math.Abs(leftHandVelocity.y);
            PeakText.text    = string.Format("Acceleration\nSet: {0:#.#}", AccelerationPeak);
        }
        if (AccelerationPeak < Math.Abs(rightHandVelocity.y))
        {
            AccelerationPeak = Math.Abs(rightHandVelocity.y);
            PeakText.text    = string.Format("Acceleration\nSet: {0:#.#}", AccelerationPeak);
        }

        //腕振り下ろしを判定
        if (leftHandVelocity.y < -config.speeddown)
        {
            //ロックモードではない or グリップボタンだけが押されている(&ロックモード)
            if (!config.lockmode || (Leftbutton == config.unlockkey))
            {
                menu.IsRightHand = false;
                if (menu.showing == false)
                {
                    menu.MenuStart = true;
                    MissSwingTime  = Time.time; //現在時刻を記録
                }
                else
                {
                    //空振り

                    //メニューを出してから十分時間経ってるのに振った
                    if (Time.time > MissSwingTime + 1)
                    {
                        AudioMan.PlayCancelSound(); //振りミス音を鳴らす
                        MissSwingTime = Time.time;  //現在時刻を記録
                    }
                }
            }
        }
        if (rightHandVelocity.y < -config.speeddown)
        {
            //ロックモードではない or グリップボタンだけが押されている(&ロックモード)
            if (!config.lockmode || (Rightbutton == config.unlockkey))
            {
                menu.IsRightHand = true;
                if (menu.showing == false)
                {
                    menu.MenuStart = true;
                    MissSwingTime  = Time.time; //現在時刻を記録
                }
                else
                {
                    //空振り

                    //メニューを出してから十分時間経ってるのに振った
                    if (Time.time > MissSwingTime + 1)
                    {
                        AudioMan.PlayCancelSound(); //振りミス音を鳴らす
                        MissSwingTime = Time.time;  //現在時刻を記録
                    }
                }
            }
        }

        //腕振り上げ判定
        if (leftHandVelocity.y > config.speedup || rightHandVelocity.y > config.speedup)
        {
            //ロックモードではない or グリップボタンだけが押されている(&ロックモード)
            if (!config.lockmode || (Rightbutton == config.unlockkey) || (Leftbutton == config.unlockkey))
            {
                menu.MenuEndFunc(0);
            }
        }

        //腕横振り判定
        if (Math.Abs(leftHandVelocity.z) > config.speedup && config.slideClose)
        {
            //ロックモードではない or グリップボタンだけが押されている(&ロックモード)
            if (!config.lockmode || Leftbutton == config.unlockkey)
            {
                //方向判定
                if (leftHandVelocity.z < 0)
                {
                    menu.MenuEndFunc(1);
                }
                else
                {
                    menu.MenuEndFunc(2);
                }
            }
        }
        if (Math.Abs(rightHandVelocity.z) > config.speedup && config.slideClose)
        {
            //ロックモードではない or グリップボタンだけが押されている(&ロックモード)
            if (!config.lockmode || Rightbutton == config.unlockkey)
            {
                //方向判定
                if (rightHandVelocity.z < 0)
                {
                    menu.MenuEndFunc(1);
                }
                else
                {
                    menu.MenuEndFunc(2);
                }
            }
        }


        //Debug.Log(util.GetRightControllerTransform().velocity.x);
    }