我想打開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;
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/54796.html
標籤:Unity3D
