参考:
http://martinecker.com/martincodes/unity-editor-window-zooming/
http://answers.unity3d.com/questions/38224/how-can-i-zoom-out-properly-within-a-editorwindow.html
方法1:
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour
{
private Vector2 scale = new Vector2(1, 1);
private Vector2 pivotPoint;
void OnGUI()
{
Matrix4x4 oldMatrix = GUI.matrix;
pivotPoint = new Vector2(Screen.width / 2, Screen.height / 2);
GUIUtility.ScaleAroundPivot(scale, pivotPoint);
if (GUI.Button(new Rect(Screen.width / 2 - 25, Screen.height / 2 - 25, 50, 50), "Big!"))
scale += new Vector2(0.5F, 0.5F);
GUI.matrix = oldMatrix;
if (GUI.Button(new Rect(Screen.width / 2 + 25, Screen.height / 2 - 25, 50, 50), "Big!"))
scale += new Vector2(0.5F, 0.5F);
}
}
方法2:
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class ZoomTestWindow : EditorWindow
{
[MenuItem("Window/Zoom Test")]
private static void Init()
{
ZoomTestWindow window = EditorWindow.GetWindow<ZoomTestWindow>(false, "Zoom Test");
window.minSize = new Vector2(600.0f, 300.0f);
window.wantsMouseMove = true;
window.Show();
//EditorWindow.FocusWindowIfItsOpen();
}
private const float kZoomMin = 0.1f;
private const float kZoomMax = 10.0f;
private readonly Rect _zoomArea = new Rect(0.0f, 75.0f, 600.0f, 300.0f - 100.0f);
private float _zoom =