Unity中调用Windows窗口选择文件
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窗口选择文件的更多相关文章
- Unity中调用Windows窗口句柄以及根据需求设置并且解决扩展屏窗体显示错乱/位置错误的Bug
问题背景: 现在在搞PC端应用开发,我们开发中需要调用系统的窗口以及需要最大化最小化,缩放窗口拖拽窗口,以及设置窗口位置,去边框等功能 解决根据: 使用user32.dll解决 具体功能: Unity ...
- unity 实现调用Windows窗口/对话框交互
Unity调用Window窗口 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- 心分 ...
- C#在父窗口中调用子窗口的过程(无法访问已释放的对象)异常,不存在从对象类型System.Windows.Forms.DateTimePicker到已知的托管提供程序本机类型的映射。
一:C#在父窗口中调用子窗口的过程(无法访问已释放的对象)异常 其实,这个问题与C#的垃圾回收有关.垃圾回收器管 理所有的托管对象,所有需要托管数据的.NET语言(包括 C#)都受运行库的 垃圾回收器 ...
- C#中调用Windows API的要点 .
介绍 API(Application Programming Interface),我想大家不会陌生,它是我们Windows编程的常客,虽然基于.Net平台的C#有了强大的类库,但是,我们还是不能否认 ...
- Unity中调用DLL库
DLL -- Dynamic Link Library(动态链接库文件),这里以Window平台为例. Unity支持的两种语言生成的DLL库(C++.C#),这里以C#为例,C++网上可以搜索很详细 ...
- java程序员图文并茂细说Unity中调用Android的接口
http://bbs.csdn.net/topics/391876421 最近做一个项目,为同事提供接口,能使他在Unity中调用Android中的函数来实现QQ登陆并获取用户信息.按照一些书上和一些 ...
- (转)C#在父窗口中调用子窗口的过程(无法访问已释放的对象)
C#在父窗口中调用子窗口的过程: 1. 创建子窗口对象 2. 显示子窗口对象 笔者的程序中,主窗体MainFrm通过菜单调用子窗口ChildFrm.在窗体中定义了子窗口对象,然后在菜单项点击事件中 ...
- C#中调用Windows API时的数据类型对应关系
原文 C#中调用Windows API时的数据类型对应关系 BOOL=System.Int32 BOOLEAN=System.Int32 BYTE=System.UInt16 CHAR=System. ...
- [原创]C/C++语言中,如何在main.c或main.cpp中调用另一个.c文件
C/C++语言中,如何在main.cpp中调用另一个.c文件主要有5种思路: 1.在VS2012 IDE中,将被引用的.c文件后缀名全部修改为.h,然后通过IDE的解决方案资源管理器中鼠标右键单击“头 ...
随机推荐
- 题解【洛谷P1046】[NOIP2005普及组] 陶陶摘苹果
[NOIP2005] 陶陶摘苹果 首先,我们用一个数组s[11]存储每个苹果的高度. 然后,用a表示陶陶的身高. 接着,用a+30与s[i]比较,大于则计数器加一. 最后,输出计数器的值即可. #in ...
- 后端工具——Maven——初篇——目录
目录 Maven的知识体系包括四个部分.Maven的配置文件,Maven命令,Maven生命周期,Maven插件.在介绍Maven之前,首先需要介绍如何安装Maven. 安装:介绍Maven在Linu ...
- selenium参数化-ddt模块
DDT介绍: DDT(数据驱动测试)允许您通过使用不同的测试数据运行一个测试用例来使其倍增,并使它显示为多个测试用例.要使用DDT需要安装,安装命令:pip install ddt 使用方法: dd. ...
- MySQL8.0服务启动(windows10)
mysql下载地址:https://dev.mysql.com/downloads/mysql/ 根目录下配置文件:my.ini [mysqld]# 设置3306端口port=3306# 设置mysq ...
- winform学习(8)RichTextBox控件
RichTextBox控件允许用户输入和编辑文本的同时提供了比普通的TextBox控件更高级的格式特征. RichTextBox的控件标识符.SelectionColor = Color.Blue; ...
- 揭秘jQuery-选择器
先看代码: $(“li”)只选择第一个无序列表中的一个li元素,而不会选择另一个无序列表中的li元素 <!DOCTYPE html> <html> <head> & ...
- 2019 ICPC 徐州网络赛 B.so easy (并查集)
计蒜客链接:https://nanti.jisuanke.com/t/41384 题目大意:给定n个数,从1到n排列,其中有q次操作,操作(1) 删除一个数字 // 操作(2)求这个数字之后第一个没有 ...
- 一起了解 .Net Foundation 项目 No.3
.Net 基金会中包含有很多优秀的项目,今天就和笔者一起了解一下其中的一些优秀作品吧. 中文介绍 中文介绍内容翻译自英文介绍,主要采用意译.如与原文存在出入,请以原文为准. AutoMapper Au ...
- 页面在谷歌浏览器和IE浏览器顶部多出空白行,火狐显示正常
引起这个问题的原因是用系统自带记事本打开过Tinkphp的模板文件,因为记事本不支持UTF8无BOM格式编码,打开之后这个编码格式丢失,转为ANSI格式的编码了: 解决的办法是:用Notepad++或 ...
- css之变形(transform)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...