Search Unity

toggle between 2d and Google Cardboard

Discussion in 'AR/VR (XR) Discussion' started by lz7cjc, May 31, 2020.

  1. arfish

    arfish

    Joined:
    Jan 28, 2017
    Posts:
    782
    Last edited: Oct 5, 2021
    mawiplay likes this.
  2. mawiplay

    mawiplay

    Joined:
    Sep 29, 2021
    Posts:
    5
    Ok. I selected the Build Settings with Mac as the target platform. Then I created and added the script including #if UNITY_EDITOR
    Currently, I used a sample scene from https://github.com/googlevr/cardboard-xr-plugin named: HelloCardboard.unity
    I would like to test it on my laptop but there is no navigation or interaction available by default.
    How to navigate without a headset?
    thank you!
     
  3. arfish

    arfish

    Joined:
    Jan 28, 2017
    Posts:
    782
    Have you tried to just rotate, and/or drag the camera in the scene while running the game in the Editor?
     
    mawiplay likes this.
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
    mawiplay likes this.
  5. mawiplay

    mawiplay

    Joined:
    Sep 29, 2021
    Posts:
    5
    Thank you. I created separate scripts for #if UNITY_EDITOR
    Currently, the console log displays the following:

    Please initialize Cardboard XR loader before calling this function.
    UnityEngine.Debug:LogError (object)
    Google.XR.Cardboard.Api:UpdateScreenParams () (at Library/PackageCache/com.google.xr.cardboard@d9f0aa2eb0/Runtime/Api.cs:295)
    CardboardStartup:Update () (at Assets/Samples/Google Cardboard XR Plugin for Unity/1.8.0/Hello Cardboard/Scripts/CardboardStartup.cs:70)

    I understand the loader needs to be initialized. What should I do these scripts?
     
  6. mawiplay

    mawiplay

    Joined:
    Sep 29, 2021
    Posts:
    5
    Yes and it is possible to rotate, drag the camera in the scene while running the game
     
    arfish likes this.
  7. arfish

    arfish

    Joined:
    Jan 28, 2017
    Posts:
    782
    You don't need any extra script for the error message.
    Just find from where the line Google.XR.Cardboard.Api:UpdateScreenParams () is called, and surround it with the platform directive to prevent from being called in the Editor.

    Code (CSharp):
    1. #if !UNITY_EDITOR
    2. UpdateScreenParams();
    3. #endif
     
    mawiplay likes this.
  8. mawiplay

    mawiplay

    Joined:
    Sep 29, 2021
    Posts:
    5
    Ok, thank you. I corrected the code. The console log displays the following:
    UnityEditor.SceneView:ShowCompileErrorNotification () (at /Users/bokken/buildslave/unity/build/Editor/Mono/SceneView/SceneView.cs:3703)
    which is this type of error and how could i fix it?
     
  9. Johnny_Mauser

    Johnny_Mauser

    Joined:
    Mar 30, 2017
    Posts:
    2
    Hi DarkVerse, I am a newbee in Unity but want to do the same thing. Did you get to it? Best, Johnny
     
  10. DarkVerse

    DarkVerse

    Joined:
    Jan 9, 2017
    Posts:
    57
    Hi Johnny,

    sorry for the delay, I have been away from Unity for a while and just came back here as I am supporting an old project.

    My recollection was that I was not able to get switching on demand to work without crashing. I was able to get around it only because my use case could be tweaked to allow the user to select whether they wanted magic window mode or VR mode on startup and once selected they remained in that mode. If they wanted a different mode they would have to exit the app and start again, selecting a different mode. Not ideal by any means, but acceptable in my case.