Closed miketucker closed 8 years ago
If you mean to render OnGUI in VR, see the Legacy/DemoScene which has an example of doing that.
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):
Is this GUI meant to be in VR mode or out of VR mode?
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.
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.)
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.
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.
@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
@miketucker It works well on Editor, but failed on Phone. Is it ok on your phone?
@ro4tub The new 0.5.1 release should fix the missing java function bug.
@smdol It works on iPhone but not on Android, why? I amusing 0.5.1
@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).
@smdol But then there is no build in solution to register button events for the new cardboard v2?
You can see screen taps either with Input.touches or Input.GetMouseButtonDown(0).
The new CardboardGUI is great for VR, but I'd like to add a traditional button to toggle Cardboard mode on/off. However, all OnGUI rendering seems to be overwritten.
Is there any way to still render a GUI.Button or GUI.Texture?
thanks!