【求助】Unity里面可以用System.Windows.Forms的DragDrop和DragEnter方法吗
我想打开U3D发布的PC窗口,实现桌面文件拖入窗口显示选择的文件路径,网上都是在winform里面的,我应用了dll,但是没有效果
using System;
using System.Collections;
using System.Collections.Generic;
using System.Windows.Forms;
using UnityEngine;
using UnityEngine.UI;
public class Test : MonoBehaviour {
public Text txt;
private void Start()
{
Form1 form = new Form1(txt);
}
}
public class Form1 : Form
{
Text txt;
public Form1(Text txt)
{
this.txt = txt;
InitializeComponent();
}
private void InitializeComponent()
{
this.AllowDrop = true;
this.DragDrop += new DragEventHandler(this.Form1_DragDrop);
this.DragEnter += new DragEventHandler(this.Form1_DragEnter);
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
txt.text = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
}
private void Form1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Link;
else e.Effect = DragDropEffects.None;
}
}