脚本宝典收集整理的这篇文章主要介绍了Unity C# GetSaveFileName()的实例详解,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。唉哟,这次厉害咯,网上搜罗了好久,终于被我找到汉化的保存对话框了,根据网上的一些前辈总结的内容,做了一些修改,
先放个效果图:
[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(Action<Stream> onSave) { 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 = @R_777_1256@Engine.Application.dataPath;//默认路径ofn.title = "@R_406_1960@"; ofn.defExt = ".xls";//显示文件的类型ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;if (Dlltest.GetSaveFileName(ofn)) { DOSomething();string Savepath = Path.GetDirectoryName (ofn.file); PRocess.Start (Savepath); } }
终于搞定保存对话框汉化了,5555,也是不容易啊!
那位小伙伴有更好的方法希望可以分享给我啊!
以上就是Unity C# GetSaveFileName()的实例详解的详细内容,更多请关注脚本宝典其它相关文章!
以上是脚本宝典为你收集整理的Unity C# GetSaveFileName()的实例详解全部内容,希望文章能够帮你解决Unity C# GetSaveFileName()的实例详解所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。