An evil workaround-hack for custom windows would be applying a translation matrix before scaling and then revert the translation. That way you can move the vanishing point for scaling to a fix position within the window.
Matrix4x4 before = GUI.matrix;
//Scale my gui matrix
Matrix4x4 Translation = Matrix4x4.TRS(new Vector3(0,25,0),Quaternion.identity,Vector3.one);
Matrix4x4 Scale = Matrix4x4.Scale(new Vector3(zoomScale, zoomScale, zoomScale));
GUI.matrix = Translation*Scale*Translation.inverse;
//Draw my zoomed GUI
DrawGUI();
//reset the matrix
GUI.matrix = before;
edit
Here’s an example editorwindow:
using UnityEngine;
using UnityEditor;
public class ScaleTest : EditorWindow
{
[MenuItem("Window/ScaleTest")]
static void Init()
{
EditorWindow.GetWindow(typeof(ScaleTest));
}
float zoomScale = 1.0f;
Vector2 vanishingPoint = new Vector2(0,21);
void OnGUI()
{
Matrix4x4 oldMatrix = GUI.matrix;
//Scale my gui matrix
Matrix4x4 Translation = Matrix4x4.TRS(vanishingPoint,Quaternion.identity,Vector3.one);
Matrix4x4 Scale = Matrix4x4.Scale(new Vector3(zoomScale, zoomScale, 1.0f));
GUI.matrix = Translation*Scale*Translation.inverse;
// Draw the GUI
GUI.Button(new Rect(0, 0 , position.width*1.5f, 30),"Foo");
GUI.Button(new Rect(0, 35, 50, 30),"Bar");
EditorGUI.FloatField(new Rect(0, 70, 50,30),0.0f);
//reset the matrix
GUI.matrix = oldMatrix;
// Just for testing (unscaled controls at the bottom)
GUILayout.FlexibleSpace();
vanishingPoint = EditorGUILayout.Vector2Field("vanishing point",vanishingPoint);
zoomScale = EditorGUILayout.Slider("zoom",zoomScale,1.0f/25.0f,2.0f);
}
}
But as i said already the EditorGUI stuff is not designed to be scaled. You will get a strange behaviour. If you want to scale it down to have more space to draw, that won't work because GUI.matrix also affects the clipping rect of the window. If you scale down the GUI, the drawable area will also shrink.
Here's an overview how it works:
second edit
I just found a built in function that do the same but even better :D. The EditorGUI problem will be the same (clip rect and mouse cursor) but you can specify the vanishing point in client coordinates like you do with all the GUI stuff.
That will scale around the "client coordinate" [0,0].
`GUIUtility.ScaleAroundPivot(Vector2.one * zoomScale,Vector2.zero);`