using UnityEngine;
using System.Runtime.InteropServices;
using System;
public class WinAPITest : MonoBehaviour
{
[DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
public static extern bool GetOpenFileName([In, Out] FileStruct ofn);
public static bool GetOpenFileName1([In, Out] FileStruct ofn)
{
return GetOpenFileName(ofn);
}
public void OpenFileDialog()
{
FileStruct ofn = new FileStruct();
ofn.structSize = Marshal.SizeOf(ofn);
ofn.filter = "All Files\0*.*\0\0";
ofn.file = new string(new char[256]);
ofn.maxFile = ofn.file.Length;
ofn.fileTitle = new string(new char[64]);
ofn.maxFileTitle = ofn.fileTitle.Length;
string path = Application.streamingAssetsPath;
path = path.Replace('/', '\\');
//默认路径
ofn.initialDir = path;
ofn.title = "Open Project";
//显示文件的类型
Unity下利用WinAPI打开FileDialog
最新推荐文章于 2023-12-13 18:03:30 发布