Unity3D Rift GameView Maximizer

Talk about Head Mounted Displays (HMDs), augmented reality, wearable computing, controller hardware, haptic feedback, motion tracking, and related topics here!
Post Reply
WiredEarp
Golden Eyed Wiseman! (or woman!)
Posts: 1498
Joined: Fri Jul 08, 2011 11:47 pm

Unity3D Rift GameView Maximizer

Post by WiredEarp »

A few weeks back, I wrote a brief C++ script for myself to maximize the Unity GameView window to the Rift when I click 'Play'. After finishing this, I found several other scripts that did a similar things (such as one by sbNewsom), however, none of the ones I saw automatically detected the Rift window/resolution, or worked without changing some variables if you had different monitor resolutions or configurations, or restored the GameView to its original location on Stop (since then, I have seen one by ggodin that automatically detects the Rift, but I think it also requires Virtual Desktop). However, I did like the way they integrated into Unity better. Not being one to be outdone, I rewrote my script into a native Unity3D script, since I thought it might be useful for others until Unity or Oculus builds in this functionality (hopefully in Unity 5?). Besides automatically maximizing, it also preserves your existing Unity3D window layout, so when you click Stop, the GameView returns to the position it was in previously. I find this handy, as often I just want to click Play to check out a gameplay feature, but don't wish to have to put on the Rift every time. The toggle GameView button is also useful for quickly switching the view at any time. I posted this on reddit recently, but thought it might be better to keep it here as mtbs3d is quite a bit superior in terms of attaching files and screenshots etc.

Main features are:
  • - Integrates as a tiny dockable window in Unity3D
    - Automatically detect Rift monitor and maximize to it when Play is clicked (without any required config)
    - Disables buttons based on whether Rift is active or not
    - Restores layout on Stop
    - Toggle GameView button (switches the GameView between full screen on the Rift and normal - works even when game is running)
    - Does nothing if Rift is not detected
    - Save/restore layout buttons for easily saving a custom layout
To use, simply create an Editor folder under your Assets folder in Unity3D (if one doesn't already exist), save the script as a .cs file with the name 'MaxGameWindowToRift.cs', and place it there. To use, click 'Window/Maximize GameView To Rift', and dock the window (or leave it floating if you prefer). When the checkbox ('Maximize GameView To Rift') is checked, clicking Play will maximize the window to the Rift. If the Rift is not turned on, nothing will happen. Please note that the Max To Rift window must be docked or active.
The 'Restore Normal layout' button is simply a button that will run a window layout called 'Normal', which can be handy if you wish to restore your windows if they get screwed up for some reason.

I use Pro, so am not sure if this will work on free Unity3D - so if it doesn't work, please let me know your system and I'll see if I can modify it to get it going for you. Also, you are free to modify it yourself (and hopefully, post a new version if you add new features). Any other suggestions, bug reports, etc, are welcomed. The current version is V1.21. I'll attach it here, but the latest version should also always be here: http://pastebin.com/HguANyxL

EDIT 19/04/2015: Updated to V1.21 with Unity 5 compatibility and some other enhancements.
MaxToRift tiny.png
MaxGameWindowToRift V1.21
MaxGameWindowToRift.zip
You do not have the required permissions to view the files attached to this post.
Last edited by WiredEarp on Sat Apr 18, 2015 9:36 am, edited 4 times in total.
User avatar
cybereality
3D Angel Eyes (Moderator)
Posts: 11407
Joined: Sat Apr 12, 2008 8:18 pm

Re: Unity3D Rift GameView Maximizer

Post by cybereality »

Very cool.
Post Reply

Return to “General VR/AR Discussion”