Custom Editor Resolution Presets?

Is it possible to add your own resolution presets to the editor’s game panel?

The little drop-down at the top-left of the game panel.

None of the existing ones fit the phone I’m developing on (HTC Sensation). I’d like to know that what I see in the editor is what I see on my phone.

No thats not possible

Well, arse :frowning:

++ This would be so useful.

(You can make a web build of any resolution, but that is a round about solution)

well you always have the dirty solution:

  1. Get the game window into the right size while its embedded in the window layout and aspect ratio free
  2. store the layout :smile:

I ran into some of the same problem. I threw togather a small c# script that will draw a black box in the lower right had corner of the window so I can size it accordingly. The resolution can be set in the editor.

using UnityEngine;

[ExecuteInEditMode]
public class PlaybackWindowSizer : MonoBehaviour {

	public Vector2 resolution;
	
	void OnGUI()
	{	
		GUI.Box(new Rect(resolution.x - 5, resolution.y -5, 5, 5), string.Empty);
	}
}

Ok, I spent way too much time on this today. This script will show common mobile device screen sizes on a GUI. The actual window size is shown in the top left corner. This script just needs to be attached to a game object.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

[ExecuteInEditMode]
public class PlaybackWindowSizer : MonoBehaviour {

	private static KeyValuePair<int, int>[] resolutions = new KeyValuePair<int, int>[]{
		new KeyValuePair<int, int>(320, 240),  // 4:3 Very Common
		new KeyValuePair<int, int>(400, 240),  // 5:3 Samsung Intercept, Uncommon
		new KeyValuePair<int, int>(800, 480),  // 5:3 Very Common
		new KeyValuePair<int, int>(854, 480),  // 16:9 Motorola Droid
		new KeyValuePair<int, int>(960, 540),  // 16:9 Becoming Common on high end phones
		new KeyValuePair<int, int>(1024, 600),  // 16:9 Tablet
		new KeyValuePair<int, int>(800, 600),  // 4:3 Tablet
		new KeyValuePair<int, int>(1200, 800),  // 3:2 Tablet
		new KeyValuePair<int, int>(1200, 800),  // 3:2 Tablet
		new KeyValuePair<int, int>(1024, 768),  // 4:3 iPad
		new KeyValuePair<int, int>(960, 640)  // 3:2 iPhone
	};
	
	void OnGUI()
	{
		// Only show the overlay in the editor
		if(Application.platform != RuntimePlatform.WindowsEditor  
		   Application.platform != RuntimePlatform.OSXEditor)
			return;
		
		GUIStyle lowerRightAligned = new GUIStyle();
		lowerRightAligned.alignment = TextAnchor.LowerRight;
		
		foreach (KeyValuePair<int, int> res in resolutions)
		{
			//GUI.Box(new Rect(resolution.x - 5, resolution.y -5, 5, 5), string.Empty);
			GUILayout.BeginArea(new Rect(res.Key - 55, res.Value - 15, 50, 15));
			GUILayout.BeginHorizontal();
			GUILayout.FlexibleSpace();
			GUILayout.Label(res.Key + "x" + res.Value, lowerRightAligned, GUILayout.ExpandHeight(true));
			GUILayout.EndHorizontal();
			GUILayout.EndArea();
			GUI.Box(new Rect(res.Key - 7, res.Value - 7, 5, 5), string.Empty);
		}
		
		// Show the current window size
		GUI.Label(new Rect(0, 0, 50, 20), Screen.width + "x" + Screen.height);
	}
}

Looking at the resolutions all on the same screen made me realize what a huge difference there is between the higher and lower end phones and tablets.

Best of luck,

Alpaca of Zion

That’s really cool dude, thank you :slight_smile:

Alpaca Of Zion: That is a really, really useful script. Thank you!

Okay, that’s so weird. I’ve always had a selection of iOS sizes to choose from…
So where the heck did these come from?

I’m using PlayMaker, iGUI and Prime31’s GameKit. Do any of these provide this kind of function?
:face_with_spiral_eyes:

695435--25047--$Screen shot 2011-09-22 at 12.27.32 PM.jpg

These sizes automatically are there if the project is an iOS project

so it’s only droid that’s not supported out of the box like this. Bummer.

Ladies Gentlemen,
I too was upset by the lack of support for awkward custom dimensions on android, and not being one to let go of a bone I decided to knock up a script as follows.
its not as elegant as it could be but hey it does the job.
Several requirements are
Game View must be undocked.
Game View Size must be set to free aspect.
In play mode you need to move the mouse over the game view before it can do anything with it(theres no way I can see of it looking for the game view by itself)

this script should be attached to any old game object in the scene (it could probably work as an editor script if I tried but hey it does the job)
you can set the width height using the public Vector2

As you will see said script will continue to set the game view size until Master is set to false.

Enjoy
Just noticed that my ezgui control layout means that once my script has resized my game view I need to just stop start it so they layout nicely. but otherwise it works well enough for what I need.

Alpaca, I noticed when I quit in the editor with your script, my game still seems to show the last rendered frame in the game view window. I was wondering if you knew what was causing this? I’m trying to figure out how to clear the game view window, but no success yet.

Thanks dude, can’t believe I didn’t think of doing this… bit slow today.

The code below is a better approach.
-No need to attach it to a game object. Just place it in the Editor folder.
-Automatic undocking.
-Automatic game window creation if it doesn’t exist.
-Window edge does not disappear.
-Automatic free aspect ratio.
-No need to move mouse over Game window.

Credits to jspease, from here:

using System;
using UnityEditor;
using UnityEngine;
 
public class GameWindowSize
{
    private static Vector2 position = new Vector2(100f, 100f);
    private static int menuOffset = 17;

    [MenuItem("Window/Game Window Size/320x480", false, 99)]
    public static void Size1()
    {
        // initialize window-specific title data and such (this can be cached)
        WindowInfos windows = new WindowInfos();
		windows.game.isOpen = false; //workaround for setting free aspect ratio
        windows.game.position = new Rect(position.x,position.y,320,480+menuOffset); // left,top,width,height
    }

	[MenuItem("Window/Game Window Size/800x1280", false, 99)]
    public static void Size2()
    {
        // initialize window-specific title data and such (this can be cached)
        WindowInfos windows = new WindowInfos();
		windows.game.isOpen = false; //workaround for setting free aspect ratio
        windows.game.position = new Rect(position.x,position.y,800,1280+menuOffset); // left,top,width,height
    }

 
    class WindowInfos
    {
        // note: some of this data might need to change a little between different versions of Unity
        public WindowInfo game = new WindowInfo("UnityEditor.GameView", "Game", "Window/Game");
    }
 
    class WindowInfo
    {
        string defaultTitle;
        string menuPath;
        Type type;
 
        public WindowInfo(string typeName, string defaultTitle=null, string menuPath=null, System.Reflection.Assembly assembly=null)
        {
            this.defaultTitle = defaultTitle;
            this.menuPath = menuPath;
 
            if(assembly == null)
                assembly = typeof(UnityEditor.EditorWindow).Assembly;
            type = assembly.GetType(typeName);
            if(type == null)
                Debug.LogWarning("Unable to find type \"" + typeName + "\" in assembly \"" + assembly.GetName().Name + "\".\nYou might want to update the data in WindowInfos.");
        }
 
        public EditorWindow[] FindAll()
        {
            if(type == null)
                return new EditorWindow[0];
            return (EditorWindow[])(Resources.FindObjectsOfTypeAll(type));
        }
 
        public EditorWindow FindFirst()
        {
            foreach(EditorWindow window in FindAll())
                return window;
            return null;
        }
 
        public EditorWindow FindFirstOrCreate()
        {
            EditorWindow window = FindFirst();
            if(window != null)
                return window;
            if(type == null)
                return null;
            if(menuPath != null  menuPath.Length != 0)
                EditorApplication.ExecuteMenuItem(menuPath);
            window = EditorWindow.GetWindow(type, false, defaultTitle);
            return window;
        }
 
        // shortcut for setting/getting the position and size of the first window of this type.
        // when setting the position, if the window doesn't exist it will also be created.
        public Rect position
        {
            get
            {
                EditorWindow window = FindFirst();
                if(window == null)
                    return new Rect(0,0,0,0);
                return window.position;
            }
            set
            {
                EditorWindow window = FindFirstOrCreate();
                if(window != null)
                    window.position = value;
            }
        }
 
        // shortcut for deciding if any windows of this type are open,
        // or for opening/closing windows
        public bool isOpen
        {
            get
            {
                return FindAll().Length != 0;
            }
            set
            {
                if(value)
                    FindFirstOrCreate();
                else
                    foreach(EditorWindow window in FindAll())
                        window.Close();
            }
        }
    }
}

Edit:
You can find a more complete solution here:
http://wiki.unity3d.com/index.php/MobileSimulator

It is now! :slight_smile: Check out my Resolution Presets asset!