您的位置:首页 > 移动开发 > Unity3D

unity调取windows保存或读取窗口

2016-07-08 10:27 423 查看
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 DllTest
{
[DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
public static extern bool GetOpenFileName([In, Out] OpenFileName ofn);
public static bool GetOpenFileName1([In, Out] OpenFileName ofn)
{
return GetOpenFileName(ofn);
}
[DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
public static extern bool GetSaveFileName([Out, In] OpenFileName ofn);
public static bool GetSaveFileName1([Out, In] OpenFileName ofn)
{
return GetSaveFileName(ofn);
}
}

上面为帮助类~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

OpenFileName ofn = new OpenFileName();

ofn.structSize = Marshal.SizeOf(ofn);

ofn.filter = "esld文件(*.esld)|*.esld";

ofn.file = new string(new char[256]);

ofn.maxFile = ofn.file.Length;

ofn.fileTitle = new string(new char[64]);

ofn.maxFileTitle = ofn.fileTitle.Length;

ofn.initialDir = UnityEngine.Application.dataPath;//默认路径

ofn.title = "请选择保存位置";

ofn.defExt = ".esld";

//注意 一下项目不一定要全选 但是0x00000008项不要缺少
ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;//OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR
if (DllTest.GetSaveFileName(ofn))
{
//你需要干什么事

}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~此为打开 保存即把open改成save

以上为本人个人笔记,禁止转载!!!!!!!!!!!!!!!!!!!!!!!
本人QQ2572768 学习交流

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  unity windows class 脚本