Unity调用系统窗口选择文件或文件路径
来源:互联网 发布:数据库设计三大范式 编辑:程序博客网 时间:2024/06/17 21:49
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 = 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;}
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(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); } } }}
效果如下:
阅读全文
0 0
- Unity调用系统窗口选择文件或文件路径
- Unity调用系统窗口选择文件或文件路径
- Unity调用系统窗口选择文件或文件路径 来赋值图片给物体
- 调用系统控件,打开选择文件或路径的对话框
- C#调用文件夹选择窗口或文件选择窗口
- 金蝶EAS,ListUI或EditUI弹出文件选择窗口,获取文件路径
- Unity中调用文件选择对话框
- Android调用系统自带的文件管理器进行文件选择并获得路径
- Android调用系统自带的文件管理器进行文件选择并获得路径,android文件管理器
- Android调用系统自带的文件管理器进行文件选择并获得路径,android文件管理器
- Android调用系统自带的文件管理器进行文件选择并获得路径,android文件管理器
- WIN32,,打开文件没有默认程序,调用系统的默认程序选择窗口
- Unity发布成exe文件,去掉分辨率选择窗口
- Unity 判断某个 路径 或 文件 是否存在
- 弹出一个选择文件或文件夹的窗口
- Unity文件路径
- unity文件操作路径
- unity 文件 路径 笔记
- caffe(四) -------------CNN
- 利用函数公式进行贷款的计算
- hdu 1950 java解法
- 手机病毒:为啥都爱用cc域名
- fileupload文件上传
- Unity调用系统窗口选择文件或文件路径
- 数据类型强制转换+号前后的区别
- PostgreSQL教程(三):高级特性
- intellij用maven来创建多模块项目
- submit 快捷键
- c语言---数值的上溢和下溢
- hibernate关联配置
- Android4.4 增加的/system/priv-app
- ROS Robotics Projects(8)自动驾驶汽车