unity 打开文件对话框功能及非Editor模式下全屏播放打开文件对话框后程序转后台问题的处理
2018-03-08 16:48
621 查看
(适用系统Windows)unity5.4及以前的版本没有自己的文件打开存储功能,如果需要操作本地文件,只能通过调用系统功能进行文件操作,以下是详细代码
openFileName.structSize = Marshal.SizeOf(openFileName);
openFileName.filter = @"视频文件|*.avi,*.AVI,*.mp4,*.MP4,*.mov,*.MOV,*.asf,*.ASF,*.wmv,*.WMV,*.mp3,*.MP3,*.wav,*.WAV";
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 = defaultfilepath;
openFileName.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000008;
if (LocalDialog.GetOpenFileName(openFileName))
{
defaultfilepath = openFileName.file;
} 因为我做的是一个全屏的播放器功能,当选取本地的视频文件时,运行程序就会跳到后台,
4000
严重影响了用户体验,最后找了个折中的办法,当选取本地文件时跳出全屏改为窗口模式,播放或进行其它操作时再进入全屏模式,两句代码的事,Screen.SetResolution(1920, 1080, true)和Screen.SetResolution(1920, 1080, false)。虽然不能完美解决,至少能让用户体验提升一点,如果有大神有更好的方法请多多指教,感谢!
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 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); } }沟通的桥梁搭建好了,下面就是方法的使用了OpenFileName openFileName = new OpenFileName();
openFileName.structSize = Marshal.SizeOf(openFileName);
openFileName.filter = @"视频文件|*.avi,*.AVI,*.mp4,*.MP4,*.mov,*.MOV,*.asf,*.ASF,*.wmv,*.WMV,*.mp3,*.MP3,*.wav,*.WAV";
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 = defaultfilepath;
openFileName.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000008;
if (LocalDialog.GetOpenFileName(openFileName))
{
defaultfilepath = openFileName.file;
} 因为我做的是一个全屏的播放器功能,当选取本地的视频文件时,运行程序就会跳到后台,
4000
严重影响了用户体验,最后找了个折中的办法,当选取本地文件时跳出全屏改为窗口模式,播放或进行其它操作时再进入全屏模式,两句代码的事,Screen.SetResolution(1920, 1080, true)和Screen.SetResolution(1920, 1080, false)。虽然不能完美解决,至少能让用户体验提升一点,如果有大神有更好的方法请多多指教,感谢!
相关文章推荐
- sql server 关于表中只增标识问题 C# 实现自动化打开和关闭可执行文件(或 关闭停止与系统交互的可执行文件) ajaxfileupload插件上传图片功能,用MVC和aspx做后台各写了一个案例 将小写阿拉伯数字转换成大写的汉字, C# WinForm 中英文实现, 国际化实现的简单方法 ASP.NET Core 2 学习笔记(六)ASP.NET Core 2 学习笔记(三)
- IIS8集成模式下打开静态资源被aspx处理程序处理,StaticFileModule失效问题分析
- iOS音频播放的几种方式,打开后台模式的音乐播放、使用AVAudioPlayer播放音乐、播放指定的音频文件、注册音频文件
- 问题:双击Excel文件提示文件找不到,只打开程序不同时打开文件,但通过打开对话框却能打开文件。
- MFC程序打开文件对话框出错的问题解决
- MFC程序打开文件对话框出错的问题解决
- AjaxFileUpLoad 文件异步上传Demo(模仿官方网站,后台使用.net一般处理程序)
- 在ashx一般处理程序文件中不能使用session和request的问题解决办法
- 实战 HTTP 处理程序(HTTP Handler) (5)---不用临时文件,直接打开动态生成的文件
- WIN7下的WCF遇到的问题:HTTP 错误 404.17 - Not Found 请求的内容似乎是脚本,因而将无法由静态文件处理程序来处理
- 全屏程序的系统功能屏蔽处理
- 用Excel打开csv文件时,如何处理数字内容展现会自动转换格式的问题
- 【转】oracle10g升级10.2.0.4补丁后,提示ORA-12526: TNS: 监听程序: 所有适用例程都处于受限模式问题处理
- OPENFILENAME打开文件对话框选择多个文件的问题解决
- WCF问题:“HTTP 错误 404.17 - Not Found 请求的内容似乎是脚本,因而将无法由静态文件处理程序来处理”解决方法
- windows server 2008下无法用程序打开一个xls文件问题
- 2006.9.19 解决了程序播放mp3文件的问题
- 一个WinForm记事本程序(包含主/下拉/弹出菜单/打开文件/保存文件/打印/页面设置/字体/颜色对话框/剪切版操作等等控件用法以及记事本菜单事件/按键事件的具体代码)
- 在ashx一般处理程序文件中不能使用session和request的问题解决办法
- MFC应用程序中处理消息,创建窗口的过程,关闭窗口(非模态窗口),打开模式对话框等的函数调用顺序