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)