Unity Editor Window Zooming

这篇博客介绍了在Unity编辑器中实现窗口缩放的方法,包括两种不同的实现方式,并引用了算法来说明从给定点缩放图像的过程。通过将平移和缩放转换为矩阵运算,可以有效地进行窗口缩放操作。
摘要由CSDN通过智能技术生成


参考:

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 = 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值