拖动资源到指定位置,获取拖动资源的路径
//一个EditorWindow
private void OnGUI()
{
    EditorGUILayout.BeginHorizontal();
    GUILayout.Label("搜索图片:", GUILayout.Width(70));
    Rect rect = EditorGUILayout.GetControlRect(GUILayout.Width(300));//创建一个区域
    a = EditorGUI.ObjectField(rect,(Object)a, typeof(Sprite),false) as Sprite;//用这个区域去创建
    EditorGUILayout.EndHorizontal();

    if ((Event.current.type == EventType.DragUpdated
            || Event.current.type == EventType.DragExited)
            && rect.Contains(Event.current.mousePosition)) //通过事件检查是否为拖拽,Rect判断是否拖到对应的区域
    {

        if (DragAndDrop.paths != null && DragAndDrop.paths.Length > 0)
        {
            searchText = DragAndDrop.paths[0];//获取资源路径
        }
    }
}

首页 我的博客
粤ICP备17103704号