Unity调用系统窗口选择文件或文件路径

using UnityEngine;
using System.Collections;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class OpenFileName
{
    public int structSize = 0;
    public IntPtr dlgOwner = IntPtr.Zero;
    public IntPtr instance = IntPtr.Zero;
    public String filter = null;
    public String customFilter = null;
    public int maxCustFilter = 0;
    public int filterIndex = 0;
    public String file = null;
    public int maxFile = 0;
    public String fileTitle = null;
    public int maxFileTitle = 0;
    public String initialDir = null;
    public String title = null;
    public int flags = 0;
    public short fileOffset = 0;
    public short 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;
}

public class LocalDialog
{
    //链接指定系统函数       打开文件对话框
    [DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
    public static extern bool GetOpenFileName([In, Out] OpenFileName ofn);
    public static bool GetOFN([In, Out] OpenFileName ofn)
    {
        return GetOpenFileName(ofn);
    }

//链接指定系统函数        另存为对话框
    [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;
public class DialogTest : MonoBehaviour {
    void OnGUI()
    {
        if (GUI.Button(new Rect(10,10,100,50),"Open"))
        {
            OpenFileName openFileName = new OpenFileName();
            openFileName.structSize = Marshal.SizeOf(openFileName);
            openFileName.filter = "Excel文件(*.xlsx)\0*.xlsx";
            openFileName.file = new string(new char[256]);
            openFileName.maxFile = openFileName.file.Length;
            openFileName.fileTitle = new string(new char[64]);
            openFileName.maxFileTitle = openFileName.fileTitle.Length;
            openFileName.initialDir = Application.streamingAssetsPath.Replace(‘/‘,‘\\‘);//默认路径
            openFileName.title = "窗口标题";
            openFileName.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000008;

if (LocalDialog.GetSaveFileName(openFileName))
            {
                Debug.Log(openFileName.file);
                Debug.Log(openFileName.fileTitle);
            }
        }
    }
}

时间: 2024-10-20 16:58:16

Unity调用系统窗口选择文件或文件路径的相关文章

C#调用系统注册程序打开pdf文件

1 private void btn_帮助文档_ItemClick(object sender, ItemClickEventArgs e) 2 { 3 try 4 { 5 System.Diagnostics.Process.Start(@"..\help\软件系统帮助文档.pdf"); 6 } 7 catch(Exception ex) 8 { 9 MessageBox.Show(ex.Message); 10 } 11 }

unity调用系统剪切板功能

package com.game.utils; import android.app.Activity; import android.content.ClipData; import android.content.ClipDescription; import android.content.ClipboardManager; import android.content.Context; import android.os.Handler; import android.os.Looper

8、?系统窗口的调用

? 调用系统窗口 调用Google搜索 Intent intent = new Intent(); intent.setAction(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager.QUERY,"searchString"); startActivity(intent);  ? 获取所有可调用的窗口及其调用细节 分析Android源代码 1. AndroidManifest.xml 2. 查看相应的源代码 安装APK文件

调用系统相册

import android.app.Activity; import android.content.Intent; import android.database.Cursor; import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; import android.provider.MediaStore; import android.support.v7.app.AppCompatA

(转)Android调用系统自带的文件管理器进行文件选择并获得路径

Android区别于iOS的沙盒模式,可以通过文件浏览器浏览本地的存储器.Android API也提供了相应的接口. 基本思路,先通过Android API调用系统自带的文件浏览器选取文件获得URI,然后将URI转换成file,从而得到file. 调用系统自带的文件浏览器 public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState

[VB.NET]调用系统的文件夹选择对话框

以下示例代码展示如何调用系统的文件夹选择对话框: 1 Private Function SelectFolder(ByVal Describe As String, Optional ByVal ShowNewFolder As Boolean = True) As String 2 Using nOpen As New System.Windows.Forms.FolderBrowserDialog() 3 nOpen.Description = Describe 4 nOpen.ShowNe

Android调用系统自带的文件管理器进行文件选择

http://blog.csdn.net/zqchn/article/details/8770913的补充 FileUtils文件 public class FileUtils {     public static String getPath(Context context, Uri uri) {         if ("content".equalsIgnoreCase(uri.getScheme())) {             String[] projection =

window2008 64位系统无法调用Microsoft.Office.Interop组件进行文件另存的解决办法

服务器是windows server2008 64位系统,项目中需要用到Microsoft.Office.Interop组件,包括excel.word.ppt等. 重点一: 步骤 1.在"开始"->"运行"中输入dcomcnfg.exe启动"组件服务" 2.依次双击"组件服务"->"计算机"->"我的电脑"->"DCOM配置" 3.在"

在Android浏览器中通过WebView调用相机拍照/选择文件 上传到服务器

最近做的一个项目中,有这样一个要求,在浏览器中调用系统的拍照功能或者选择文件,然后将文件上传到服务器,类似修改头像.        简单而言,就是在一个html页面中有这样一段代码 <input class="filePrew" type="file" capture="camera" accept="image/*" name="image"> 刚开始的时候,没有感觉很难的,因为在UC浏览器.