GJM : Unity调用系统窗口选择本地文件
- 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 WindowDll
- {
- [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);
- }
- }
- using UnityEngine;
- using System.Collections;
- using System.Runtime.InteropServices;
- using System.Reflection;
- public class CameraTest : MonoBehaviour
- {
- public WebCamTexture cameraTexture;
- public string cameraName = "";
- private bool isPlay = false;
- // Use this for initialization
- void Start()
- {
- //StartCoroutine(OpenCamera());
- }
- // Update is called once per frame
- void Update()
- {
- }
- /// <summary>
- /// 获取权限打开摄像头
- /// </summary>
- /// <returns></returns>
- IEnumerator OpenCamera()
- {
- yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
- if (Application.HasUserAuthorization(UserAuthorization.WebCam))
- {
- WebCamDevice[] devices = WebCamTexture.devices;
- cameraName = devices[0].name;
- cameraTexture = new WebCamTexture(cameraName, 320, 240, 15);
- cameraTexture.Play();
- isPlay = true;
- }
- }
- void OnGUI()
- {
- if (isPlay)
- {
- GUI.DrawTexture(new Rect(0, 0, 320, 240), cameraTexture, ScaleMode.ScaleAndCrop);
- }
- if (GUI.Button(new Rect(0, 0, 100, 35), "OpenDialog"))
- {
- OpenFileName ofn = new OpenFileName();
- ofn.structSize = Marshal.SizeOf(ofn);
- ofn.filter = "All Files\0*.*\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;
- string path = Application.streamingAssetsPath;
- path = path.Replace('/','\\');
- //默认路径
- ofn.InitialDirectory = path;
- //ofn.InitialDirectory = "D:\\MyProject\\UnityOpenCV\\Assets\\StreamingAssets";
- ofn.title = "Open Project";
- ofn.defExt = "JPG";//显示文件的类型
- //注意 一下项目不一定要全选 但是0x00000008项不要缺少
- ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;//OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR
- if (WindowDll.GetOpenFileName(ofn))
- {
- Debug.Log("Selected file with full path: {0}" + ofn.file);
- }
- }
- }
- }
文件的类型设置
- ofn.filter = "图片文件(*.jpg*.png)\0*.jpg;*.png";

GJM : Unity调用系统窗口选择本地文件的更多相关文章
- (转)在WinForm中选择本地文件
相信很多朋友在日常的编程中总会遇到各钟各样的问题,关于在WinForm中选择本地文件就是很多朋友们都认为很难的一个学习.net的难点, 在WebForm中提供了FileUpload控件来供我们选择本地 ...
- 【.Net】在WinForm中选择本地文件
相信很多朋友在日常的编程中总会遇到各钟各样的问题,关于在WinForm中选择本地文件就是很多朋友们都认为很难的一个学习.net的难点, 在WebForm中提供了FileUpload控件来供我们选择本地 ...
- 选择本地文件上传控件 input标签
当要通过控件来选择本地文件上传的时候的一种方式 <input type="file" id="input-file"/> 注意 type类型一定要是 ...
- JS调用activeX实现浏览本地文件夹功能 wekit内核只需要<input type="file" id="files" name="files[]" webkitdirectory/>即可,IE内核比较麻烦
研究了一天,js访问本地文件本身是不可能的,只能借助于插件.植入正题,IE仅支持ActiveX插件. function openDialog() { try { var Message = " ...
- Google调用explorer.exe打开本地文件
给IE浏览器地址栏输个本地文件路径,会自动用explorer.exe打开,这个挺好的,但是IE对jQuery稍微高点的版本不怎么待见,只好自己给Google折腾一个调用explorer的功能----- ...
- Android调用相机拍照并返回路径和调用系统图库选择图片
调用系统图库: Intent intent = new Intent(Intent.ACTION_PICK,MediaStore.Images.Media.EXTERNAL_CONTENT_URI); ...
- Unity中调用Windows窗口选择文件
1.OpenFileName数据接收类,如下: using UnityEngine; using System.Collections; using System; using System.Runt ...
- iOS 调用拍照、选择本地相册、上传功能---未完善。
1.新建viewController 拖入一个Button,添加点击事件,使用代理方法 <UIActionSheetDelegate,UIImagePickerControllerDelegat ...
- Android WebView选择本地文件上传
This sample demonstrate android webview choose file to upload. I just implement the client code ,the ...
随机推荐
- 微信小程序产品定位及功能介绍
产品定位及功能介绍 微信小程序是一种全新的连接用户与服务的方式,它可以在微信内被便捷地获取和传播,同时具有出色的使用体验. 小程序注册 注册小程序帐号 在微信公众平台官网首页(mp.weixin.qq ...
- ASP.NET列表信息以Excel形式导出
1.从数据查出数据扔进table中: private DataTable getTable() { var dbHelper = applyBLL.CreateDataBase("VISAd ...
- JMeter--一、安装JMeter
Apache JMeter是Apache组织开发的基于Java的接口和性能测试工具. 作用: 1.能够对HTTP和FTP服务器进行压力和性能测试, 也可以对任何数据库进行同样的测试(通过JDBC). ...
- 探讨Js的事件的冒泡阶段
近来看到了一个新的知识点叫Js的事件冒泡,因此决定自己来研究一番. 大家应该都知道,Js中的事件处理分为三个阶段,1:事件的捕获阶段,2:处于目标阶段,3:事件的冒泡阶段.那么什么是事件的捕获和冒泡呢 ...
- 08. Web大前端时代之:HTML5+CSS3入门系列 ~ QQ空间时间轴
Web大前端时代之:HTML5+CSS3入门系列:http://www.cnblogs.com/dunitian/p/5121725.html 大前端系列,主要就是使用CSS3.0来实现,注释我已经打 ...
- jQuery 2.0.3 源码分析core - 选择器
声明:本文为原创文章,如需转载,请注明来源并保留原文链接Aaron,谢谢! 打开jQuery源码,一眼看去到处都充斥着正则表达式,jQuery框架的基础就是查询了,查询文档元素对象 ...
- Easyui datagrid 显示隐藏列
html: <div style="float: left; width: 1450px; height:auto; "> & ...
- ASP.NET MVC 6 一些不晓得的写法
今天在看 Scott Guthrie 的一篇博文<Introducing ASP.NET 5>,在 MVC 6 中,发现有些之前不晓得的写法,这边简单记录下,算是对自己知识的补充,有些我并 ...
- 升级 Visual Studio 2015 CTP 5 的坑、坑、坑
前两天,微软发布了 Visual Studio 2015 CTP 5,全称为 Visual Studio 2015 Community Technology Preview 5,意为社区技术预览版,之 ...
- (三)WebGIS前端地图显示之根据地理范围换算出瓦片行列号的原理(核心)
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/. 1.前言 在上一节中我们知道了屏幕上一像素等于实际中多少单位长度(米或 ...