我的工作统一游戏工具,在那里你需要拖放文件从资源管理器,处理那里,并拖放回资源管理器,记事本,油漆或其他东西。
问题:我不能在资源管理器或其他地方放置文件,但我可以"复制"文件到左侧栏或滚动条的空白区域。
无法复制文件和文件夹空间:https://i.stack.imgur.com/J4DBU.png
可以"复制"到空白空间:https://i.stack.imgur.com/ZdaYD.png
可以"复制"到滚动条:https://i.stack.imgur.com/2rWDd.png
private void StartDrag()
{
var data = new DataObject();
var ls = new System.Collections.Specialized.StringCollection();
ls.Add("C:/ExeMask.log");
data.SetFileDropList(ls);
OleInitialize(null);
int[] array = new int[1];
DoDragDrop(data, new DropSource(), (int)DragDropEffects.Copy, array);
OleUninitialize();
}
[DllImport("ole32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern int OleInitialize(Action lpVoid);
[DllImport("ole32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern void OleUninitialize();
[DllImport("ole32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern int DoDragDrop(System.Runtime.InteropServices.ComTypes.IDataObject dataObject, IOleDropSource dropSource, int allowedEffects, int[] finalEffect);
[ComImport]
[Guid("00000121-0000-0000-C000-000000000046")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IOleDropSource
{
[PreserveSig]
int OleQueryContinueDrag(int fEscapePressed, [In][MarshalAs(UnmanagedType.U4)] int grfKeyState);
[PreserveSig]
int OleGiveFeedback([In][MarshalAs(UnmanagedType.U4)] int dwEffect);
}
public class DropSource : IOleDropSource
{
public DropSource()
{
}
public int OleQueryContinueDrag(int fEscapePressed, [In, MarshalAs(UnmanagedType.U4)] int grfKeyState)
{
QueryContinueDragEventArgs qcdevent = null;
bool escapePressed = fEscapePressed != 0;
DragAction cancel = DragAction.Continue;
if (escapePressed)
{
cancel = DragAction.Cancel;
}
else if ((((grfKeyState & 1) == 0) && ((grfKeyState & 2) == 0)) && ((grfKeyState & 0x10) == 0))
{
cancel = DragAction.Drop;
}
qcdevent = new QueryContinueDragEventArgs(grfKeyState, escapePressed, cancel);
//this.peer.OnQueryContinueDrag(qcdevent);
switch (qcdevent.Action)
{
case DragAction.Drop:
return 0x40100;
case DragAction.Cancel:
return 0x40101;
}
return 0;
}
public int OleGiveFeedback([In, MarshalAs(UnmanagedType.U4)] int dwEffect)
{
GiveFeedbackEventArgs gfbevent = new GiveFeedbackEventArgs((DragDropEffects)dwEffect, true);
//this.peer.OnGiveFeedback(gfbevent);
if (gfbevent.UseDefaultCursors)
{
return 0x40102;
}
return 0;
}
}
我尝试了:
- 调用和不调用OleInitialize和OleUninitialize
- 导入与WinForms在Unity中使用的完全相同的System.Windows.Forms.dll(由于在Unity中找不到CIL而无法导入)
- new Control(). DoDragDrop-相同的结果(但我使用的dll不完全相同)
- 以管理员身份运行应用程序。
也许有一些库,可以开始拖放没有自己的图形用户界面-只需调用方法和繁荣!拖放启动?我看到了c++的解决方案,但我很糟糕。
1条答案
按热度按时间svujldwt1#
我试着拖放图像到assets并且不能做它,然后我转到文件夹与名字到项目在我的计算机上打开assets文件夹并且拖动图像到那里,并且现在他们出现在assets in unity