Code Monkey home page Code Monkey logo

Comments (14)

smdol avatar smdol commented on May 21, 2024

If you mean to render OnGUI in VR, see the Legacy/DemoScene which has an example of doing that.

from gvr-unity-sdk.

miketucker avatar miketucker commented on May 21, 2024

Thanks for your advice. I'd like to do an old-fashioned OnGUI directly onto the screen frame. The legacy example appears to render the GUI to a render texture which is then imposed in the 3d environment (see screengrab):

screen

from gvr-unity-sdk.

smdol avatar smdol commented on May 21, 2024

Is this GUI meant to be in VR mode or out of VR mode?

from gvr-unity-sdk.

miketucker avatar miketucker commented on May 21, 2024

the gui will simply be a static button locked to the corner of the screen that toggles between regular and VR mode. Traditionally this could be done with an OnGUI(){ GUI.Button()... but this is being overwritten by the SDK's rendering.

from gvr-unity-sdk.

smdol avatar smdol commented on May 21, 2024

If you are willing to modify the Cardboard.cs script slightly, you can get something to draw on the screen after the stereo view is done. That would be in the EndOfFrame() function. You can use CardboardOnGUIWindow script as well. Which version of the Cardboard SDK are you using? (The exact way to do this depends on the version.)

from gvr-unity-sdk.

miketucker avatar miketucker commented on May 21, 2024

That did it, thanks! It was a little fiddly to capture touch inputs because OnGUI can occur more than once per frame, but that hook allows GUI textures to be rendered correctly. (Using latest version btw)

Maybe for the next version there could be a standardized way of toggling Cardboard mode? I'd imagine there will be many apps that want to support it, but don't necessarily want to maintain two separate apps on the store.

from gvr-unity-sdk.

ro4tub avatar ro4tub commented on May 21, 2024

hello @miketucker Could the buttons in legacy DemoScene receive any input?
In my built demo, the buttons can't be touchable on a mobile phone.

from gvr-unity-sdk.

miketucker avatar miketucker commented on May 21, 2024

@ro4tub

In Cardboard.cs add this to the header:

public delegate void CardboardOnGUIEvent();
public event CardboardOnGUIEvent OnGUIRender;

and in the EndOfFrame function:

 if(OnGUIRender != null) OnGUIRender();

This will provide a hook for doing regular OnGUI stuff.
Then in your script with the GUI:

void Start(){
     cardboard.OnGUIRender += HandleOnGUIRender;
}

void OnDestroy(){
     cardboard.OnGUIRender -= HandleOnGUIRender;
}

void OnGUI(){
    HandleOnGUIRender();
}

void HandleOnGUIRender(){
    if(GUI.Button ...
}

The key thing here is that Unity will continue to check for mouse/touch button events with the OnGUI function, and the new event hook will allow it to be rendered properly by Cardboard

from gvr-unity-sdk.

ro4tub avatar ro4tub commented on May 21, 2024

@miketucker
It works well on Editor, but failed on Phone.
Is it ok on your phone?

from gvr-unity-sdk.

smdol avatar smdol commented on May 21, 2024

@ro4tub The new 0.5.1 release should fix the missing java function bug.

from gvr-unity-sdk.

smxthereisonlyone avatar smxthereisonlyone commented on May 21, 2024

@smdol It works on iPhone but not on Android, why? I amusing 0.5.1

from gvr-unity-sdk.

smdol avatar smdol commented on May 21, 2024

@smxthereisonlyone Try turning off TapIsTrigger on the Cardboard script. That setting makes screen touches look like magnet trigger events (which only happens on Android but not iPhone).

from gvr-unity-sdk.

smxthereisonlyone avatar smxthereisonlyone commented on May 21, 2024

@smdol But then there is no build in solution to register button events for the new cardboard v2?

from gvr-unity-sdk.

smdol avatar smdol commented on May 21, 2024

You can see screen taps either with Input.touches or Input.GetMouseButtonDown(0).

from gvr-unity-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.