LoginSignup
0
0

More than 3 years have passed since last update.

【Unity(C#)】VIVE用にデバッグ時のリセット実装

Posted at

デバッグでPCまで戻るのめんどくさい

デバッグはしらみつぶしに行いたいのでキー入力でリセットの実装にしてると
何度もPCとプレイ位置を往復するのでめんどうです。

かなり短くてしょーもない記事ですが、今後毎回使いそうなのでメモします。

コード

ベースはまんま前の記事1ですが、、、

#if UNITY_EDITOR
using UnityEngine;
using UnityEngine.SceneManagement;
using Valve.VR;

public class DebugReload : MonoBehaviour
{
    [SerializeField]
    SteamVR_Input_Sources hand;

    [SerializeField]
    SteamVR_Action_Boolean grabAction;

    [SerializeField]
    float inputSeconds;

    bool preventContinuityPushButton;

    float timer;


    void Update()
    {

        if (grabAction.GetStateDown(hand))
        {
            preventContinuityPushButton = true;
        }

        if (grabAction.GetState(hand) == false)
        {
            timer = 0;
            return;
        }
        else if (grabAction.GetState(hand) && preventContinuityPushButton)
        {
            timer += Time.deltaTime;
        }

        if (timer > inputSeconds)
        {
            Scene loadScene = SceneManager.GetActiveScene();
            SceneManager.LoadScene(loadScene.name);
        }
    }
}
#endif

SteamVR 2.0からVIVEの入力回りは、最初に設定したアクションから取得する形になってます。
簡単に言えば、それぞれの入力にポーズ名が決まっているだけのことです。

今回はGripButtonの取得をしたいので、GrabGripを設定すればOKです。

image.png

Platform Dependent Compilation(プラットフォーム依存コンパイル)2

下記のようにEditor上のみでコンパイルする設定にしておけば、
実行ファイル形式で書きだした際に、変な機能が残ったままにならないので便利です。

#if UNITY_EDITOR

#endif
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0