Maximize Unity in Windows like a normal application

Hi,

I’m using Unity to build a GUI like application and need it to maximize / restore like a normal application (to any monitor). I also want it to remember its last application window state (location, size, maximized) and allow it to stretch.

I have created a system like this in TGE, but I’m struggling a bit with Unity.

I have the Pro version, and am trying to write a plugin. It seems the issues are:

  1. Getting the Unity window
  2. Setting the window to a non-standard resolution

Do I need to set the resolution in order to maximize the window? When I’ve programmed 3d apps from scratch I was able to change the projection of the window without the underlying resolution.

I haven’t played with 2.5, but it seems like it will probably have a maximize button and remember window states, so it must be possible to do this in Unity, since it is said that this is programmed in Unity.

Also it seems like the web player is already able to partially do this, as you can dynamically scale the content.

Any help is appreciated,

Ryan

I can’t help with the general plugin questions so I’ll leave that for other responders but…

Assume nothing. In fact, we’ve repeatedly stated this: do not expect run-time features in the 2.5 release. Unity 2.5 is heavily focused on authoring changes, not only bringing the editor to Windows but a new tabbed interface, enhanced editor customization, etc. What you cited is definitely not coming in Unity 2.5.

The ability to break our content out of the window (app window or browser) is there today, you can go full screen any time you want (desktop or web). The hitch here is that you want to resize the containing window and that’s not at all the same thing, thus the extra hijynx needed.

I don’t want to turn this thread into a 2.5 feature thread, but just to be clear, are you stating that in Unity 2.5 you will not be able to maximize or dynamically resize the authoring window(s)?

Thanks,

Ryan

I was under the impression that your questions had nothing at all to do with authoring window resizing, that they were about resizing the content windows in the run-time environment. Of course you can resize authoring Windows and/or go full screen with them.

I have not yet been able to get maximizing working as a plugin, but I have been able to get something nice working using a c# web browser object. The downsides are that since it is in a web browser the Unity plugin must be installed, plus the pro-only .dll plugins can’t be used in the web browser version.

The following solution embeds Unity in a window that looks like a standard Microsoft Windows window (this is a solution for Microsoft Windows). You can maximize, minimize, and dynamically scale the window using the window’s borders. In addition the last position, size and state (maximized/not-maximized) is saved and restored. This code also will ensure the window is not lost on a secondary monitor that is disconnected, and will only restore the last windows size/position/state if it is visible in the current monitor set up.

The attached .zip file contains a complete example including a Unity example .unity3d / .html file, the C# source (Visual Studio 2005), which you will need in order to set the window title (and icon) of your game, as well as to change the registry key where the window settings are stored.

The C# project loads an .html file that is set to maximize the .unity3d file to the web browser, which is maximized to the C# main window, which results in the maximizable and resizable Unity game window. If you want to change the name of the .unity3d file you will need to edit the .html file. If you want to change the name of the .html file you will need to change the file loaded in the C# project.

Make sure that in the final project the executable from the C# project, the .html file, and the .unity3d file are all in the same directory. You could also specify a remote file in the C# project if you wanted to make a remote http:// file look and act more like local content.

To test this just download the attached UnityFrame.zip file, unzip it, and run the UnityFrame/UnitFrame.exe file.

You will notice that when you scale your game, any gui elements will stay in their current location unless you specify otherwise. Since I store my gui rects elsewhere, I need to check for resolution changes and dynamically update my gui, you may need to do the same. I do this like this:

void OnGUI () 
{
  CheckIfResolutionChanged();
  if (!guiSetup) 
  {
    guiSetup = true;
    SetupGui();
  }
  ...
}

private void CheckIfResolutionChanged() {
  if (screenWidth != Screen.width  || screenHeight != Screen.height) {
    screenWidth = Screen.width;
    screenHeight = Screen.height; 
    guiSetup = false; 
  }
}

private void SetupGui() {
  [Calculate any gui stuff that is not calculated every frame, that is based on the window size]
}

131666–4894–$unityframe_147.zip (73.2 KB)

1 Like

To all you programmers creating Unity, it would be great to get something like this integrated into the Unity projects that can be built with Unity.

The Unity 2.5 for Windows editor has something similar. It remembers window placement, but doesn’t remember maximization creating a small error if you close Unity while maximized and reopen it, as the window is a little too big, and not maximized, so it extends off the screen (I have two screens) either to the left or right. Of course feel free to use any of the code I posted above. I would just love to have these features available in the projects created with Unity. It would open Unity up to more app development, which is one of the things I am using it for, including applications that have both 2d and 3d features mixed together.

Thanks,

Ryan

1 Like