关于unityUI拖拽的问题

问题遇到的现象和发生背景

这里在开发一个editor,老板给我的要求是让整个UI可以实现自由拖拽和缩放。UI上有很多小组件,要求是让它们可以一起被拖拽及缩放。我现在已经实现了缩放功能,其实就是把所有小组件挂在一个大的panel上面。但是关于拖拽,出现了一点问题。我现在使用的是Ondrag方法,但是这个方法只有在点击Panel组件时才能实现拖拽。我的老板希望我在点击背景时也可以随意拖拽缩放。所以现在我想要知道该如何实现这个功能。

问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法

我现在使用的代码:
using UnityEngine;
using UnityEngine.EventSystems;

public class DragUI : MonoBehaviour, IDragHandler, IPointerDownHandler
{

private Vector2 offsetPos;  


public void OnDrag(PointerEventData eventData)
{
    transform.position = eventData.position - offsetPos;
}

public void OnPointerDown(PointerEventData eventData)
{
    offsetPos = eventData.position - (Vector2)transform.position;
}

}

我想要达到的结果

刚好昨天在帮另一个题主搞UI检测这一块,感觉你的问题跟他其实可以用同一套逻辑和思路,将脚本挂在任意物体上,然后判断射线射中物体是否为背景哪里你可以用名字判断也可以搞个单独的层,将你这个挂了dragUI的物体拖到脚本的public变量上,play


```c#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class Simulation : MonoBehaviour
{

    EventSystem eventSystem;
    PointerEventData pointerEventData;
    List<RaycastResult> uiRaycastResultCache = new List<RaycastResult>();
    public GameObject mDragUI;
    void Start()
    {
        eventSystem = EventSystem.current;
        pointerEventData = new PointerEventData(eventSystem);
    }

    // Update is called once per frame
    void Update()
    {
        Drag();
    }
    void Drag()
    {
        pointerEventData.position = Input.mousePosition;
        //射线检测ui
        eventSystem.RaycastAll(pointerEventData, uiRaycastResultCache);
        Debug.Log($"{uiRaycastResultCache.Count}");
        if (uiRaycastResultCache.Count > 0)
        {
            if (uiRaycastResultCache[0].gameObject.name == "BG")
            {
                eventSystem.SetSelectedGameObject(mDragUI);
                if (Input.GetMouseButtonDown(0))
                {
                    ExecuteEvents.Execute(mDragUI, pointerEventData, ExecuteEvents.pointerDownHandler);

                }
                if (Input.GetMouseButton(0))
                {
                    ExecuteEvents.Execute(mDragUI, pointerEventData, ExecuteEvents.dragHandler);
                }

            }
        }
    }

}


```

背景是指什么,点到地面也能拖拽panel??

panel做成全屏带透明的