如何实现UnityC#GetSaveFileName()
如何实现Unity C# GetSaveFileName()?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
站在用户的角度思考问题,与客户深入沟通,找到西工网站设计与西工网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:网站设计、成都网站建设、企业官网、英文网站、手机端网站、网站推广、国际域名空间、网络空间、企业邮箱。业务覆盖西工地区。
先放个效果图:
首先需要定义一个OpenFileName的类:
[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; }
当然,也不是都用到了,只用到了一小部分,有性趣的童鞋可以个性化一下保存对话框,
然后是最重要的委托GetSaveName()方法:
public class DllUse { [DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)] public static extern bool GetSaveFileName([In, Out] OpenFileName ofn); }
挡挡挡,最后调用一下即可:
public static void OpenDialog(ActiononSave) { OpenFileName ofn = new OpenFileName(); ofn.structSize = Marshal.SizeOf(ofn); ofn.filter = "Excel (*.xls)\0*.xls\0\0"; 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 = ".xls";//显示文件的类型ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;if (DllTest.GetSaveFileName(ofn)) { dosomething();string Savepath = Path.GetDirectoryName (ofn.file); Process.Start (Savepath); } }
看完上述内容,你们掌握如何实现Unity C# GetSaveFileName()的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!
网站名称:如何实现UnityC#GetSaveFileName()
当前网址:http://pwwzsj.com/article/gsegpi.html