1.OpenFileName数据接收类,如下:

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

2.系统函数调用类, 如下:

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);
}
}

3.测试入口类,如下:

using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices; public class DialogTest : MonoBehaviour { void OnGUI()
{
if (GUI.Button(new Rect(,,,),"Open"))
{
OpenFileName openFileName = new OpenFileName();
openFileName.structSize = Marshal.SizeOf(openFileName);
openFileName.filter = "Excel文件(*.xlsx)\0*.xlsx";
openFileName.file = new string(new char[]);
openFileName.maxFile = openFileName.file.Length;
openFileName.fileTitle = new string(new char[]);
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);
}
}
}
}

Unity中调用Windows窗口选择文件的更多相关文章

  1. Unity中调用Windows窗口句柄以及根据需求设置并且解决扩展屏窗体显示错乱/位置错误的Bug

    问题背景: 现在在搞PC端应用开发,我们开发中需要调用系统的窗口以及需要最大化最小化,缩放窗口拖拽窗口,以及设置窗口位置,去边框等功能 解决根据: 使用user32.dll解决 具体功能: Unity ...

  2. unity 实现调用Windows窗口/对话框交互

    Unity调用Window窗口 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- 心分 ...

  3. C#在父窗口中调用子窗口的过程(无法访问已释放的对象)异常,不存在从对象类型System.Windows.Forms.DateTimePicker到已知的托管提供程序本机类型的映射。

    一:C#在父窗口中调用子窗口的过程(无法访问已释放的对象)异常 其实,这个问题与C#的垃圾回收有关.垃圾回收器管 理所有的托管对象,所有需要托管数据的.NET语言(包括 C#)都受运行库的 垃圾回收器 ...

  4. C#中调用Windows API的要点 .

    介绍 API(Application Programming Interface),我想大家不会陌生,它是我们Windows编程的常客,虽然基于.Net平台的C#有了强大的类库,但是,我们还是不能否认 ...

  5. Unity中调用DLL库

    DLL -- Dynamic Link Library(动态链接库文件),这里以Window平台为例. Unity支持的两种语言生成的DLL库(C++.C#),这里以C#为例,C++网上可以搜索很详细 ...

  6. java程序员图文并茂细说Unity中调用Android的接口

    http://bbs.csdn.net/topics/391876421 最近做一个项目,为同事提供接口,能使他在Unity中调用Android中的函数来实现QQ登陆并获取用户信息.按照一些书上和一些 ...

  7. (转)C#在父窗口中调用子窗口的过程(无法访问已释放的对象)

    C#在父窗口中调用子窗口的过程: 1. 创建子窗口对象 2. 显示子窗口对象   笔者的程序中,主窗体MainFrm通过菜单调用子窗口ChildFrm.在窗体中定义了子窗口对象,然后在菜单项点击事件中 ...

  8. C#中调用Windows API时的数据类型对应关系

    原文 C#中调用Windows API时的数据类型对应关系 BOOL=System.Int32 BOOLEAN=System.Int32 BYTE=System.UInt16 CHAR=System. ...

  9. [原创]C/C++语言中,如何在main.c或main.cpp中调用另一个.c文件

    C/C++语言中,如何在main.cpp中调用另一个.c文件主要有5种思路: 1.在VS2012 IDE中,将被引用的.c文件后缀名全部修改为.h,然后通过IDE的解决方案资源管理器中鼠标右键单击“头 ...

随机推荐

  1. LED Decorative Light Manufacturer - LED Neon Rope: 5 Advantages

    In the past 100 years, lighting has come a long way. Nowadays, the decorative LED lighting design ca ...

  2. linux下删除空行的几种方法

    在查看linux下的配置文件时,为了便于一目了然的查看,经常会删除空行和#头的行.而linux在删除空行的方法很多,grep.sed.awk.tr等工具都能实现.现总结如下: 1.grep grep ...

  3. 【转载】Java反射机制详解

    转自:http://baike.xsoftlab.net/view/209.html#3_8 1反射机制是什么 反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法:对于任意一个对 ...

  4. java &&和&与逻辑运算区别

    二者都表示与运算,同真为真,遇假即假 && 具有短路功能,前面为false后面不在预算直接表达式为false; &还可以用作位运算符,当&操作符两边的表达式不是 boo ...

  5. linux centos7分区

    哈喽! 我今天来分享一下Linux的分区,本次我使用的是LinuxCentos7版本为例,使用虚拟机,命令是fdisk Linux分区有4个主分区及扩展分区,逻辑分区. 首先给虚拟机添加8G硬盘(硬盘 ...

  6. linx下跑多个tomcat

    1.修改server.xml文件 <Server port="8005" shutdown="SHUTDOWN"> <Connector po ...

  7. jsp+servlet实现的验证登陆

    可以将业务逻辑处理和视图相分离,使用jsp界面表示视图,使用servlet处理业务逻辑 login.jsp <%@ page language="java" contentT ...

  8. java 并交集运算

    在面试的过程中,忘记了List中还可以进行交并集运算,这也是常见的数据问题啊,这也是常见的数据结构问题---集合,面试的过程中一直没有想到这种数据结构 java中API中已经集成了并交集的运算. 代码 ...

  9. 简单记录搭建Harbor私服仓库

    一.本机环境 ①系统镜像:CentOS7 ②Docker:Docker version 19.03.5 ③Docker-compose:docker-compose 二.Docker安装 参考官网安装 ...

  10. UVa 400 Unix Is命令

    简单题 #include <bits/stdc++.h> using namespace std; const int maxn=110; string s[maxn]; int main ...