Using Unityengine;
Using System.Collections;
Using System;
Using System.Runtime.InteropServices;
[StructLayout (layoutkind.sequential, CharSet = CharSet.Auto)]
public class OpenFileName
{
Publicint structsize =0;
Public IntPtr Dlgowner = IntPtr.Zero;
Public INTPTR instance = IntPtr.Zero;
PublicStringFilter =Null
PublicString Customfilter =Null
Publicint maxcustfilter =0;
Publicint filterindex =0;
PublicString file =Null
Publicint maxfile =0;
PublicString Filetitle =Null
Publicint maxfiletitle =0;
PublicString Initialdir =Null
PublicString title =Null
Publicint flags =0;
PublicShort Fileoffset =0;
Publicshort fileextension = 0;
public string defext = null;
public IntPtr custdata = IntPtr.Zero;
public IntPtr hook = IntPtr.Zero;
public string templatename = null;
public IntPtr reservedptr = IntPtr.Zero;
public int reservedint = 0;
public int flagsex = 0;
} /span>
PublicClassLocaldialog
{
Link Specify system function open file dialog box
[DllImport ("Comdlg32.dll", SetLastError =True, Throwonunmappablechar =True, CharSet = CharSet.Auto)]
PublicStaticexternboolGetOpenFileName ([In, out] OpenFileName ofn);
PublicStaticboolGetofn ([In, out] OpenFileName ofn)
{
Return GetOpenFileName (OFN);
}
Link Specify system function Save As dialog box
[DllImport ("Comdlg32.dll", SetLastError = true, Throwonunmappablechar = true, CharSet = CharSet.Auto)]
Public static extern bool getsavefilename ([in, out] openfilename ofn);
Public static bool GETSFN ([in,out] openfilename ofn)
{
return GetSaveFileName (OFN);
}
}
Using Unityengine;
Using System.Collections;
Using System.Runtime.InteropServices;
PublicClassDialogtest:Monobehaviour {
voidOngui ()
{
if (GUI. Button (New Rect (10,10,100,50),"Open"))
{
OpenFileName openfilename =New OpenFileName ();
Openfilename.structsize = marshal.sizeof (openfilename);
Openfilename.filter ="Excel file (*.xlsx) \0*.xlsx";
Openfilename.file =NewStringNewchar[256]);
Openfilename.maxfile = OpenFileName.file.Length;
Openfilename.filetitle =NewStringNewchar[64]);
Openfilename.maxfiletitle = OpenFileName.fileTitle.Length;
Openfilename.initialdir = Application.streamingAssetsPath.Replace (‘/‘,‘\\‘);Default Path
Openfilename.title ="Window caption";
Openfilename.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000008;
if (Localdialog.getsavefilename (openfilename))
{
Debug.Log (Openfilename.file);
Debug.Log (Openfilename.filetitle);
}
}
}
}
Unity calls the System window to select a file or file path